Re: [Vala] Possible but in string.index_of, index_of_char and contains



On Thu, 2013-10-17 at 09:19 +0800, Nor Jaidi Tuah wrote:
"ABC".index_of_char('\x00'):  0

This looks like a bug. But why should
you want to search for \x00 ?

string.index_of_char is basically a wrapper around g_utf8_strchr.  I
guess g_utf8_strchr could return null if c==0, but it does feel a bit
ridiculous.  If you feel strongly about it you can file a bug against
glib.

Strings in Vala (and C) can't really contain NUL since NUL is used to
mark the end of a string, and it isn't typically considered to be part
of the string (i.e., strlen() doesn't include it).  To put it another
way, string.index_of_char('\x00') is basically asking, "What is the
index of the first occurrence of NUL before the first occurrence of
NUL?".

"ABC".index_of("\x00"):  0
"ABC".contains("\x00"):  true

These 2 lines should be okay because vala
strings are really C strings.
Thus, "\x00" is equivalent to "".
(Or, I have just revealed my ignorance
concerning vala strings).

Nope, that's basically right.


-E



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