Mailinglist Archive: yast-devel (50 mails)

< Previous Next >
Re: [yast-devel] YCP String operator [] and UTF-8
On Fri, 30 Mar 2012 17:01:04 +0200
Ladislav Slezak <lslezak@xxxxxxx> wrote:

Hi all,

This is just a note for you in case you came across a strange UTF-8 string
problem in
YCP (maybe you already know that but for me it was quite a surprise):

YCP string operator [] takes _byte_ index in the string, while size(string)
_number_of_characters_. The problem is when you combine both functions, the
will be probably buggy, see

Example from the bug:

size("áa") => 2,


"áa"[1] is not "a" as expected but the second _byte_ of the string which is
half of the "á" UTF-8 character, if you remove it you'll get garbage in the

Keep this in your mind when iterating over YCP strings...

(I'm not sure whether fixing YCPString::[] would be a good idea, it might
something else. Martin?)

When I compare behaviour to other languages like wstring in C++ or ruby string,
I see this behaviour really strange. operator[] is expected to return element
at given position. For a lot of programmer , which don't have ycp as first
first language, is string is array of character ( not bytes ).
So I really vote for change of this behaviour.


Ladislav Slezák
Appliance department / YaST Developer
Lihovarská 1060/12
190 00 Prague 9 / Czech Republic
tel: +420 284 028 960

To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: yast-devel+owner@xxxxxxxxxxxx

< Previous Next >
List Navigation