Overview
Comment: | Implement -[UTF8String] and -[UTF8StringLength] in OFString. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
ea76dec036535c70a9491ac3c93bd92d |
User & Date: | js on 2011-12-26 16:57:59 |
Other Links: | manifest | tags |
Context
2011-12-28
| ||
18:41 | Move a few selectors from OFObject to the OFObject protocol. check-in: 12eafc42ef user: js tags: trunk | |
2011-12-26
| ||
16:57 | Implement -[UTF8String] and -[UTF8StringLength] in OFString. check-in: ea76dec036 user: js tags: trunk | |
16:38 | Add a note about the lifetime of the result of -[UTF8String]. check-in: 55bba95bce user: js tags: trunk | |
Changes
Modified src/OFString.m from [eb1dd81502] to [3c525cf553].
︙ | ︙ | |||
903 904 905 906 907 908 909 | } return self; } - (const char*)UTF8String { | > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > | > | > > > > > | > > > > > > > > > > | > > > > > > > | | > > > > > > > | 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 | } return self; } - (const char*)UTF8String { const of_unichar_t *unicodeString = [self unicodeString]; char *UTF8String; size_t i, j = 0, length = [self length]; size_t UTF8StringLength = length; OFObject *object; object = [[[OFObject alloc] init] autorelease]; UTF8String = [object allocMemoryWithSize: (length * 4) + 1]; for (i = 0; i < length; i++) { char buffer[4]; size_t characterLen = of_string_unicode_to_utf8( unicodeString[i], buffer); switch (characterLen) { case 1: UTF8String[j++] = buffer[0]; break; case 2: UTF8StringLength++; memcpy(UTF8String + j, buffer, 2); j += 2; break; case 3: UTF8StringLength += 2; memcpy(UTF8String + j, buffer, 3); j += 3; break; case 4: UTF8StringLength += 3; memcpy(UTF8String + j, buffer, 4); j += 4; break; default: @throw [OFInvalidEncodingException exceptionWithClass: isa]; } } UTF8String[j] = '\0'; @try { UTF8String = [object resizeMemory: UTF8String toSize: UTF8StringLength + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } return UTF8String; } - (const char*)cStringWithEncoding: (of_string_encoding_t)encoding { if (encoding == OF_STRING_ENCODING_UTF_8) return [self UTF8String]; /* TODO: Implement! */ @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; } - (size_t)length { @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; } - (size_t)UTF8StringLength { const of_unichar_t *unicodeString = [self unicodeString]; size_t length = [self length]; size_t i, UTF8StringLength = 0; for (i = 0; i < length; i++) { char buffer[4]; size_t characterLen = of_string_unicode_to_utf8( unicodeString[i], buffer); if (characterLen == 0) @throw [OFInvalidEncodingException exceptionWithClass: isa]; UTF8StringLength += characterLen; } return UTF8StringLength; } - (size_t)cStringLengthWithEncoding: (of_string_encoding_t)encoding { if (encoding == OF_STRING_ENCODING_UTF_8) return [self UTF8StringLength]; /* TODO: Implement! */ @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; } - (of_unichar_t)characterAtIndex: (size_t)index { |
︙ | ︙ |