Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -189,10 +189,15 @@ /** * \return The OFString as a UTF-8 encoded C string */ - (const char*)cString; +/** + * \return The length of the string in Unicode characters + */ +- (size_t)length; + /** * \return The length of the string which cString would return */ - (size_t)cStringLength; Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -501,10 +501,17 @@ - (const char*)cString { return string; } + +- (size_t)length +{ + /* FIXME: Maybe cache this in an ivar? */ + + return of_string_position_to_index(string, length); +} - (size_t)cStringLength { return length; } Index: tests/string.m ================================================================== --- tests/string.m +++ tests/string.m @@ -44,11 +44,11 @@ OFString *s[3]; OFArray *a; int i; EntityHandler *h; - s[0] = [OFMutableString stringWithString: @"test"]; + s[0] = [OFMutableString stringWithString: @"täs€"]; s[1] = [OFMutableString string]; s[2] = [[s[0] copy] autorelease]; TEST(@"-[isEqual:]", [s[0] isEqual: s[2]] && ![s[0] isEqual: [[[OFObject alloc] init] autorelease]]) @@ -58,16 +58,19 @@ TEST(@"-[hash] is the same if -[isEqual:] is YES", [s[0] hash] == [s[2] hash]) TEST(@"-[appendString:] and -[appendCString:]", - [s[1] appendCString: "12"] && [s[1] appendString: @"3"] && - [[s[0] appendString: s[1]] isEqual: @"test123"]) + [s[1] appendCString: "1𝄞"] && [s[1] appendString: @"3"] && + [[s[0] appendString: s[1]] isEqual: @"täs€1𝄞3"]) + + TEST(@"-[length]", [s[0] length] == 7) + TEST(@"-[cStringLength]", [s[0] cStringLength] == 13) + TEST(@"-[hash]", [s[0] hash] == 0x8AC1EEF6) + TEST(@"-[reverse]", [[s[0] reverse] isEqual: @"3𝄞1€sät"]) - TEST(@"-[cStringLength]", [s[0] cStringLength] == 7) - TEST(@"-[hash]", [s[0] hash] == 0xC44F49A4) - TEST(@"-[reverse]", [[s[0] reverse] isEqual: @"321tset"]) + s[0] = [OFMutableString stringWithString: @"321tset"]; TEST(@"-[upper]", [[s[0] upper] isEqual: @"321TSET"]) TEST(@"-[lower]", [[s[0] lower] isEqual: @"321tset"]) TEST(@"+[stringWithCString:length:]", (s[0] = [OFMutableString stringWithCString: "foobar"