[OpenSCAD] How to detect chr(0)
doug at moens.org
Fri Apr 17 08:09:27 EDT 2015
HI Fantome. In OpenSCAD, a string is an array of Unicode "code points", it
isn't an array of bytes. Each code point in a string has a value between 1
and 0x10FFFF, except that some code point values are invalid. len(string)
is the number of code points in the string, and str[i] is the i'th code
Torsten told you that internally, strings are represented in UTF-8 format.
But there are no operations in OpenSCAD that allow you to access that
internal representation. Numbers are represented internally as floating
point, but you can't access the underlying bit and byte patterns in a
Your test program contains the word ASCII several times, but that's
misleading, you don't have access to the underlying byte representation.
On 16 April 2015 at 23:20, Fantome <paul at brownsbrain.com> wrote:
> tp3 wrote
> > The chr() function is supposed to return valid unicode characters in
> > encoding, so for example "echo(chr(128512));" is valid and should give
> > smiley character U+1F600.
> > Invalid input values will return an empty string, chr(0) is always
> > as invalid.
> > Note: This means that asking for chr(255) will internally result in the
> > bytes 0xc3 0xbf and not 0xff. As len() is also utf-8 aware, len(chr(255))
> > still returns 1 as it's one character.
> > ciao,
> > Torsten.
> > _______________________________________________
> Hello and thanks for the input. I'm not sure what you mean by 'internally
> result' but here's an example that shows that chr(255) does return a hex
> value of 0xFF.
> the_text = chr(255);
> echo("number of characters = ",len(the_text));
> for (i=[0:len(the_text)-1])
> for (ascii_v = [0:255])
> if (the_text[i] == chr(ascii_v)) :
> if ((ascii_v) == 255):
> echo("character: ",the_text[i]);
> echo("ASCII value:", ascii_v); // print the ascii
> value being checked
> ECHO: "number of characters = ", 1
> ECHO: "character: ", "y"
> ECHO: "ASCII value:", 255
> Note that the character that prints like a y with two dots above it has the
> hex value of 0xFF, not 0xC3 .0xBF.
> View this message in context:
> Sent from the OpenSCAD mailing list archive at Nabble.com.
> OpenSCAD mailing list
> Discuss at lists.openscad.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Discuss