poke-devel
[Top][All Lists]
Advanced

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

Challenges of adding octal and hexadecimal escape sequences in strings


From: Mohammad-Reza Nabipoor
Subject: Challenges of adding octal and hexadecimal escape sequences in strings
Date: Fri, 30 Oct 2020 14:54:57 +0330

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.


WDYT?


Regards,
Mohammad-Reza



reply via email to

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