mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-11 16:50:42 +00:00
Add a couple of MacOS-X methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@19678 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
fe0bcb1de3
commit
49d11595cd
3 changed files with 180 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2004-07-04 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSString.m: Added two new methods from MacOS-X
|
||||||
|
([stringByAddingPercentEscapesUsingEncoding:]) and
|
||||||
|
([stringByReplacingPercentEscapesUsingEncoding:])
|
||||||
|
|
||||||
2004-07-03 Richard Frith-Macdonald <rfm@gnu.org>
|
2004-07-03 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Tools/plmerge.m: Portability ... was attempting to set values in a
|
* Tools/plmerge.m: Portability ... was attempting to set values in a
|
||||||
|
|
|
@ -289,9 +289,11 @@ enum {
|
||||||
forRange: (NSRange)aRange;
|
forRange: (NSRange)aRange;
|
||||||
- (NSRange) lineRangeForRange: (NSRange)aRange;
|
- (NSRange) lineRangeForRange: (NSRange)aRange;
|
||||||
- (const char*) lossyCString;
|
- (const char*) lossyCString;
|
||||||
|
- (NSString*) stringByAddingPercentEscapesUsingEncoding: (NSStringEncoding)e;
|
||||||
- (NSString*) stringByPaddingToLength: (unsigned int)newLength
|
- (NSString*) stringByPaddingToLength: (unsigned int)newLength
|
||||||
withString: (NSString*)padString
|
withString: (NSString*)padString
|
||||||
startingAtIndex: (unsigned int)padIndex;
|
startingAtIndex: (unsigned int)padIndex;
|
||||||
|
- (NSString*) stringByReplacingPercentEscapesUsingEncoding: (NSStringEncoding)e;
|
||||||
- (NSString*) stringByTrimmingCharactersInSet: (NSCharacterSet*)aSet;
|
- (NSString*) stringByTrimmingCharactersInSet: (NSCharacterSet*)aSet;
|
||||||
- (const char *)UTF8String;
|
- (const char *)UTF8String;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1593,7 +1593,82 @@ handle_printf_atsign (FILE *stream,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combining Strings
|
/**
|
||||||
|
* Constructs a new ASCII string which is a representation of the receiver
|
||||||
|
* in which characters are esacped where necessary in order to produce a
|
||||||
|
* legal URL.<br />
|
||||||
|
* Returns nil if the receiver cannot be represented using the specified
|
||||||
|
* encoding.
|
||||||
|
*/
|
||||||
|
- (NSString*) stringByAddingPercentEscapesUsingEncoding: (NSStringEncoding)e
|
||||||
|
{
|
||||||
|
NSData *data = [self dataUsingEncoding: e];
|
||||||
|
NSString *s = nil;
|
||||||
|
|
||||||
|
if (data != nil)
|
||||||
|
{
|
||||||
|
unsigned char *src = (unsigned char*)[data bytes];
|
||||||
|
unsigned int slen = [data length];
|
||||||
|
NSMutableData *d = [[NSMutableData alloc] initWithLength: slen * 3];
|
||||||
|
unsigned char *dst = (unsigned char*)[d mutableBytes];
|
||||||
|
unsigned int spos = 0;
|
||||||
|
unsigned int dpos = 0;
|
||||||
|
|
||||||
|
while (spos < slen)
|
||||||
|
{
|
||||||
|
unsigned char c = src[spos++];
|
||||||
|
unsigned int hi;
|
||||||
|
unsigned int lo;
|
||||||
|
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case ',':
|
||||||
|
case ';':
|
||||||
|
case '"':
|
||||||
|
case '\'':
|
||||||
|
case '&':
|
||||||
|
case '=':
|
||||||
|
case '(':
|
||||||
|
case ')':
|
||||||
|
case '<':
|
||||||
|
case '>':
|
||||||
|
case '?':
|
||||||
|
case '#':
|
||||||
|
case '{':
|
||||||
|
case '}':
|
||||||
|
case '%':
|
||||||
|
case ' ':
|
||||||
|
case '+':
|
||||||
|
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;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if (c < ' ' || c > 127)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[d setLength: dpos];
|
||||||
|
s = [[NSString alloc] initWithData: d encoding: NSASCIIStringEncoding];
|
||||||
|
RELEASE(d);
|
||||||
|
AUTORELEASE(s);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new string consisting of this instance followed by the string
|
* Constructs a new string consisting of this instance followed by the string
|
||||||
|
@ -3586,6 +3661,102 @@ handle_printf_atsign (FILE *stream,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string created by replacing percent escape sequences in the
|
||||||
|
* receiver assuning that the resulting data represents characters in
|
||||||
|
* the specified encoding.<br />
|
||||||
|
* Returns nil if the ressult is not a string in the specified encoding.
|
||||||
|
*/
|
||||||
|
- (NSString*) stringByReplacingPercentEscapesUsingEncoding: (NSStringEncoding)e
|
||||||
|
{
|
||||||
|
NSMutableData *d;
|
||||||
|
NSString *s = nil;
|
||||||
|
|
||||||
|
d = [[self dataUsingEncoding: NSASCIIStringEncoding] mutableCopy];
|
||||||
|
if (d != nil)
|
||||||
|
{
|
||||||
|
unsigned char *p = (unsigned char*)[d mutableBytes];
|
||||||
|
unsigned l = [d length];
|
||||||
|
unsigned i = 0;
|
||||||
|
unsigned j = 0;
|
||||||
|
|
||||||
|
while (i < l)
|
||||||
|
{
|
||||||
|
unsigned char t;
|
||||||
|
|
||||||
|
if ((t = p[i++]) == '%')
|
||||||
|
{
|
||||||
|
unsigned char c;
|
||||||
|
|
||||||
|
if (i >= l)
|
||||||
|
{
|
||||||
|
DESTROY(d);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
t = p[i++];
|
||||||
|
|
||||||
|
if (isxdigit(t))
|
||||||
|
{
|
||||||
|
if (t <= '9')
|
||||||
|
{
|
||||||
|
c = t - '0';
|
||||||
|
}
|
||||||
|
else if (t <= 'A')
|
||||||
|
{
|
||||||
|
c = t - 'A' + 10;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
c = t - 'a' + 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DESTROY(d);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
c <<= 4;
|
||||||
|
|
||||||
|
if (i >= l)
|
||||||
|
{
|
||||||
|
DESTROY(d);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
t = p[i++];
|
||||||
|
if (isxdigit(t))
|
||||||
|
{
|
||||||
|
if (t <= '9')
|
||||||
|
{
|
||||||
|
c |= t - '0';
|
||||||
|
}
|
||||||
|
else if (t <= 'A')
|
||||||
|
{
|
||||||
|
c |= t - 'A' + 10;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
c |= t - 'a' + 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DESTROY(d);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
p[j++] = c;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p[j++] = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[d setLength: j];
|
||||||
|
s = AUTORELEASE([[NSString alloc] initWithData: d encoding: e]);
|
||||||
|
RELEASE(d);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces path string by one in which path components representing symbolic
|
* Replaces path string by one in which path components representing symbolic
|
||||||
* links have been replaced by their referents.
|
* links have been replaced by their referents.
|
||||||
|
|
Loading…
Reference in a new issue