OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "wtf/text/TextCodecLatin1.h" | 27 #include "wtf/text/TextCodecLatin1.h" |
28 | 28 |
29 #include "wtf/text/TextCodecASCIIFastPath.h" | |
30 #include "wtf/PassOwnPtr.h" | 29 #include "wtf/PassOwnPtr.h" |
31 #include "wtf/text/CString.h" | 30 #include "wtf/text/CString.h" |
32 #include "wtf/text/StringBuffer.h" | 31 #include "wtf/text/StringBuffer.h" |
| 32 #include "wtf/text/TextCodecASCIIFastPath.h" |
33 #include "wtf/text/WTFString.h" | 33 #include "wtf/text/WTFString.h" |
34 | 34 |
35 using namespace WTF; | |
36 | |
37 namespace WTF { | 35 namespace WTF { |
38 | 36 |
39 static const UChar table[256] = { | 37 static const UChar table[256] = { |
40 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, // 00-07 | 38 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, // 00-07 |
41 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F, // 08-0F | 39 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F, // 08-0F |
42 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, // 10-17 | 40 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, // 10-17 |
43 0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, // 18-1F | 41 0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, // 18-1F |
44 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, // 20-27 | 42 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, // 20-27 |
45 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, // 28-2F | 43 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, // 28-2F |
46 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, // 30-37 | 44 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, // 30-37 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 char* bytes = result.data(); | 206 char* bytes = result.data(); |
209 | 207 |
210 size_t resultLength = 0; | 208 size_t resultLength = 0; |
211 for (size_t i = 0; i < length; ) { | 209 for (size_t i = 0; i < length; ) { |
212 UChar32 c; | 210 UChar32 c; |
213 U16_NEXT(characters, i, length, c); | 211 U16_NEXT(characters, i, length, c); |
214 unsigned char b = static_cast<unsigned char>(c); | 212 unsigned char b = static_cast<unsigned char>(c); |
215 // Do an efficient check to detect characters other than 00-7F and A0-FF
. | 213 // Do an efficient check to detect characters other than 00-7F and A0-FF
. |
216 if (b != c || (c & 0xE0) == 0x80) { | 214 if (b != c || (c & 0xE0) == 0x80) { |
217 // Look for a way to encode this with Windows Latin-1. | 215 // Look for a way to encode this with Windows Latin-1. |
218 for (b = 0x80; b < 0xA0; ++b) | 216 for (b = 0x80; b < 0xA0; ++b) { |
219 if (table[b] == c) | 217 if (table[b] == c) |
220 goto gotByte; | 218 goto gotByte; |
| 219 } |
221 // No way to encode this character with Windows Latin-1. | 220 // No way to encode this character with Windows Latin-1. |
222 UnencodableReplacementArray replacement; | 221 UnencodableReplacementArray replacement; |
223 int replacementLength = TextCodec::getUnencodableReplacement(c, hand
ling, replacement); | 222 int replacementLength = TextCodec::getUnencodableReplacement(c, hand
ling, replacement); |
224 result.grow(resultLength + replacementLength + length - i); | 223 result.grow(resultLength + replacementLength + length - i); |
225 bytes = result.data(); | 224 bytes = result.data(); |
226 memcpy(bytes + resultLength, replacement, replacementLength); | 225 memcpy(bytes + resultLength, replacement, replacementLength); |
227 resultLength += replacementLength; | 226 resultLength += replacementLength; |
228 continue; | 227 continue; |
229 } | 228 } |
230 gotByte: | 229 gotByte: |
(...skipping 30 matching lines...) Expand all Loading... |
261 { | 260 { |
262 return encodeCommon(characters, length, handling); | 261 return encodeCommon(characters, length, handling); |
263 } | 262 } |
264 | 263 |
265 CString TextCodecLatin1::encode(const LChar* characters, size_t length, Unencoda
bleHandling handling) | 264 CString TextCodecLatin1::encode(const LChar* characters, size_t length, Unencoda
bleHandling handling) |
266 { | 265 { |
267 return encodeCommon(characters, length, handling); | 266 return encodeCommon(characters, length, handling); |
268 } | 267 } |
269 | 268 |
270 } // namespace WTF | 269 } // namespace WTF |
OLD | NEW |