[Substrate-commits] SF.net SVN: substrate: [301] trunk
Brought to you by:
landonf
|
From: <la...@us...> - 2006-09-02 01:33:08
|
Revision: 301
http://svn.sourceforge.net/substrate/?rev=301&view=rev
Author: landonf
Date: 2006-09-01 18:33:04 -0700 (Fri, 01 Sep 2006)
Log Message:
-----------
Minor fixes for getCharacters, etc.
Modified Paths:
--------------
trunk/Foundation/NSSimpleCString.m
trunk/Foundation/NSUnicodeString.m
trunk/Tests/NSUnicodeFormatString.m
trunk/Tests/NSUnicodeString.m
Modified: trunk/Foundation/NSSimpleCString.m
===================================================================
--- trunk/Foundation/NSSimpleCString.m 2006-09-02 00:49:19 UTC (rev 300)
+++ trunk/Foundation/NSSimpleCString.m 2006-09-02 01:33:04 UTC (rev 301)
@@ -84,6 +84,8 @@
}
- (unichar) characterAtIndex:(unsigned int) index {
+ if (index > _numBytes - 1)
+ [NSException raise: NSRangeException format: @"index out of bounds"];
/* ASCII can be directly mapped to UTF-16 */
return (unichar) _bytes[index];
}
Modified: trunk/Foundation/NSUnicodeString.m
===================================================================
--- trunk/Foundation/NSUnicodeString.m 2006-09-02 00:49:19 UTC (rev 300)
+++ trunk/Foundation/NSUnicodeString.m 2006-09-02 01:33:04 UTC (rev 301)
@@ -37,6 +37,7 @@
#include <Foundation/NSData.h>
#include <Foundation/NSException.h>
+#include <string.h>
/*!
* @defgroup NSUnicodeString UTF-16 NSString Implementation
@@ -359,6 +360,19 @@
* @{
*/
+- (void) getCharacters:(unichar *) buffer range:(NSRange) aRange {
+ if (aRange.location + aRange.length > _length)
+ [NSException raise: NSRangeException format: @"range out of bounds"];
+
+ memcpy(buffer, _string + aRange.location, aRange.length);
+}
+
+- (unichar)characterAtIndex:(unsigned)index {
+ if (index > _length - 1)
+ [NSException raise: NSRangeException format: @"index out of bounds"];
+ return _string[index];
+}
+
- (unsigned int) length {
return _length;
}
Modified: trunk/Tests/NSUnicodeFormatString.m
===================================================================
--- trunk/Tests/NSUnicodeFormatString.m 2006-09-02 00:49:19 UTC (rev 300)
+++ trunk/Tests/NSUnicodeFormatString.m 2006-09-02 01:33:04 UTC (rev 301)
@@ -28,6 +28,7 @@
#endif
#include <Foundation/NSString.h>
+#include <Foundation/NSAutoreleasePool.h>
/*
* Tests that are specific to the NSString format string handling.
Modified: trunk/Tests/NSUnicodeString.m
===================================================================
--- trunk/Tests/NSUnicodeString.m 2006-09-02 00:49:19 UTC (rev 300)
+++ trunk/Tests/NSUnicodeString.m 2006-09-02 01:33:04 UTC (rev 301)
@@ -255,6 +255,20 @@
}
END_TEST
+START_TEST (test_getCharacters) {
+ NSString *string = [[NSString alloc] initWithBytes: NSUnicodeStringEncoding_data length: sizeof(NSUnicodeStringEncoding_data) encoding: NSUnicodeStringEncoding];
+ unichar *chars;
+
+ chars = malloc([string length] * sizeof(unichar));
+ [string getCharacters: chars];
+
+ /* chars + 1 skips the BOM */
+ fail_unless(memcmp(chars + 1, NSUnicodeStringEncoding_data, [string length]), "-[NSString getCharacters:] returned unexpected data: '%s'", [string UTF8String]);
+ free(chars);
+ [string release];
+}
+END_TEST
+
Suite *NSUnicodeString_suite(void) {
Suite *s = suite_create("NSUnicodeString");
@@ -280,8 +294,13 @@
TCase *tc_conv = tcase_create("Conversion");
tcase_add_checked_fixture(tc_conv, setUp, tearDown);
- suite_add_tcase(s, tc_conv);
+ suite_add_tcase(s, tc_conv);
tcase_add_test(tc_conv, test_dataUsingEncodingStringEncodingAllowLossyConversion);
+ TCase *tc_access = tcase_create("Accessing");
+ tcase_add_checked_fixture(tc_access, setUp, tearDown);
+ suite_add_tcase(s, tc_access);
+ tcase_add_test(tc_access, test_getCharacters);
+
return (s);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|