diff --git a/Source/Additions/GSXML.m b/Source/Additions/GSXML.m index 1a853c572..12abd2edc 100644 --- a/Source/Additions/GSXML.m +++ b/Source/Additions/GSXML.m @@ -1411,15 +1411,20 @@ static NSMapTable *nodeNames = 0; - (NSString*) objectForKey: (NSString*)key { NSString *value = nil; + const char *str = 0; xmlAttrPtr prop; prop = ((xmlNodePtr)(lib))->properties; while (prop != NULL) { const void *name = prop->name; - NSString *n = UTF8Str(name); - if ([key isEqualToString: n] == YES) + if (0 == str) + { + str = [key UTF8String]; + } + + if (strcmp(str, name) == 0) { xmlNodePtr child = prop->children; diff --git a/Source/GSString.m b/Source/GSString.m index 8d8a1226a..54f19937a 100644 --- a/Source/GSString.m +++ b/Source/GSString.m @@ -1671,6 +1671,61 @@ fixBOM(unsigned char **bytes, NSUInteger*length, BOOL *owned, return (id)me; } +- (id) initWithUTF8String: (const char*)bytes +{ + BOOL ascii = YES; + NSUInteger length; + GSStr me; + + if (0 == bytes) + { + return (id)@""; + } + /* Skip leading BOM + */ + if (bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF) + { + bytes = &bytes[3]; + } + if (0 == bytes[0]) + { + return (id)@""; + } + + for (length = 0; bytes[length]; length++) + { + if (bytes[length] > 127) + { + ascii = NO; + } + } + + if (YES == ascii) + { + me = (GSStr)newCInline(length, [self zone]); + memcpy(me->_contents.c, bytes, length); + return (id)me; + } + else + { + const unsigned char *b = (const unsigned char*)bytes; + NSZone *z = [self zone]; + unichar *u = 0; + unsigned l = 0; + + if (GSToUnicode(&u, &l, b, length, NSUTF8StringEncoding, z, 0) == NO) + { + return nil; // Invalid data + } + me = (GSStr)NSAllocateObject(GSUnicodeBufferStringClass, 0, z); + me->_contents.u = u; + me->_count = l; + me->_flags.wide = 1; + me->_flags.owned = YES; + } + return (id)me; +} + - (NSUInteger) length { [NSException raise: NSInternalInconsistencyException diff --git a/Source/NSString.m b/Source/NSString.m index e7634606d..cd63857a8 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -981,7 +981,14 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale) if (NULL == bytes) [NSException raise: NSInvalidArgumentException format: @"[NSString+stringWithUTF8String:]: NULL cString"]; - obj = [self allocWithZone: NSDefaultMallocZone()]; + if (self == NSStringClass) + { + obj = defaultPlaceholderString; + } + else + { + obj = [self allocWithZone: NSDefaultMallocZone()]; + } obj = [obj initWithUTF8String: bytes]; return AUTORELEASE(obj); }