From b3086cfd9aead0b2900c2d942b289957837286ab Mon Sep 17 00:00:00 2001 From: thomasvl Date: Fri, 1 Feb 2008 20:16:57 +0000 Subject: - Fixed up the prefix header of the project and prefix handing in the Unittest Xcode Config. (thanks schafdog) - Fixed error in handling default compression for NSData+zlib - Changed name on API in NSString+XML and added another api to make this a litte more clear. (thanks Kent) --- Foundation/GTMNSData+zlib.m | 5 ++- Foundation/GTMNSString+XML.h | 14 +++++- Foundation/GTMNSString+XML.m | 77 +++++++++++++++++++++------------ Foundation/GTMNSString+XMLTest.m | 31 +++++++++---- Foundation/GTMObjectSingleton.h | 4 +- GTM.xcodeproj/project.pbxproj | 6 ++- ReleaseNotes.txt | 21 ++++++++- XcodeConfig/subconfig/Unittest.xcconfig | 4 -- 8 files changed, 115 insertions(+), 47 deletions(-) diff --git a/Foundation/GTMNSData+zlib.m b/Foundation/GTMNSData+zlib.m index 89a906a..be84114 100644 --- a/Foundation/GTMNSData+zlib.m +++ b/Foundation/GTMNSData+zlib.m @@ -35,7 +35,10 @@ useGzip:(BOOL)useGzip { if (!bytes || !length) return nil; - if (level < Z_BEST_SPEED) + if (level == Z_DEFAULT_COMPRESSION) { + // the default value is actually outside the range, so we have to let it + // through specifically. + } else if (level < Z_BEST_SPEED) level = Z_BEST_SPEED; else if (level > Z_BEST_COMPRESSION) level = Z_BEST_COMPRESSION; diff --git a/Foundation/GTMNSString+XML.h b/Foundation/GTMNSString+XML.h index ed2d161..6ef54d7 100644 --- a/Foundation/GTMNSString+XML.h +++ b/Foundation/GTMNSString+XML.h @@ -31,7 +31,19 @@ // Returns: // Autoreleased NSString // -- (NSString *)gtm_stringByEscapingForXML; +- (NSString *)gtm_stringBySanitizingAndEscapingForXML; + +/// Get a string where characters that invalid characters per the XML spec have been removed +// +/// This call removes all invalid characters as defined by Section 2.2 of the +/// xml spec. If you are writing XML yourself, you probably was to use the +/// above api (gtm_stringBySanitizingAndEscapingForXML) so any entities also +/// get escaped. +// +// Returns: +// Autoreleased NSString +// +- (NSString *)gtm_stringBySanitizingToXMLSpec; // There is no stringByUnescapingFromXML because the XML parser will do this. // The above api is here just incase you need to create XML yourself. diff --git a/Foundation/GTMNSString+XML.m b/Foundation/GTMNSString+XML.m index edc82a0..c08f7b7 100644 --- a/Foundation/GTMNSString+XML.m +++ b/Foundation/GTMNSString+XML.m @@ -17,6 +17,7 @@ // #import "GTMNSString+XML.h" +#import "GTMGarbageCollection.h" typedef enum { kGMXMLCharModeEncodeQUOT = 0, @@ -37,12 +38,12 @@ static NSString *gXMLEntityList[] = { @">", }; -FOUNDATION_STATIC_INLINE GMXMLCharMode XMLModeForUnichar(unichar c) { +FOUNDATION_STATIC_INLINE GMXMLCharMode XMLModeForUnichar(UniChar c) { // Per XML spec Section 2.2 Characters // ( http://www.w3.org/TR/REC-xml/#charsets ) // - // Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | + // Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | // [#x10000-#x10FFFF] if (c <= 0xd7ff) { @@ -78,7 +79,7 @@ FOUNDATION_STATIC_INLINE GMXMLCharMode XMLModeForUnichar(unichar c) { if (c <= 0xFFFD) return kGMXMLCharModeValid; - // unichar can't have the following values + // UniChar can't have the following values // if (c < 0x10000) // return kGMXMLCharModeInvalid; // if (c <= 0x10FFFF) @@ -87,60 +88,72 @@ FOUNDATION_STATIC_INLINE GMXMLCharMode XMLModeForUnichar(unichar c) { return kGMXMLCharModeInvalid; } // XMLModeForUnichar -@implementation NSString (GTMNSStringXMLAdditions) - -- (NSString *)gtm_stringByEscapingForXML { +static NSString *AutoreleasedCloneForXML(NSString *src, BOOL escaping) { + // + // NOTE: + // We don't use CFXMLCreateStringByEscapingEntities because it's busted in + // 10.3 (http://lists.apple.com/archives/Cocoa-dev/2004/Nov/msg00059.html) and + // it doesn't do anything about the chars that are actually invalid per the + // xml spec. + // + + // we can't use the CF call here because it leaves the invalid chars + // in the string. + NSMutableString *finalString = [NSMutableString string]; - int length = [self length]; + int length = [src length]; require_quiet(length != 0, cantConvertAnything); - + // see if we can just use the interal version BOOL freeBuffer = NO; - unichar *buffer = (unichar*)CFStringGetCharactersPtr((CFStringRef)self); + UniChar *buffer = (UniChar*)CFStringGetCharactersPtr((CFStringRef)src); if (!buffer) { // nope, alloc buffer and fetch the chars ourselves - buffer = malloc(sizeof(unichar) * length); - if (!buffer) return nil; + buffer = malloc(sizeof(UniChar) * length); + require_action(buffer, cantCreateString, finalString = nil); freeBuffer = YES; - [self getCharacters:buffer]; + [src getCharacters:buffer]; } - - unichar *goodRun = buffer; + + UniChar *goodRun = buffer; int goodRunLength = 0; - + for (int i = 0; i < length; ++i) { - + GMXMLCharMode cMode = XMLModeForUnichar(buffer[i]); - - if (cMode == kGMXMLCharModeValid) { + + // valid chars go as is, and if we aren't doing entities, then + // everything goes as is. + if ((cMode == kGMXMLCharModeValid) || + (!escaping && (cMode != kGMXMLCharModeInvalid))) { // goes as is goodRunLength += 1; } else { // it's something we have to encode or something invalid - + // start by adding what we already collected (if anything) if (goodRunLength) { CFStringRef goodRunString = - CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, - goodRun, goodRunLength, - kCFAllocatorNull); + CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, + goodRun, goodRunLength, + kCFAllocatorNull); require_action(goodRunString != NULL, cantCreateString, finalString = nil); [finalString appendString:(NSString*)goodRunString]; CFRelease(goodRunString); goodRunLength = 0; } - + // if it wasn't invalid, add the encoded version if (cMode != kGMXMLCharModeInvalid) { // add this encoded [finalString appendString:gXMLEntityList[cMode]]; } - - // update goodRun to point to the next unichar + + // update goodRun to point to the next UniChar goodRun = buffer + i + 1; } } - + // anything left to add? if (goodRunLength) { CFStringRef goodRunString = @@ -157,6 +170,16 @@ cantCreateString2: free(buffer); cantConvertAnything: return finalString; -} // gtm_stringByEscapingForXML +} // AutoreleasedCloneForXML + +@implementation NSString (GTMNSStringXMLAdditions) + +- (NSString *)gtm_stringBySanitizingAndEscapingForXML { + return AutoreleasedCloneForXML(self, YES); +} // gtm_stringBySanitizingAndEscapingForXML + +- (NSString *)gtm_stringBySanitizingToXMLSpec { + return AutoreleasedCloneForXML(self, NO); +} // gtm_stringBySanitizingToXMLSpec @end diff --git a/Foundation/GTMNSString+XMLTest.m b/Foundation/GTMNSString+XMLTest.m index c53ce64..52834f5 100644 --- a/Foundation/GTMNSString+XMLTest.m +++ b/Foundation/GTMNSString+XMLTest.m @@ -26,19 +26,34 @@ @implementation GTMNSString_XMLTest -- (void)testStringByEscapingForXML { - unichar chars[] = - { 0, 'z', 1, 'z', 4, 'z', 5, 'z', 34, 'z', 38, 'z', 39, 'z', +- (void)testStringBySanitizingAndEscapingForXML { + UniChar chars[] = { + 'z', 0, 'z', 1, 'z', 4, 'z', 5, 'z', 34, 'z', 38, 'z', 39, 'z', 60, 'z', 62, 'z', ' ', 'z', 0xd800, 'z', 0xDFFF, 'z', 0xFFFE, - 0xFFFF, 'z' }; + 'z', 0xFFFF, 'z' }; NSString *string1 = [NSString stringWithCharacters:chars - length:sizeof(chars) / sizeof(unichar)]; - NSString *string2 = @"zzzz"z&z'z<z>z zzzz"; + length:sizeof(chars) / sizeof(UniChar)]; + NSString *string2 = @"zzzzz"z&z'z<z>z zzzzz"; - STAssertEqualObjects([string1 gtm_stringByEscapingForXML], + STAssertEqualObjects([string1 gtm_stringBySanitizingAndEscapingForXML], string2, - @"Escaped for XML failed"); + @"Sanitize and Escape for XML failed"); +} + +- (void)testStringBySanitizingToXMLSpec { + UniChar chars[] = { + 'z', 0, 'z', 1, 'z', 4, 'z', 5, 'z', 34, 'z', 38, 'z', 39, 'z', + 60, 'z', 62, 'z', ' ', 'z', 0xd800, 'z', 0xDFFF, 'z', 0xFFFE, + 'z', 0xFFFF, 'z' }; + + NSString *string1 = [NSString stringWithCharacters:chars + length:sizeof(chars) / sizeof(UniChar)]; + NSString *string2 = @"zzzzz\"z&z'zz zzzzz"; + + STAssertEqualObjects([string1 gtm_stringBySanitizingToXMLSpec], + string2, + @"Sanitize for XML failed"); } @end diff --git a/Foundation/GTMObjectSingleton.h b/Foundation/GTMObjectSingleton.h index ff03ea0..9bdeb0a 100644 --- a/Foundation/GTMObjectSingleton.h +++ b/Foundation/GTMObjectSingleton.h @@ -35,7 +35,7 @@ static _object_name_ *z##_shared_obj_name_ = nil; \ /* Note that 'self' may not be the same as _object_name_ */ \ /* first assignment done in allocWithZone but we must reassign in case init fails */ \ z##_shared_obj_name_ = [[self alloc] init]; \ - GTMDebugAssert((z##_shared_obj_name_ != nil), @"didn't catch singleton allocation"); \ + NSAssert((z##_shared_obj_name_ != nil), @"didn't catch singleton allocation"); \ } \ } \ return z##_shared_obj_name_; \ @@ -49,7 +49,7 @@ static _object_name_ *z##_shared_obj_name_ = nil; \ } \ \ /* We can't return the shared instance, because it's been init'd */ \ - GTMDebugAssert(NO, @"use the singleton API, not alloc+init"); \ + NSAssert(NO, @"use the singleton API, not alloc+init"); \ return nil; \ } \ - (id)retain { \ diff --git a/GTM.xcodeproj/project.pbxproj b/GTM.xcodeproj/project.pbxproj index f0257ea..9dfd689 100644 --- a/GTM.xcodeproj/project.pbxproj +++ b/GTM.xcodeproj/project.pbxproj @@ -617,6 +617,8 @@ isa = XCBuildConfiguration; baseConfigurationReference = F48FE2410D197F9A009257D2 /* DebugTigerOrLater.xcconfig */; buildSettings = { + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = GTM_Prefix.pch; }; name = Debug; }; @@ -624,6 +626,8 @@ isa = XCBuildConfiguration; baseConfigurationReference = F48FE2440D197F9A009257D2 /* ReleaseTigerOrLater.xcconfig */; buildSettings = { + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = GTM_Prefix.pch; }; name = Release; }; @@ -668,7 +672,6 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; FRAMEWORK_VERSION = A; - GCC_PREFIX_HEADER = GTM_prefix.pch; INFOPLIST_FILE = "GTM-Info.plist"; INSTALL_PATH = "@loader_path/../Frameworks"; PRODUCT_NAME = GTM; @@ -682,7 +685,6 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; FRAMEWORK_VERSION = A; - GCC_PREFIX_HEADER = GTM_prefix.pch; INFOPLIST_FILE = "GTM-Info.plist"; INSTALL_PATH = "@loader_path/../Frameworks"; PRODUCT_NAME = GTM; diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index 0233235..f197504 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -1,5 +1,22 @@ +Google Toolbox for Mac Release Notes + +Project site: http://code.google.com/p/google-toolbox-for-mac/ +Discussion group: http://groups.google.com/group/google-toolbox-for-mac + + +Release ?.?.? +Changes since 1.0.0 + +- Fixed up the prefix header of the project and prefix handing in the Unittest + Xcode Config. (thanks schafdog) +- Fixed error in handling default compression for NSData+zlib +- Changed name on API in NSString+XML and added another api to make this a + litte more clear. (thanks Kent) + + + Release 1.0.0 14-January-2008 -Initial public release. Includes some simple utils, xcode configs, and -some support for doing unit tests of graphical things. +- Initial public release. Includes some simple utils, xcode configs, and + some support for doing unit tests of graphical things. diff --git a/XcodeConfig/subconfig/Unittest.xcconfig b/XcodeConfig/subconfig/Unittest.xcconfig index d3bdee8..a35dc61 100644 --- a/XcodeConfig/subconfig/Unittest.xcconfig +++ b/XcodeConfig/subconfig/Unittest.xcconfig @@ -25,10 +25,6 @@ // Unittests are loadable bundles #include "../LoadableBundle.xcconfig" -// No prefix -GCC_PRECOMPILE_PREFIX_HEADER = NO -GCC_PREFIX_HEADER = - // Force C99 dialect with GNU extensions (needed for OCUnit) GCC_C_LANGUAGE_STANDARD = gnu99 -- cgit v1.2.3