Differences From Artifact [1d69719094]:
- File
src/OFString.m
— part of check-in
[f412995e6a]
at
2011-10-31 22:01:49
on branch trunk
— Assume big endian encoding for UTF16 if none is specified and no BOM.
This was changed from native to big endian because UCS-2 is defined to
be big endian. (user: js, size: 43212) [annotate] [blame] [check-ins using]
To Artifact [e38e775f82]:
- File src/OFString.m — part of check-in [a51b3cb390] at 2011-10-31 22:02:09 on branch trunk — Add -[UTF16String] to OFString. (user: js, size: 44178) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 | exceptionWithClass: isa]; ret[j++] = c; i += cLen; } ret[j] = 0; return ret; } - (void)writeToFile: (OFString*)path { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 | exceptionWithClass: isa]; ret[j++] = c; i += cLen; } ret[j] = 0; return ret; } - (const uint16_t*)UTF16String { OFObject *object = [[[OFObject alloc] init] autorelease]; uint16_t *ret; size_t i, j; /* Allocate memory for the worst case */ ret = [object allocMemoryForNItems: s->length * 2 + 1 ofSize: sizeof(uint16_t)]; i = 0; j = 0; while (i < s->cStringLength) { of_unichar_t c; size_t cLen; cLen = of_string_utf8_to_unicode(s->cString + i, s->cStringLength - i, &c); if (cLen == 0 || c > 0x10FFFF) @throw [OFInvalidEncodingException exceptionWithClass: isa]; if (c > 0xFFFF) { c -= 0x10000; ret[j++] = of_bswap16_if_le(0xD800 | (c >> 10)); ret[j++] = of_bswap16_if_le(0xDC00 | (c & 0x3FF)); } else ret[j++] = of_bswap16_if_le(c); i += cLen; } ret[j] = 0; @try { ret = [object resizeMemory: ret toNItems: j + 1 ofSize: sizeof(uint16_t)]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } return ret; } - (void)writeToFile: (OFString*)path { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; |
︙ | ︙ |