mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Initial/untested implementation of new string function.
This commit is contained in:
parent
b1f47e6f22
commit
613d90c193
1 changed files with 53 additions and 10 deletions
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue