mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
All tests passing. Implementation of string and nscharacterset methods completed
This commit is contained in:
parent
f1b48541ae
commit
298f87d24e
4 changed files with 54 additions and 27 deletions
|
@ -802,10 +802,10 @@ typedef NSUInteger NSStringEncodingConversionOptions;
|
|||
- (const char *)UTF8String;
|
||||
#endif
|
||||
|
||||
// #if OS_API_VERSION(MAC_OS_X_VERSION_10_9,GS_API_LATEST)
|
||||
// #if OS_API_VERSION(MAC_OS_X_VERSION_10_9,GS_API_LATEST)
|
||||
- (NSString *) stringByAddingPercentEncodingWithAllowedCharacters: (NSCharacterSet *)aSet;
|
||||
- (NSString *) stringByRemovingPercentEncoding;
|
||||
//#endif
|
||||
//#endif
|
||||
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_3,GS_API_LATEST)
|
||||
/** Not implemented */
|
||||
|
|
|
@ -543,7 +543,7 @@
|
|||
|
||||
|
||||
/* A simple array for caching standard bitmap sets */
|
||||
#define MAX_STANDARD_SETS 15
|
||||
#define MAX_STANDARD_SETS 20
|
||||
static NSCharacterSet *cache_set[MAX_STANDARD_SETS];
|
||||
static Class abstractClass = nil;
|
||||
static Class abstractMutableClass = nil;
|
||||
|
@ -841,10 +841,6 @@ static Class concreteMutableClass = nil;
|
|||
|
||||
+ (id) URLFragmentAllowedCharacterSet;
|
||||
{
|
||||
// NSString *charSetString = @"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?/:@-._~!$&'()*+,=";
|
||||
// NSData *data = [charSetString dataUsingEncoding: NSUTF8StringEncoding];
|
||||
// char *bytes = [data bytes];
|
||||
|
||||
return [self _staticSet: urlFragmentAllowedCharSet
|
||||
length: sizeof(urlFragmentAllowedCharSet)
|
||||
number: 15];
|
||||
|
|
|
@ -276,6 +276,7 @@ GSPathHandling(const char *mode)
|
|||
}
|
||||
}
|
||||
|
||||
// Test if the digit is hex..
|
||||
inline int ishex(int x)
|
||||
{
|
||||
return
|
||||
|
@ -284,6 +285,33 @@ inline int ishex(int x)
|
|||
(x >= 'A' && x <= 'F');
|
||||
}
|
||||
|
||||
// URL decoding...
|
||||
int urldecode(const char *s, char *dec)
|
||||
{
|
||||
char *o;
|
||||
const char *end = s + strlen(s);
|
||||
int c;
|
||||
int cx;
|
||||
for (o = dec; s <= end; o++)
|
||||
{
|
||||
c = *s++;
|
||||
cx = c; // preserve original value if we are not to decode
|
||||
if (c == '%' && (!ishex(*s++) ||
|
||||
!ishex(*s++) ||
|
||||
!sscanf(s - 2, "%2x", &c)))
|
||||
{
|
||||
c = cx; // reset c to original value.
|
||||
s--;
|
||||
}
|
||||
if (dec)
|
||||
{
|
||||
*o = c;
|
||||
}
|
||||
}
|
||||
|
||||
return o - dec;
|
||||
}
|
||||
|
||||
#define GSPathHandlingRight() \
|
||||
((pathHandling == PH_DO_THE_RIGHT_THING) ? YES : NO)
|
||||
#define GSPathHandlingUnix() \
|
||||
|
@ -1939,27 +1967,23 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
|
|||
- (NSString *) stringByRemovingPercentEncoding
|
||||
{
|
||||
NSData *data = [self dataUsingEncoding: NSUTF8StringEncoding];
|
||||
NSString *result = nil;
|
||||
char *s = (char *)[data bytes];
|
||||
char *o;
|
||||
const char *end = s + strlen(s);
|
||||
int c;
|
||||
NSUInteger slen = 0;
|
||||
char *o = NULL;
|
||||
|
||||
// Allocate memory...
|
||||
slen = strlen(s);
|
||||
o = (char *)NSZoneMalloc(NSDefaultMallocZone(), slen * 3);
|
||||
|
||||
// Decode...
|
||||
urldecode(s,o);
|
||||
|
||||
// Free up temporary space...
|
||||
result = [NSString stringWithCString: o encoding: NSUTF8StringEncoding];
|
||||
NSZoneFree(NSDefaultMallocZone(), o);
|
||||
|
||||
for (o = 0; s <= end; o++) {
|
||||
c = *s++;
|
||||
if (c == '+')
|
||||
{
|
||||
c = ' ';
|
||||
}
|
||||
else if (c == '%' &&
|
||||
(!ishex(*s++) ||
|
||||
!ishex(*s++) ||
|
||||
!sscanf(s - 2, "%2x", &c)))
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
return [NSString stringWithCString: o encoding: NSUTF8StringEncoding];
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,7 +46,14 @@ int main (int argc, const char * argv[])
|
|||
urlEncodedString = @"%01";
|
||||
allowedCharacterSet = [NSCharacterSet alphanumericCharacterSet];
|
||||
PASS(testUrlCharacterSetEncoding(urlDecodedString, urlEncodedString, allowedCharacterSet), "alphanumericCharacterSet");
|
||||
|
||||
|
||||
NSLog(@"Test5");
|
||||
urlDecodedString = @"All alphabetic characters should be encoded. Symbols should not be: !@#$%^&*()_+-=";
|
||||
urlEncodedString = @"%41%6C%6C %61%6C%70%68%61%62%65%74%69%63 %63%68%61%72%61%63%74%65%72%73 %73%68%6F%75%6C%64 %62%65 "
|
||||
@"%65%6E%63%6F%64%65%64. %53%79%6D%62%6F%6C%73 %73%68%6F%75%6C%64 %6E%6F%74 %62%65: !@#$%^&*()_+-=";
|
||||
NSString *result = [urlEncodedString stringByRemovingPercentEncoding];
|
||||
PASS([urlDecodedString isEqualToString: result], "stringByRemovingPercentEncoding");
|
||||
NSLog(@"Result = \"%@\",\ndecodedString = \"%@\",\nencodedString = \"%@\"", result, urlDecodedString, urlEncodedString);
|
||||
[pool drain];
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue