2002-09-24 17:53:36 +00:00
|
|
|
#include <Foundation/Foundation.h>
|
1995-04-03 03:29:10 +00:00
|
|
|
|
1998-10-23 12:14:28 +00:00
|
|
|
// Fri Oct 23 02:58:47 MET DST 1998 dave@turbocat.de
|
|
|
|
// cStringNoCopy -> cString
|
|
|
|
|
1995-04-03 03:29:10 +00:00
|
|
|
/* For demo of Strings as Collections of char's. */
|
1997-09-23 21:00:33 +00:00
|
|
|
#include <Foundation/NSString.h>
|
1998-10-03 05:11:05 +00:00
|
|
|
#include <Foundation/NSAutoreleasePool.h>
|
1995-04-03 03:29:10 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
print_string(NSString* s)
|
|
|
|
{
|
2002-03-16 09:54:50 +00:00
|
|
|
printf("The string [%s], length %d\n", [s lossyCString], [s length]);
|
1995-04-03 03:29:10 +00:00
|
|
|
}
|
1995-03-12 19:35:17 +00:00
|
|
|
|
1996-07-15 18:41:44 +00:00
|
|
|
#include <Foundation/NSString.h>
|
2000-09-07 16:42:45 +00:00
|
|
|
#include <Foundation/NSGeometry.h>
|
1996-07-15 18:41:44 +00:00
|
|
|
|
|
|
|
|
1995-03-12 19:35:17 +00:00
|
|
|
int main()
|
|
|
|
{
|
1998-10-03 05:11:05 +00:00
|
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
1995-03-12 19:35:17 +00:00
|
|
|
id s = @"This is a test string";
|
1996-09-24 17:43:57 +00:00
|
|
|
id s2, s3;
|
1999-09-09 02:56:20 +00:00
|
|
|
int a;
|
2002-03-16 09:54:50 +00:00
|
|
|
unichar u0[5] = { 0xFE66, 'a', 'b', 'c', 'd'};
|
|
|
|
unichar u1[6] = { '1', '2', '.', '3', '4', 0xFE66};
|
|
|
|
unichar u2[7] = { 'a', 'b', 0xFE66, 'a', 'b', 'c', 'd'};
|
|
|
|
NSString *us0 = [NSString stringWithCharacters: u0 length: 5];
|
|
|
|
NSString *us1 = [NSString stringWithCharacters: u1 length: 6];
|
|
|
|
NSString *us2 = [NSString stringWithCharacters: u2 length: 7];
|
|
|
|
NSMutableString *fo = [NSMutableString stringWithString: @"abcdef"];
|
|
|
|
NSMutableString *f1 = [NSMutableString stringWithString: @"ab"];
|
2002-08-28 13:41:54 +00:00
|
|
|
NSStringEncoding *encs;
|
1995-03-12 19:35:17 +00:00
|
|
|
|
2002-09-24 17:53:36 +00:00
|
|
|
{
|
|
|
|
NSURL *currentURL;
|
|
|
|
NSData *data;
|
|
|
|
|
|
|
|
currentURL = [NSURL URLWithString:
|
|
|
|
@"http:/www.foobar.org/PageWithAValid.plist"];
|
|
|
|
data = [currentURL resourceDataUsingCache: NO];
|
|
|
|
|
|
|
|
if( data )
|
|
|
|
printf(" YES \n");
|
|
|
|
printf(" NO\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
2002-09-18 09:34:33 +00:00
|
|
|
#if 0
|
|
|
|
{ // GSM test
|
|
|
|
unichar buf[] = { 163, '[', ']', '{', '}', '\\', '^', '|', '~', '_' };
|
2002-09-08 08:53:35 +00:00
|
|
|
NSString *str = [NSString stringWithCharacters: buf
|
|
|
|
length: sizeof(buf)/sizeof(unichar)];
|
|
|
|
NSData *gsm = [str dataUsingEncoding: NSGSM0338StringEncoding];
|
|
|
|
|
|
|
|
NSLog(@"GSM: %*.*s", [gsm length], [gsm length], [gsm bytes]);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-09-18 09:34:33 +00:00
|
|
|
#endif
|
|
|
|
|
2000-09-22 04:20:52 +00:00
|
|
|
NS_DURING
|
2002-03-16 09:54:50 +00:00
|
|
|
[fo replaceCharactersInRange: [fo rangeOfString: @"xx"] withString: us1];
|
2000-09-22 04:20:52 +00:00
|
|
|
NS_HANDLER
|
|
|
|
printf("Caught exception during string replacement (expected)\n");
|
|
|
|
NS_ENDHANDLER
|
2000-09-11 11:59:33 +00:00
|
|
|
|
2002-03-16 09:54:50 +00:00
|
|
|
[f1 appendString: us0];
|
|
|
|
print_string(f1);
|
|
|
|
printf("%d\n", [f1 isEqual: us2]);
|
|
|
|
|
1995-04-03 03:29:10 +00:00
|
|
|
print_string(s);
|
|
|
|
|
2000-09-07 16:42:45 +00:00
|
|
|
s2 = NSStringFromPoint(NSMakePoint(1.374, 5.100));
|
|
|
|
print_string(s2);
|
|
|
|
|
2002-03-16 09:54:50 +00:00
|
|
|
printf("%f", [[NSString stringWithCharacters: u1 length: 5] floatValue]);
|
2000-11-06 14:15:27 +00:00
|
|
|
|
1996-09-24 17:43:57 +00:00
|
|
|
s2 = [s copy];
|
|
|
|
print_string(s2);
|
|
|
|
s3 = [s2 mutableCopy];
|
|
|
|
[s2 release];
|
|
|
|
s2 = [s3 copy];
|
|
|
|
[s3 release];
|
|
|
|
[s2 release];
|
|
|
|
|
1997-01-11 21:34:55 +00:00
|
|
|
s2 = [s copyWithZone: NSDefaultMallocZone ()];
|
1996-07-15 18:41:44 +00:00
|
|
|
print_string(s2);
|
|
|
|
|
1995-04-03 03:29:10 +00:00
|
|
|
s2 = [s stringByAppendingString:@" with something added"];
|
|
|
|
print_string(s2);
|
|
|
|
|
|
|
|
s2 = [s mutableCopy];
|
|
|
|
[s2 replaceCharactersInRange:((NSRange){10,4})
|
|
|
|
withString:@"changed"];
|
|
|
|
print_string(s2);
|
|
|
|
|
1999-09-09 02:56:20 +00:00
|
|
|
#if 0
|
1996-07-15 18:41:44 +00:00
|
|
|
/* Test the use of the `%@' format directive. */
|
|
|
|
s2 = [NSString stringWithFormat: @"foo %@ bar",
|
|
|
|
@"test"];
|
|
|
|
print_string(s2);
|
|
|
|
|
1999-09-09 02:56:20 +00:00
|
|
|
for (a = 0; a < 10; a++)
|
|
|
|
NSLog(@"A string with precision %d is :%.*@:", a, a, @"String");
|
|
|
|
#endif
|
1996-04-16 22:04:21 +00:00
|
|
|
|
2002-03-16 09:54:50 +00:00
|
|
|
{
|
|
|
|
NSMutableString *base = [@"hello" mutableCopy];
|
|
|
|
NSString *ext = [@"\"\\UFE66???\"" propertyList];
|
|
|
|
NSString *want = [@"\"hello\\UFE66???\"" propertyList];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
[base appendString: ext];
|
|
|
|
printf("%u\n", [base length]);
|
|
|
|
printf("%u\n", [ext length]);
|
|
|
|
printf("%u\n", [want length]);
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
printf("%x\n", [ext characterAtIndex: i]);
|
|
|
|
for (i = 0; i < 9; i++)
|
|
|
|
printf("%x,%x\n", [base characterAtIndex: i], [want characterAtIndex: i]);
|
|
|
|
|
|
|
|
printf("%u\n", [want isEqual: base]);
|
2002-03-20 22:37:22 +00:00
|
|
|
for (i = 0; i < 1000; i++)
|
|
|
|
[base appendString: want];
|
|
|
|
print_string(base);
|
2002-08-28 13:41:54 +00:00
|
|
|
|
|
|
|
encs = [NSString availableStringEncodings];
|
|
|
|
while (*encs != 0)
|
|
|
|
printf("Encoding %x\n", *encs++);
|
2002-03-16 09:54:50 +00:00
|
|
|
}
|
2002-09-08 08:53:35 +00:00
|
|
|
|
1998-10-03 05:11:05 +00:00
|
|
|
[arp release];
|
1995-03-12 19:35:17 +00:00
|
|
|
exit(0);
|
|
|
|
}
|