Overview
Comment: | Allow hexadecimal values with h suffix in -[hexadecimalValue]. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
eb328c80dfa1f6e07f81b32896812fb3 |
User & Date: | js on 2010-12-29 12:49:59 |
Other Links: | manifest | tags |
Context
2010-12-29
| ||
16:40 | Add methods for local time to OFDate. check-in: 172e8f39da user: js tags: trunk | |
12:49 | Allow hexadecimal values with h suffix in -[hexadecimalValue]. check-in: eb328c80df user: js tags: trunk | |
2010-12-28
| ||
22:18 | Make ObjFW work again without threads and without atomic ops. check-in: 88c920bd62 user: js tags: trunk | |
Changes
Modified src/OFString.m from [03fe30d505] to [ba94761fb4].
︙ | ︙ | |||
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 | return num; } - (uintmax_t)hexadecimalValue { int i = 0; uintmax_t num = 0; if (length == 0) return 0; if (length >= 2 && string[0] == '0' && string[1] == 'x') i = 2; else if (length >= 1 && (string[0] == 'x' || string[0] == '$')) i = 1; if (i == length) @throw [OFInvalidEncodingException newWithClass: isa]; for (; i < length; i++) { uintmax_t newnum; if (string[i] >= '0' && string[i] <= '9') newnum = (num << 4) | (string[i] - '0'); else if (string[i] >= 'A' && string[i] <= 'F') newnum = (num << 4) | (string[i] - 'A' + 10); else if (string[i] >= 'a' && string[i] <= 'f') newnum = (num << 4) | (string[i] - 'a' + 10); | > > > > > > > | | 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | return num; } - (uintmax_t)hexadecimalValue { int i = 0; uintmax_t num = 0; BOOL suffix = NO; if (length == 0) return 0; if (length >= 2 && string[0] == '0' && string[1] == 'x') i = 2; else if (length >= 1 && (string[0] == 'x' || string[0] == '$')) i = 1; if (i == length) @throw [OFInvalidEncodingException newWithClass: isa]; for (; i < length; i++) { uintmax_t newnum; if (suffix) @throw [OFInvalidEncodingException newWithClass: isa]; if (string[i] >= '0' && string[i] <= '9') newnum = (num << 4) | (string[i] - '0'); else if (string[i] >= 'A' && string[i] <= 'F') newnum = (num << 4) | (string[i] - 'A' + 10); else if (string[i] >= 'a' && string[i] <= 'f') newnum = (num << 4) | (string[i] - 'a' + 10); else if (string[i] == 'h') { suffix = YES; continue; } else @throw [OFInvalidEncodingException newWithClass: isa]; if (newnum < num) @throw [OFOutOfRangeException newWithClass: isa]; num = newnum; } |
︙ | ︙ |
Modified tests/OFStringTests.m from [860575542d] to [e02f931b13].
︙ | ︙ | |||
227 228 229 230 231 232 233 234 235 236 237 238 239 240 | [@"" decimalValue] == 0) TEST(@"-[hexadecimalValue]", [@"123f" hexadecimalValue] == 0x123f && [@"0xABcd" hexadecimalValue] == 0xABCD && [@"xbCDE" hexadecimalValue] == 0xBCDE && [@"$CdEf" hexadecimalValue] == 0xCDEF && [@"" hexadecimalValue] == 0) EXPECT_EXCEPTION(@"Detect invalid characters in -[decimalValue] #1", OFInvalidEncodingException, [@"abc" decimalValue]) EXPECT_EXCEPTION(@"Detect invalid characters in -[decimalValue] #2", OFInvalidEncodingException, [@"0a" decimalValue]) | > | 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | [@"" decimalValue] == 0) TEST(@"-[hexadecimalValue]", [@"123f" hexadecimalValue] == 0x123f && [@"0xABcd" hexadecimalValue] == 0xABCD && [@"xbCDE" hexadecimalValue] == 0xBCDE && [@"$CdEf" hexadecimalValue] == 0xCDEF && [@"Feh" hexadecimalValue] == 0xFE && [@"" hexadecimalValue] == 0) EXPECT_EXCEPTION(@"Detect invalid characters in -[decimalValue] #1", OFInvalidEncodingException, [@"abc" decimalValue]) EXPECT_EXCEPTION(@"Detect invalid characters in -[decimalValue] #2", OFInvalidEncodingException, [@"0a" decimalValue]) |
︙ | ︙ |