aboutsummaryrefslogtreecommitdiff
path: root/Foundation/GTMNSString+HTML.m
diff options
context:
space:
mode:
authorGravatar thomasvl <thomasvl@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2008-05-09 18:53:09 +0000
committerGravatar thomasvl <thomasvl@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2008-05-09 18:53:09 +0000
commitf90bcf3263b80b96754977ddbd5309704cf817fb (patch)
tree585db4c1126cea3bd0ff9b338628d33febe36e59 /Foundation/GTMNSString+HTML.m
parente5c365c04b9f2f6d04b2c5bd828f39fab2882e7d (diff)
Flush out suppport for 64bit, GC support.
Added some more xcode configs related to the above. Removed some classes that the unittesting doesn't need (and aren't able to support 64bit). add base64, httpfetcher, and progress monitor stream.
Diffstat (limited to 'Foundation/GTMNSString+HTML.m')
-rw-r--r--Foundation/GTMNSString+HTML.m37
1 files changed, 25 insertions, 12 deletions
diff --git a/Foundation/GTMNSString+HTML.m b/Foundation/GTMNSString+HTML.m
index a6abb0e..5178ba9 100644
--- a/Foundation/GTMNSString+HTML.m
+++ b/Foundation/GTMNSString+HTML.m
@@ -19,8 +19,6 @@
#import "GTMDefines.h"
#import "GTMNSString+HTML.h"
-#import "GTMNSString+Utilities.h"
-#import "GTMMethodCheck.h"
typedef struct {
NSString *escapeSequence;
@@ -373,23 +371,38 @@ static int EscapeMapCompare(const void *ucharVoid, const void *mapVoid) {
}
@implementation NSString (GTMNSStringHTMLAdditions)
-GTM_METHOD_CHECK(NSString, gtm_UTF16StringWithLength:);
- (NSString *)gtm_stringByEscapingHTMLUsingTable:(HTMLEscapeMap*)table
- ofSize:(int)size
+ ofSize:(NSUInteger)size
escapingUnicode:(BOOL)escapeUnicode {
- int length = [self length];
+ NSUInteger length = [self length];
if (!length) {
- return nil;
+ return self;
}
NSMutableString *finalString = [NSMutableString string];
-
NSMutableData *data2 = [NSMutableData dataWithCapacity:sizeof(unichar) * length];
- const unichar *buffer = (const unichar *)[self gtm_UTF16StringWithLength:nil];
+
+ // this block is common between GTMNSString+HTML and GTMNSString+XML but
+ // it's so short that it isn't really worth trying to share.
+ const unichar *buffer = CFStringGetCharactersPtr((CFStringRef)self);
+ if (!buffer) {
+ size_t memsize = length * sizeof(UniChar);
+
+ // nope, alloc buffer and fetch the chars ourselves
+ buffer = malloc(memsize);
+ if (!buffer) {
+ // COV_NF_START - Memory fail case
+ _GTMDevLog(@"couldn't alloc buffer");
+ return nil;
+ // COV_NF_END
+ }
+ [self getCharacters:(void*)buffer];
+ [NSData dataWithBytesNoCopy:(void*)buffer length:memsize];
+ }
if (!buffer || !data2) {
- // COV_NF_BEGIN
+ // COV_NF_START
_GTMDevLog(@"Unable to allocate buffer or data2");
return nil;
// COV_NF_END
@@ -397,9 +410,9 @@ GTM_METHOD_CHECK(NSString, gtm_UTF16StringWithLength:);
unichar *buffer2 = (unichar *)[data2 mutableBytes];
- int buffer2Length = 0;
+ NSUInteger buffer2Length = 0;
- for (int i = 0; i < length; ++i) {
+ for (NSUInteger i = 0; i < length; ++i) {
HTMLEscapeMap *val = bsearch(&buffer[i], table,
size / sizeof(HTMLEscapeMap),
sizeof(HTMLEscapeMap), EscapeMapCompare);
@@ -459,7 +472,7 @@ GTM_METHOD_CHECK(NSString, gtm_UTF16StringWithLength:);
}
NSRange escapeRange = NSMakeRange(subrange.location, semiColonRange.location - subrange.location + 1);
NSString *escapeString = [self substringWithRange:escapeRange];
- unsigned length = [escapeString length];
+ NSUInteger length = [escapeString length];
// a squence must be longer than 3 (&lt;) and less than 11 (&thetasym;)
if (length > 3 && length < 11) {
if ([escapeString characterAtIndex:1] == '#') {