OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2006, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2008, 2011 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 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | 84 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
85 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | 85 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
86 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | 86 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
87 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, | 87 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
88 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | 88 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
89 return lengths[firstByte]; | 89 return lengths[firstByte]; |
90 } | 90 } |
91 | 91 |
92 static inline int decodeNonASCIISequence(const uint8_t* sequence, | 92 static inline int decodeNonASCIISequence(const uint8_t* sequence, |
93 unsigned length) { | 93 unsigned length) { |
94 ASSERT(!isASCII(sequence[0])); | 94 DCHECK(!isASCII(sequence[0])); |
95 if (length == 2) { | 95 if (length == 2) { |
96 ASSERT(sequence[0] <= 0xDF); | 96 DCHECK_LE(sequence[0], 0xDF); |
97 if (sequence[0] < 0xC2) | 97 if (sequence[0] < 0xC2) |
98 return nonCharacter1; | 98 return nonCharacter1; |
99 if (sequence[1] < 0x80 || sequence[1] > 0xBF) | 99 if (sequence[1] < 0x80 || sequence[1] > 0xBF) |
100 return nonCharacter1; | 100 return nonCharacter1; |
101 return ((sequence[0] << 6) + sequence[1]) - 0x00003080; | 101 return ((sequence[0] << 6) + sequence[1]) - 0x00003080; |
102 } | 102 } |
103 if (length == 3) { | 103 if (length == 3) { |
104 ASSERT(sequence[0] >= 0xE0 && sequence[0] <= 0xEF); | 104 DCHECK_GE(sequence[0], 0xE0); |
| 105 DCHECK_LE(sequence[0], 0xEF); |
105 switch (sequence[0]) { | 106 switch (sequence[0]) { |
106 case 0xE0: | 107 case 0xE0: |
107 if (sequence[1] < 0xA0 || sequence[1] > 0xBF) | 108 if (sequence[1] < 0xA0 || sequence[1] > 0xBF) |
108 return nonCharacter1; | 109 return nonCharacter1; |
109 break; | 110 break; |
110 case 0xED: | 111 case 0xED: |
111 if (sequence[1] < 0x80 || sequence[1] > 0x9F) | 112 if (sequence[1] < 0x80 || sequence[1] > 0x9F) |
112 return nonCharacter1; | 113 return nonCharacter1; |
113 break; | 114 break; |
114 default: | 115 default: |
115 if (sequence[1] < 0x80 || sequence[1] > 0xBF) | 116 if (sequence[1] < 0x80 || sequence[1] > 0xBF) |
116 return nonCharacter1; | 117 return nonCharacter1; |
117 } | 118 } |
118 if (sequence[2] < 0x80 || sequence[2] > 0xBF) | 119 if (sequence[2] < 0x80 || sequence[2] > 0xBF) |
119 return nonCharacter2; | 120 return nonCharacter2; |
120 return ((sequence[0] << 12) + (sequence[1] << 6) + sequence[2]) - | 121 return ((sequence[0] << 12) + (sequence[1] << 6) + sequence[2]) - |
121 0x000E2080; | 122 0x000E2080; |
122 } | 123 } |
123 ASSERT(length == 4); | 124 DCHECK_EQ(length, 4u); |
124 ASSERT(sequence[0] >= 0xF0 && sequence[0] <= 0xF4); | 125 DCHECK_GE(sequence[0], 0xF0); |
| 126 DCHECK_LE(sequence[0], 0xF4); |
125 switch (sequence[0]) { | 127 switch (sequence[0]) { |
126 case 0xF0: | 128 case 0xF0: |
127 if (sequence[1] < 0x90 || sequence[1] > 0xBF) | 129 if (sequence[1] < 0x90 || sequence[1] > 0xBF) |
128 return nonCharacter1; | 130 return nonCharacter1; |
129 break; | 131 break; |
130 case 0xF4: | 132 case 0xF4: |
131 if (sequence[1] < 0x80 || sequence[1] > 0x8F) | 133 if (sequence[1] < 0x80 || sequence[1] > 0x8F) |
132 return nonCharacter1; | 134 return nonCharacter1; |
133 break; | 135 break; |
134 default: | 136 default: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 consumePartialSequenceByte(); | 174 consumePartialSequenceByte(); |
173 } | 175 } |
174 | 176 |
175 template <> | 177 template <> |
176 bool TextCodecUTF8::handlePartialSequence<LChar>(LChar*& destination, | 178 bool TextCodecUTF8::handlePartialSequence<LChar>(LChar*& destination, |
177 const uint8_t*& source, | 179 const uint8_t*& source, |
178 const uint8_t* end, | 180 const uint8_t* end, |
179 bool flush, | 181 bool flush, |
180 bool, | 182 bool, |
181 bool&) { | 183 bool&) { |
182 ASSERT(m_partialSequenceSize); | 184 DCHECK(m_partialSequenceSize); |
183 do { | 185 do { |
184 if (isASCII(m_partialSequence[0])) { | 186 if (isASCII(m_partialSequence[0])) { |
185 *destination++ = m_partialSequence[0]; | 187 *destination++ = m_partialSequence[0]; |
186 consumePartialSequenceByte(); | 188 consumePartialSequenceByte(); |
187 continue; | 189 continue; |
188 } | 190 } |
189 int count = nonASCIISequenceLength(m_partialSequence[0]); | 191 int count = nonASCIISequenceLength(m_partialSequence[0]); |
190 if (!count) | 192 if (!count) |
191 return true; | 193 return true; |
192 | 194 |
(...skipping 28 matching lines...) Expand all Loading... |
221 return false; | 223 return false; |
222 } | 224 } |
223 | 225 |
224 template <> | 226 template <> |
225 bool TextCodecUTF8::handlePartialSequence<UChar>(UChar*& destination, | 227 bool TextCodecUTF8::handlePartialSequence<UChar>(UChar*& destination, |
226 const uint8_t*& source, | 228 const uint8_t*& source, |
227 const uint8_t* end, | 229 const uint8_t* end, |
228 bool flush, | 230 bool flush, |
229 bool stopOnError, | 231 bool stopOnError, |
230 bool& sawError) { | 232 bool& sawError) { |
231 ASSERT(m_partialSequenceSize); | 233 DCHECK(m_partialSequenceSize); |
232 do { | 234 do { |
233 if (isASCII(m_partialSequence[0])) { | 235 if (isASCII(m_partialSequence[0])) { |
234 *destination++ = m_partialSequence[0]; | 236 *destination++ = m_partialSequence[0]; |
235 consumePartialSequenceByte(); | 237 consumePartialSequenceByte(); |
236 continue; | 238 continue; |
237 } | 239 } |
238 int count = nonASCIISequenceLength(m_partialSequence[0]); | 240 int count = nonASCIISequenceLength(m_partialSequence[0]); |
239 if (!count) { | 241 if (!count) { |
240 handleError(destination, stopOnError, sawError); | 242 handleError(destination, stopOnError, sawError); |
241 if (stopOnError) | 243 if (stopOnError) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 continue; | 336 continue; |
335 } | 337 } |
336 int count = nonASCIISequenceLength(*source); | 338 int count = nonASCIISequenceLength(*source); |
337 int character; | 339 int character; |
338 if (count == 0) { | 340 if (count == 0) { |
339 character = nonCharacter1; | 341 character = nonCharacter1; |
340 } else { | 342 } else { |
341 if (count > end - source) { | 343 if (count > end - source) { |
342 SECURITY_DCHECK(end - source < | 344 SECURITY_DCHECK(end - source < |
343 static_cast<ptrdiff_t>(sizeof(m_partialSequence))); | 345 static_cast<ptrdiff_t>(sizeof(m_partialSequence))); |
344 ASSERT(!m_partialSequenceSize); | 346 DCHECK(!m_partialSequenceSize); |
345 m_partialSequenceSize = end - source; | 347 m_partialSequenceSize = end - source; |
346 memcpy(m_partialSequence, source, m_partialSequenceSize); | 348 memcpy(m_partialSequence, source, m_partialSequenceSize); |
347 source = end; | 349 source = end; |
348 break; | 350 break; |
349 } | 351 } |
350 character = decodeNonASCIISequence(source, count); | 352 character = decodeNonASCIISequence(source, count); |
351 } | 353 } |
352 if (isNonCharacter(character)) { | 354 if (isNonCharacter(character)) { |
353 sawError = true; | 355 sawError = true; |
354 if (stopOnError) | 356 if (stopOnError) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 continue; | 417 continue; |
416 } | 418 } |
417 int count = nonASCIISequenceLength(*source); | 419 int count = nonASCIISequenceLength(*source); |
418 int character; | 420 int character; |
419 if (count == 0) { | 421 if (count == 0) { |
420 character = nonCharacter1; | 422 character = nonCharacter1; |
421 } else { | 423 } else { |
422 if (count > end - source) { | 424 if (count > end - source) { |
423 SECURITY_DCHECK(end - source < | 425 SECURITY_DCHECK(end - source < |
424 static_cast<ptrdiff_t>(sizeof(m_partialSequence))); | 426 static_cast<ptrdiff_t>(sizeof(m_partialSequence))); |
425 ASSERT(!m_partialSequenceSize); | 427 DCHECK(!m_partialSequenceSize); |
426 m_partialSequenceSize = end - source; | 428 m_partialSequenceSize = end - source; |
427 memcpy(m_partialSequence, source, m_partialSequenceSize); | 429 memcpy(m_partialSequence, source, m_partialSequenceSize); |
428 source = end; | 430 source = end; |
429 break; | 431 break; |
430 } | 432 } |
431 character = decodeNonASCIISequence(source, count); | 433 character = decodeNonASCIISequence(source, count); |
432 } | 434 } |
433 if (isNonCharacter(character)) { | 435 if (isNonCharacter(character)) { |
434 sawError = true; | 436 sawError = true; |
435 if (stopOnError) | 437 if (stopOnError) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 return encodeCommon(characters, length); | 489 return encodeCommon(characters, length); |
488 } | 490 } |
489 | 491 |
490 CString TextCodecUTF8::encode(const LChar* characters, | 492 CString TextCodecUTF8::encode(const LChar* characters, |
491 size_t length, | 493 size_t length, |
492 UnencodableHandling) { | 494 UnencodableHandling) { |
493 return encodeCommon(characters, length); | 495 return encodeCommon(characters, length); |
494 } | 496 } |
495 | 497 |
496 } // namespace WTF | 498 } // namespace WTF |
OLD | NEW |