M
MichaelAtOz
Fri, Apr 17, 2015 12:14 AM
Hi, welcome to the forum.
Your post is still flagged "This post has NOT been accepted by the mailing
list yet." which means that most people don't see it unless they look here.
You need to complete the mailing list subscription
http://forum.openscad.org/mailing_list/MailingListOptions.jtp?forum=1
Re chr(0). Many systems use null terminated strings so chr(0) is treated as
the end of the string. I suspect this is the case here, but haven't looked
into the C RTL to confirm this.
Unless specifically shown otherwise above, my contribution is in the Public Domain; To the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. This work is published globally via the internet. :) Inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/How-to-detect-chr-0-tp12351p12389.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Hi, welcome to the forum.
Your post is still flagged "This post has NOT been accepted by the mailing
list yet." which means that most people don't see it unless they look here.
You need to complete the mailing list subscription
<http://forum.openscad.org/mailing_list/MailingListOptions.jtp?forum=1>
Re chr(0). Many systems use null terminated strings so chr(0) is treated as
the end of the string. I suspect this is the case here, but haven't looked
into the C RTL to confirm this.
-----
Unless specifically shown otherwise above, my contribution is in the Public Domain; To the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. This work is published globally via the internet. :) Inclusion of works of previous authors is not included in the above.
The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/
--
View this message in context: http://forum.openscad.org/How-to-detect-chr-0-tp12351p12389.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
M
MichaelAtOz
Fri, Apr 17, 2015 12:22 AM
Well ignore what I said...
t = chr(0,41,42,43,44,255);
echo(t);
text(t);
for(i=[0:len(t)-1]) {
echo(t[i]);
translate([0,i*15,0]) text(t[i]);
}
Shows it if getting past the chr(0)
Unless specifically shown otherwise above, my contribution is in the Public Domain; To the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. This work is published globally via the internet. :) Inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/How-to-detect-chr-0-tp12351p12392.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Well ignore what I said...
t = chr(0,41,42,43,44,255);
echo(t);
text(t);
for(i=[0:len(t)-1]) {
echo(t[i]);
translate([0,i*15,0]) text(t[i]);
}
Shows it if getting past the chr(0)
-----
Unless specifically shown otherwise above, my contribution is in the Public Domain; To the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. This work is published globally via the internet. :) Inclusion of works of previous authors is not included in the above.
The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/
--
View this message in context: http://forum.openscad.org/How-to-detect-chr-0-tp12351p12392.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
M
MichaelAtOz
Fri, Apr 17, 2015 12:33 AM
t = chr(0,41,42,43,44,255);
echo(t);
text(t);
for(i=[0:len(t)-1]) {
echo(t[i]);
translate([0,i*15,0])
text(t[i]);
if(t[i]==chr(0))
echo("match 0");
if(t[i]==chr(255))
echo("match 255");
}
Hmmm...
Either a bug, or chr(0) plays a part in unicode or means something else...
Unless specifically shown otherwise above, my contribution is in the Public Domain; To the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. This work is published globally via the internet. :) Inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/How-to-detect-chr-0-tp12351p12393.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
t = chr(0,41,42,43,44,255);
echo(t);
text(t);
for(i=[0:len(t)-1]) {
echo(t[i]);
translate([0,i*15,0])
text(t[i]);
if(t[i]==chr(0))
echo("match 0");
if(t[i]==chr(255))
echo("match 255");
}
Hmmm...
Either a bug, or chr(0) plays a part in unicode or means something else...
-----
Unless specifically shown otherwise above, my contribution is in the Public Domain; To the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. This work is published globally via the internet. :) Inclusion of works of previous authors is not included in the above.
The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/
--
View this message in context: http://forum.openscad.org/How-to-detect-chr-0-tp12351p12393.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
TP
Torsten Paul
Fri, Apr 17, 2015 12:37 AM
The chr() function is supposed to return valid unicode characters in utf-8
encoding, so for example "echo(chr(128512));" is valid and should give the
smiley character U+1F600.
Invalid input values will return an empty string, chr(0) is always treated
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.
The chr() function is supposed to return valid unicode characters in utf-8
encoding, so for example "echo(chr(128512));" is valid and should give the
smiley character U+1F600.
Invalid input values will return an empty string, chr(0) is always treated
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.
F
Fantome
Fri, Apr 17, 2015 3:20 AM
The chr() function is supposed to return valid unicode characters in utf-8
encoding, so for example "echo(chr(128512));" is valid and should give the
smiley character U+1F600.
Invalid input values will return an empty string, chr(0) is always treated
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):
{
xFF(count);
}
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: http://forum.openscad.org/How-to-detect-chr-0-tp12351p12396.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
tp3 wrote
> The chr() function is supposed to return valid unicode characters in utf-8
> encoding, so for example "echo(chr(128512));" is valid and should give the
> smiley character U+1F600.
>
> Invalid input values will return an empty string, chr(0) is always treated
> 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):
{
xFF(count);
}
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: http://forum.openscad.org/How-to-detect-chr-0-tp12351p12396.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
F
Fantome
Fri, Apr 17, 2015 3:27 AM
Sorry about those colons in the if statements. My cut&paste seemed to have
messed things up a bit.
--
View this message in context: http://forum.openscad.org/How-to-detect-chr-0-tp12351p12397.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Sorry about those colons in the if statements. My cut&paste seemed to have
messed things up a bit.
--
View this message in context: http://forum.openscad.org/How-to-detect-chr-0-tp12351p12397.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
M
MichaelAtOz
Fri, Apr 17, 2015 3:39 AM
Your logic is a bit off there.
Basically your test is 'if(chr(255)==chr(255))'
Unfortunately, OpenSCAD doesn't (yet?) have a asc() function (or whatever
the unicode version would be called).
Unless specifically shown otherwise above, my contribution is in the Public Domain; To the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. This work is published globally via the internet. :) Inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/How-to-detect-chr-0-tp12351p12398.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Your logic is a bit off there.
Basically your test is 'if(chr(255)==chr(255))'
Unfortunately, OpenSCAD doesn't (yet?) have a asc() function (or whatever
the unicode version would be called).
-----
Unless specifically shown otherwise above, my contribution is in the Public Domain; To the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. This work is published globally via the internet. :) Inclusion of works of previous authors is not included in the above.
The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/
--
View this message in context: http://forum.openscad.org/How-to-detect-chr-0-tp12351p12398.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
DM
doug moen
Fri, Apr 17, 2015 12:09 PM
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
point.
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
float, either.
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@brownsbrain.com 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):
{
xFF(count);
}
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:
http://forum.openscad.org/How-to-detect-chr-0-tp12351p12396.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
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
point.
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
float, either.
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@brownsbrain.com> wrote:
> tp3 wrote
> > The chr() function is supposed to return valid unicode characters in
> utf-8
> > encoding, so for example "echo(chr(128512));" is valid and should give
> the
> > smiley character U+1F600.
> >
> > Invalid input values will return an empty string, chr(0) is always
> treated
> > 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):
> {
> xFF(count);
> }
> 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:
> http://forum.openscad.org/How-to-detect-chr-0-tp12351p12396.html
> Sent from the OpenSCAD mailing list archive at Nabble.com.
>
> _______________________________________________
> OpenSCAD mailing list
> Discuss@lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
>
F
Fantome
Fri, Apr 17, 2015 4:15 PM
Your logic is a bit off there.
Basically your test is 'if(chr(255)==chr(255))'
Unfortunately, OpenSCAD doesn't (yet?) have a asc() function (or whatever
the unicode version would be called).
Yes, thanks. This is really just an example that represents my code. The
actual code is many lines now. Basically it compares each character of
the_text to the values from 0 to 255. This is, as I'm sure everybody here
knows, the same as 0x00 to 0xFF. For example sake, I only included the
condition that finds the 0xFF. Once I clean up my code I'll post it here or
somewhere so people can enjoy it - tearing it apart or marveling at it.
Either way it will be working at that point. (chr(0) is only part not
working yet.)
... I should have pointed out that this code was only an example to show the
comparison and what it printed out.
--
View this message in context: http://forum.openscad.org/How-to-detect-chr-0-tp12351p12403.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
MichaelAtOz wrote
> Your logic is a bit off there.
>
> Basically your test is 'if(chr(255)==chr(255))'
>
> Unfortunately, OpenSCAD doesn't (yet?) have a asc() function (or whatever
> the unicode version would be called).
Yes, thanks. This is really just an example that represents my code. The
actual code is many lines now. Basically it compares each character of
the_text to the values from 0 to 255. This is, as I'm sure everybody here
knows, the same as 0x00 to 0xFF. For example sake, I only included the
condition that finds the 0xFF. Once I clean up my code I'll post it here or
somewhere so people can enjoy it - tearing it apart or marveling at it.
Either way it will be working at that point. (chr(0) is only part not
working yet.)
... I should have pointed out that this code was only an example to show the
comparison and what it printed out.
--
View this message in context: http://forum.openscad.org/How-to-detect-chr-0-tp12351p12403.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
F
Fantome
Fri, Apr 17, 2015 4:29 PM
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
point.
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
float, either.
Your test program contains the word ASCII several times, but that's
misleading, you don't have access to the underlying byte representation.
Hello.
It's interesting to hear about the inner working of this. If OpenSCAD had
the ability to let users manipulate the bits the possibilities for modelling
objects and systems would be increased. Just my opinion of course.
When OpenScad echos/prints the chr(value), what it prints matches with the
ASCII chart. This is why I named the variable ASCII_value. I don't think
it's misleading. It is the ASCII value. It works for all 255 values, value 0
is the only one that is ignored by OpenSCAD.
For my specific application I guess I'll just figure out a work around since
it seems obvious now that OpenSCAD is treating chr(0) as a 'something' that
is not used in any comparison. The inner workings of OpenSCAD must have
checks for a NULL character or chr(0) that equates to 'jump to the next
character'. Oh well. One disappointment out of 256 values, still 99.61%
satisfaction.
--
View this message in context: http://forum.openscad.org/How-to-detect-chr-0-tp12351p12405.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
doug.moen wrote
> 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
> point.
>
> 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
> float, either.
>
> Your test program contains the word ASCII several times, but that's
> misleading, you don't have access to the underlying byte representation.
Hello.
It's interesting to hear about the inner working of this. If OpenSCAD had
the ability to let users manipulate the bits the possibilities for modelling
objects and systems would be increased. Just my opinion of course.
When OpenScad echos/prints the chr(value), what it prints matches with the
ASCII chart. This is why I named the variable ASCII_value. I don't think
it's misleading. It is the ASCII value. It works for all 255 values, value 0
is the only one that is ignored by OpenSCAD.
For my specific application I guess I'll just figure out a work around since
it seems obvious now that OpenSCAD is treating chr(0) as a 'something' that
is not used in any comparison. The inner workings of OpenSCAD must have
checks for a NULL character or chr(0) that equates to 'jump to the next
character'. Oh well. One disappointment out of 256 values, still 99.61%
satisfaction.
--
View this message in context: http://forum.openscad.org/How-to-detect-chr-0-tp12351p12405.html
Sent from the OpenSCAD mailing list archive at Nabble.com.