From: Yukihiro Matsumoto Date: 2011-01-23T07:59:57+09:00 Subject: [ruby-core:34799] Re: [Ruby 1.9-Bug#4298] Duration of calling String#[] with the same index is strangely related to string length. Hi, In message "Re: [ruby-core:34793] [Ruby 1.9-Bug#4298] Duration of calling String#[] with the same index is strangely related to string length." on Sun, 23 Jan 2011 03:42:20 +0900, Charles Nutter writes: |Perhaps I'm mistaken, but isn't RSTRING_LEN the byte length of the string? Isn't that always guaranteed to be >= str_strlen, which is the character length? And doesn't this patch basically break completely if beg is greater than the encoded character length but not greater than the raw byte length? RSTRING_LEN is the byte length of the string, but we can assume RSTRING_LEN > str_strlen(str,enc), I think. |I believe this is one reason Python 3+ allows you to force all strings to be either UTF-8 or UTF-32 in-memory, and only supports those two encodings. It is also one of the original reasons Java and .NET chose to use UTF-16, though that obviously became a small problem when Unicode expanded to 24 bits... Unfortunately, UTF-16 is no longer fixed length encoding since introduction of surrogate pairs. Almost same for UTF-32 with IVS. matz.