Overview
Comment: | Add -[unicodeString] to OFString. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
b5f0fc343d3f2395bed66b201df5387d |
User & Date: | js on 2010-09-19 22:35:22 |
Other Links: | manifest | tags |
Context
2010-09-19
| ||
22:39 | Add -[typeEncodingForSelector] and +[typeEncodingForInstanceSelector:]. check-in: 477d06da14 user: js tags: trunk | |
22:35 | Add -[unicodeString] to OFString. check-in: b5f0fc343d user: js tags: trunk | |
02:52 | Improve OFStreamObserver. check-in: b554732eae user: js tags: trunk | |
Changes
Modified src/OFString.h from [b8bdd51fbc] to [0db9d52d0e].
︙ | ︙ | |||
363 364 365 366 367 368 369 370 371 372 373 374 375 376 | * Returns the hexadecimal value of the string as an intmax_t or throws an * OFInvalidEncoding exception if the string contains any non-number characters. * * \return An OFNumber */ - (uintmax_t)hexadecimalValueAsInteger; /** * Writes the string into the specified file using UTF-8 encoding. * * \param path The path of the file to write to */ - (void)writeToFile: (OFString*)path; @end | > > > > > > > > > | 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | * Returns the hexadecimal value of the string as an intmax_t or throws an * OFInvalidEncoding exception if the string contains any non-number characters. * * \return An OFNumber */ - (uintmax_t)hexadecimalValueAsInteger; /** * Returns the string as an array of of_unichar_t. The result needs to be * free()'d by the caller, as the memory is not marked as belonging to the * object. * * \return The string as an array of Unicode characters */ - (of_unichar_t*)unicodeString; /** * Writes the string into the specified file using UTF-8 encoding. * * \param path The path of the file to write to */ - (void)writeToFile: (OFString*)path; @end |
︙ | ︙ |
Modified src/OFString.m from [5dd44cde77] to [2b9702d139].
︙ | ︙ | |||
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 | @throw [OFOutOfRangeException newWithClass: isa]; num = newnum; } return num; } - (void)writeToFile: (OFString*)path { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFFile *file; file = [OFFile fileWithPath: path mode: @"wb"]; [file writeString: self]; [pool release]; } @end | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 | @throw [OFOutOfRangeException newWithClass: isa]; num = newnum; } return num; } - (of_unichar_t*)unicodeString { of_unichar_t *ret; size_t i, j, len; len = [self length]; if ((ret = malloc((len + 1) * sizeof(of_unichar_t))) == NULL) @throw [OFOutOfMemoryException newWithClass: isa]; i = j = 0; while (i < length) { of_unichar_t c; size_t clen; clen = of_string_utf8_to_unicode(string + i, length - 1, &c); if (clen == 0 || c > 0x10FFFF) { free(ret); @throw [OFInvalidEncodingException newWithClass: isa]; } ret[j++] = c; i += clen; } ret[j] = 0; return ret; } - (void)writeToFile: (OFString*)path { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFFile *file; file = [OFFile fileWithPath: path mode: @"wb"]; [file writeString: self]; [pool release]; } @end |
Modified tests/OFStringTests.m from [d62d62cd6e] to [ae4138d157].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | /* * Copyright (c) 2008 - 2010 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #include "config.h" #import "OFString.h" #import "OFArray.h" #import "OFAutoreleasePool.h" #import "OFExceptions.h" #import "TestsAppDelegate.h" static OFString *module = @"OFString"; static OFString* whitespace[] = { @" \r \t\n\t \tasd \t \t\t\r\n", @" \t\t \t\t \t \t" }; @interface EntityHandler: OFObject <OFStringXMLUnescapingDelegate> @end @implementation EntityHandler - (OFString*)string: (OFString*)string containsUnknownEntityNamed: (OFString*)entity | > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | /* * Copyright (c) 2008 - 2010 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #include "config.h" #include <stdlib.h> #include <string.h> #import "OFString.h" #import "OFArray.h" #import "OFAutoreleasePool.h" #import "OFExceptions.h" #import "TestsAppDelegate.h" static OFString *module = @"OFString"; static OFString* whitespace[] = { @" \r \t\n\t \tasd \t \t\t\r\n", @" \t\t \t\t \t \t" }; static of_unichar_t ucstr[] = { 'f', 0xF6, 0xF6, 'b', 0xE4, 'r', 0 }; @interface EntityHandler: OFObject <OFStringXMLUnescapingDelegate> @end @implementation EntityHandler - (OFString*)string: (OFString*)string containsUnknownEntityNamed: (OFString*)entity |
︙ | ︙ | |||
41 42 43 44 45 46 47 48 49 50 51 52 53 54 | @implementation TestsAppDelegate (OFStringTests) - (void)stringTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFMutableString *s[3]; OFArray *a; int i; EntityHandler *h; s[0] = [OFMutableString stringWithString: @"täs€"]; s[1] = [OFMutableString string]; s[2] = [[s[0] copy] autorelease]; TEST(@"-[isEqual:]", [s[0] isEqual: s[2]] && | > | 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | @implementation TestsAppDelegate (OFStringTests) - (void)stringTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFMutableString *s[3]; OFArray *a; int i; of_unichar_t *ua; EntityHandler *h; s[0] = [OFMutableString stringWithString: @"täs€"]; s[1] = [OFMutableString string]; s[2] = [[s[0] copy] autorelease]; TEST(@"-[isEqual:]", [s[0] isEqual: s[2]] && |
︙ | ︙ | |||
248 249 250 251 252 253 254 255 256 257 258 259 260 261 | decimalValueAsInteger]) EXPECT_EXCEPTION(@"Detect out of range in -[hexadecilamValueAsInteger", OFOutOfRangeException, [@"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" @"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" hexadecimalValueAsInteger]) TEST(@"-[md5Hash]", [[@"asdfoobar" md5Hash] isEqual: @"184dce2ec49b5422c7cfd8728864db4c"]) TEST(@"-[sha1Hash]", [[@"asdfoobar" sha1Hash] isEqual: @"f5f81ac0a8b5cbfdc4585ec1ad32e7b3a12b9b49"]) | > > > | 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | decimalValueAsInteger]) EXPECT_EXCEPTION(@"Detect out of range in -[hexadecilamValueAsInteger", OFOutOfRangeException, [@"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" @"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" hexadecimalValueAsInteger]) TEST(@"-[unicodeString]", (ua = [@"fööbär" unicodeString]) && !memcmp(ua, ucstr, 7 * sizeof(of_unichar_t)) && R(free(ua))) TEST(@"-[md5Hash]", [[@"asdfoobar" md5Hash] isEqual: @"184dce2ec49b5422c7cfd8728864db4c"]) TEST(@"-[sha1Hash]", [[@"asdfoobar" sha1Hash] isEqual: @"f5f81ac0a8b5cbfdc4585ec1ad32e7b3a12b9b49"]) |
︙ | ︙ |