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" | 29 #include "wtf/text/TextCodecASCIIFastPath.h" |
30 #include "wtf/PassOwnPtr.h" | 30 #include "wtf/PassOwnPtr.h" |
31 #include "wtf/text/CString.h" | 31 #include "wtf/text/CString.h" |
32 #include "wtf/text/StringBuffer.h" | 32 #include "wtf/text/StringBuffer.h" |
33 #include "wtf/text/WTFString.h" | 33 #include "wtf/text/WTFString.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 goto upConvertTo16Bit; | 155 goto upConvertTo16Bit; |
156 | 156 |
157 *destination = table[*source]; | 157 *destination = table[*source]; |
158 } | 158 } |
159 | 159 |
160 ++source; | 160 ++source; |
161 ++destination; | 161 ++destination; |
162 } | 162 } |
163 | 163 |
164 return result; | 164 return result; |
165 | 165 |
166 upConvertTo16Bit: | 166 upConvertTo16Bit: |
167 UChar* characters16; | 167 UChar* characters16; |
168 String result16 = String::createUninitialized(length, characters16); | 168 String result16 = String::createUninitialized(length, characters16); |
169 | 169 |
170 UChar* destination16 = characters16; | 170 UChar* destination16 = characters16; |
171 | 171 |
172 // Zero extend and copy already processed 8 bit data | 172 // Zero extend and copy already processed 8 bit data |
173 LChar* ptr8 = characters; | 173 LChar* ptr8 = characters; |
174 LChar* endPtr8 = destination; | 174 LChar* endPtr8 = destination; |
175 | 175 |
176 while (ptr8 < endPtr8) | 176 while (ptr8 < endPtr8) |
177 *destination16++ = *ptr8++; | 177 *destination16++ = *ptr8++; |
178 | 178 |
179 // Handle the character that triggered the 16 bit path | 179 // Handle the character that triggered the 16 bit path |
180 *destination16 = table[*source]; | 180 *destination16 = table[*source]; |
181 ++source; | 181 ++source; |
182 ++destination16; | 182 ++destination16; |
183 | 183 |
184 while (source < end) { | 184 while (source < end) { |
185 if (isASCII(*source)) { | 185 if (isASCII(*source)) { |
186 // Fast path for ASCII. Most Latin-1 text will be ASCII. | 186 // Fast path for ASCII. Most Latin-1 text will be ASCII. |
187 if (isAlignedToMachineWord(source)) { | 187 if (isAlignedToMachineWord(source)) { |
188 while (source < alignedEnd) { | 188 while (source < alignedEnd) { |
189 MachineWord chunk = *reinterpret_cast_ptr<const MachineWord*
>(source); | 189 MachineWord chunk = *reinterpret_cast_ptr<const MachineWord*
>(source); |
190 | 190 |
191 if (!isAllASCII<LChar>(chunk)) | 191 if (!isAllASCII<LChar>(chunk)) |
192 goto useLookupTable16; | 192 goto useLookupTable16; |
193 | 193 |
194 copyASCIIMachineWord(destination16, source); | 194 copyASCIIMachineWord(destination16, source); |
195 source += sizeof(MachineWord); | 195 source += sizeof(MachineWord); |
196 destination16 += sizeof(MachineWord); | 196 destination16 += sizeof(MachineWord); |
197 } | 197 } |
198 | 198 |
199 if (source == end) | 199 if (source == end) |
200 break; | 200 break; |
201 } | 201 } |
202 *destination16 = *source; | 202 *destination16 = *source; |
203 } else { | 203 } else { |
204 useLookupTable16: | 204 useLookupTable16: |
205 *destination16 = table[*source]; | 205 *destination16 = table[*source]; |
206 } | 206 } |
207 | 207 |
208 ++source; | 208 ++source; |
209 ++destination16; | 209 ++destination16; |
210 } | 210 } |
211 | 211 |
212 return result16; | 212 return result16; |
213 } | 213 } |
214 | 214 |
215 template<typename CharType> | 215 template<typename CharType> |
216 static CString encodeComplexWindowsLatin1(const CharType* characters, size_t len
gth, UnencodableHandling handling) | 216 static CString encodeComplexWindowsLatin1(const CharType* characters, size_t len
gth, UnencodableHandling handling) |
217 { | 217 { |
218 Vector<char> result(length); | 218 Vector<char> result(length); |
219 char* bytes = result.data(); | 219 char* bytes = result.data(); |
220 | 220 |
221 size_t resultLength = 0; | 221 size_t resultLength = 0; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 { | 272 { |
273 return encodeCommon(characters, length, handling); | 273 return encodeCommon(characters, length, handling); |
274 } | 274 } |
275 | 275 |
276 CString TextCodecLatin1::encode(const LChar* characters, size_t length, Unencoda
bleHandling handling) | 276 CString TextCodecLatin1::encode(const LChar* characters, size_t length, Unencoda
bleHandling handling) |
277 { | 277 { |
278 return encodeCommon(characters, length, handling); | 278 return encodeCommon(characters, length, handling); |
279 } | 279 } |
280 | 280 |
281 } // namespace WTF | 281 } // namespace WTF |
OLD | NEW |