poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Challenges of adding octal and hexadecimal escape sequences in strin


From: Dan Čermák
Subject: Re: Challenges of adding octal and hexadecimal escape sequences in strings
Date: Sun, 01 Nov 2020 21:43:51 +0100

Hi Mohammad,

Mohammad-Reza Nabipoor via poke-devel <poke-devel@gnu.org> writes:

> Hi.
>
> I've added support for octal and hexadecimal escape sequences in strings.
> But there's a problem with Poke strings: they are null-terminated.
>
> Please consider the following example:
>
> ```poke
> defvar s = "a\0b";
>
> assert (s'length == 1);
> assert (s'size == 2#B);
> assert (s == "a");
> ```
>
> This behavior is IMHO annoying and counter-intuitive.
>
> The desired behavior (IMHO):
>
> ```poke
> defvar s = "a\0b";
>
> assert (s'length == 3);
> assert (s'size == 4#B);
> assert (s == "a\0b");
> assert (s + "cde" == "a\0bcde");
> ```
>
> I'm not sure about how `printf` (and `format` in future) should behave:
>
> ```poke
> printf ("%s\n", a); // Should behave like C and prints only two bytes?
>                     // Or should prints all the 3 bytes?
> ```
>
> Maybe choosing the first approach plus providing something like the "%.*s"
> specifier (like in `C`) to let the user choose about how many bytes he/she
> wants to print.
>
>
> Possible solution for Poke:
>   Using a property to keep track of length of string.

I think this is a good idea, because there can be situations where you
want to have strings including a NULL (C++ explicitly supports this in
std::string for instance).

Also, something comparable would be probably required anyway for proper
UTF8 support, where the string's length is not equal to the number of
bytes (minus 1).

So starting this now sounds like a good idea.


Cheers,

Dan

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]