Initial/untested implementation of new string function.

This commit is contained in:
Gregory John Casamento 2019-04-09 02:28:54 -04:00
parent b1f47e6f22
commit 613d90c193

View file

@ -1886,6 +1886,59 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
}
}
- (NSString *) stringByAddingPercentWithAllowedCharacters: (NSCharacterSet *)aSet
{
NSData *data = [self dataUsingEncoding: NSUTF8StringEncoding];
NSString *s = nil;
if (data != nil)
{
unsigned char *src = (unsigned char*)[data bytes];
unsigned int slen = [data length];
unsigned char *dst;
unsigned int spos = 0;
unsigned int dpos = 0;
dst = (unsigned char*)NSZoneMalloc(NSDefaultMallocZone(), slen * 3);
while (spos < slen)
{
unsigned char c = src[spos++];
unsigned int hi;
unsigned int lo;
if([aSet characterIsMember: c])
{
if (c <= 32 || c > 126 || c == 34 || c == 35 || c == 37
|| c == 60 || c == 62 || c == 91 || c == 92 || c == 93
|| c == 94 || c == 96 || c == 123 || c == 124 || c == 125)
{
dst[dpos++] = '%';
hi = (c & 0xf0) >> 4;
dst[dpos++] = (hi > 9) ? 'A' + hi - 10 : '0' + hi;
lo = (c & 0x0f);
dst[dpos++] = (lo > 9) ? 'A' + lo - 10 : '0' + lo;
}
else
{
dst[dpos++] = c;
}
}
s = [[NSString alloc] initWithBytes: dst
length: dpos
encoding: NSASCIIStringEncoding];
NSZoneFree(NSDefaultMallocZone(), dst);
IF_NO_GC([s autorelease];)
}
}
return s;
}
- (NSString *) stringByRemovingEscapeEncoding
{
return nil;
}
/**
* Constructs a new ASCII string which is a representation of the receiver
* in which characters are escaped where necessary in order to produce a
@ -1949,16 +2002,6 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
return s;
}
- (NSString *) stringByAddingPercentWithAllowedCharacters: (NSCharacterSet *)aSet
{
return nil;
}
- (NSString *) stringByRemovingEscapeEncoding
{
return nil;
}
/**
* Constructs a new string consisting of this instance followed by the string
* specified by format.