Discussion:
is \000 an ascii value?
Mark Hahn
2004-06-10 05:45:03 UTC
Permalink
Should I throw an exception when I see an ascii value of zero? This is
illegal in C text, but is it legal in unicode in general?
Michael Geary
2004-06-10 06:15:01 UTC
Permalink
From: Mark Hahn
Should I throw an exception when I see an ascii value
of zero? This is illegal in C text, but is it legal in unicode
in general?
Don't throw an exception. Zero is a legal and useful character in C text:

const char szEmbeddedNulls[] = "One\0Two\0Three\0";

That's a character array with embedded \0 characters and terminated by a
pair of \0 characters. Strings like this are used in the DOS/Windows
environment and in the filter string for a GetOpenFileName or
GetSaveFileName call.

-Mike

p.s. Sorry I've been away, especially after bringing up the topic of code
blocks a week or so ago. Meant to get back and follow up on that, will do it
soon...
Jonathan M. Gardner
2004-06-10 06:32:38 UTC
Permalink
Post by Mark Hahn
Should I throw an exception when I see an ascii value of zero? This is
illegal in C text, but is it legal in unicode in general?
No, don't throw an exception.

Yes, \x00 is legal. It is legal in C as well, except that it is used as
the traditional string delimiter. However, if you store the size of the
string, and only use that and ignore \x00, you can use it in strings.
(use memcpy, not strcpy.)
--
Jonathan Gardner
***@jonathangardner.net
Serge Orlov
2004-06-10 06:46:08 UTC
Permalink
Post by Mark Hahn
Should I throw an exception when I see an ascii value of zero? This is
illegal in C text, but is it legal in unicode in general?
\000 is a convention in C, it's not illegal. In unicode it's
legal too.

-- Serge
Greg Ewing
2004-06-11 02:39:42 UTC
Permalink
Post by Mark Hahn
Should I throw an exception when I see an ascii value of zero? This is
illegal in C text, but is it legal in unicode in general?
It's a perfectly valid ASCII code, therefore I would expect it
to be a valid Unicode code, too.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
***@cosc.canterbury.ac.nz +--------------------------------------+
Loading...