OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. |
3 * Copyright (C) 2006 Alexey Proskuryakov <ap@nypop.com> | 3 * Copyright (C) 2006 Alexey Proskuryakov <ap@nypop.com> |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 switch (character) { | 402 switch (character) { |
403 case 0x01F9: | 403 case 0x01F9: |
404 return 0xE7C8; // mapped to xA8xBF by ICU. | 404 return 0xE7C8; // mapped to xA8xBF by ICU. |
405 case 0x1E3F: | 405 case 0x1E3F: |
406 return 0xE7C7; // mapped to xA8xBC by ICU. | 406 return 0xE7C7; // mapped to xA8xBC by ICU. |
407 } | 407 } |
408 return 0; | 408 return 0; |
409 } | 409 } |
410 #endif | 410 #endif |
411 | 411 |
412 // Invalid character handler when writing escaped entities for unrepresentable | 412 // Generic helper for writing escaped entities using the specfied UnencodableHan
dling. |
413 // characters. See the declaration of TextCodec::encode for more. | 413 static void formatEscapedEntityCallback(const void* context, UConverterFromUnico
deArgs* fromUArgs, const UChar* codeUnits, int32_t length, |
414 static void urlEscapedEntityCallback(const void* context, UConverterFromUnicodeA
rgs* fromUArgs, const UChar* codeUnits, int32_t length, | 414 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err, Unencod
ableHandling handling) |
415 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) | |
416 { | 415 { |
417 if (reason == UCNV_UNASSIGNED) { | 416 if (reason == UCNV_UNASSIGNED) { |
418 *err = U_ZERO_ERROR; | 417 *err = U_ZERO_ERROR; |
419 | 418 |
420 UnencodableReplacementArray entity; | 419 UnencodableReplacementArray entity; |
421 int entityLen = TextCodec::getUnencodableReplacement(codePoint, URLEncod
edEntitiesForUnencodables, entity); | 420 int entityLen = TextCodec::getUnencodableReplacement(codePoint, handling
, entity); |
422 ucnv_cbFromUWriteBytes(fromUArgs, entity, entityLen, 0, err); | 421 ucnv_cbFromUWriteBytes(fromUArgs, entity, entityLen, 0, err); |
423 } else { | 422 } else { |
424 UCNV_FROM_U_CALLBACK_ESCAPE(context, fromUArgs, codeUnits, length, codeP
oint, reason, err); | 423 UCNV_FROM_U_CALLBACK_ESCAPE(context, fromUArgs, codeUnits, length, codeP
oint, reason, err); |
425 } | 424 } |
426 } | 425 } |
427 | 426 |
| 427 // Invalid character handler when writing escaped entities in CSS encoding for |
| 428 // unrepresentable characters. See the declaration of TextCodec::encode for more
. |
| 429 static void cssEscapedEntityCallback(const void* context, UConverterFromUnicodeA
rgs* fromUArgs, const UChar* codeUnits, int32_t length, |
| 430 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) |
| 431 { |
| 432 formatEscapedEntityCallback(context, fromUArgs, codeUnits, length, codePoint
, reason, err, CSSEncodedEntitiesForUnencodables); |
| 433 } |
| 434 |
| 435 // Invalid character handler when writing escaped entities in HTML/XML encoding
for |
| 436 // unrepresentable characters. See the declaration of TextCodec::encode for more
. |
| 437 static void urlEscapedEntityCallback(const void* context, UConverterFromUnicodeA
rgs* fromUArgs, const UChar* codeUnits, int32_t length, |
| 438 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) |
| 439 { |
| 440 formatEscapedEntityCallback(context, fromUArgs, codeUnits, length, codePoint
, reason, err, URLEncodedEntitiesForUnencodables); |
| 441 } |
| 442 |
428 #if defined(USING_SYSTEM_ICU) | 443 #if defined(USING_SYSTEM_ICU) |
429 // Substitutes special GBK characters, escaping all other unassigned entities. | 444 // Substitutes special GBK characters, escaping all other unassigned entities. |
430 static void gbkCallbackEscape(const void* context, UConverterFromUnicodeArgs* fr
omUArgs, const UChar* codeUnits, int32_t length, | 445 static void gbkCallbackEscape(const void* context, UConverterFromUnicodeArgs* fr
omUArgs, const UChar* codeUnits, int32_t length, |
431 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) | 446 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) |
432 { | 447 { |
433 UChar outChar; | 448 UChar outChar; |
434 if (reason == UCNV_UNASSIGNED && (outChar = fallbackForGBK(codePoint))) { | 449 if (reason == UCNV_UNASSIGNED && (outChar = fallbackForGBK(codePoint))) { |
435 const UChar* source = &outChar; | 450 const UChar* source = &outChar; |
436 *err = U_ZERO_ERROR; | 451 *err = U_ZERO_ERROR; |
437 ucnv_cbFromUWriteUChars(fromUArgs, &source, source + 1, 0, err); | 452 ucnv_cbFromUWriteUChars(fromUArgs, &source, source + 1, 0, err); |
438 return; | 453 return; |
439 } | 454 } |
440 UCNV_FROM_U_CALLBACK_ESCAPE(context, fromUArgs, codeUnits, length, codePoint
, reason, err); | 455 UCNV_FROM_U_CALLBACK_ESCAPE(context, fromUArgs, codeUnits, length, codePoint
, reason, err); |
441 } | 456 } |
442 | 457 |
| 458 // Combines both gbkCssEscapedEntityCallback and GBK character substitution. |
| 459 static void gbkCssEscapedEntityCallack(const void* context, UConverterFromUnicod
eArgs* fromUArgs, const UChar* codeUnits, int32_t length, |
| 460 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) |
| 461 { |
| 462 if (reason == UCNV_UNASSIGNED) { |
| 463 if (UChar outChar = fallbackForGBK(codePoint)) { |
| 464 const UChar* source = &outChar; |
| 465 *err = U_ZERO_ERROR; |
| 466 ucnv_cbFromUWriteUChars(fromUArgs, &source, source + 1, 0, err); |
| 467 return; |
| 468 } |
| 469 cssEscapedEntityCallback(context, fromUArgs, codeUnits, length, codePoin
t, reason, err); |
| 470 return; |
| 471 } |
| 472 UCNV_FROM_U_CALLBACK_ESCAPE(context, fromUArgs, codeUnits, length, codePoint
, reason, err); |
| 473 } |
| 474 |
443 // Combines both gbkUrlEscapedEntityCallback and GBK character substitution. | 475 // Combines both gbkUrlEscapedEntityCallback and GBK character substitution. |
444 static void gbkUrlEscapedEntityCallack(const void* context, UConverterFromUnicod
eArgs* fromUArgs, const UChar* codeUnits, int32_t length, | 476 static void gbkUrlEscapedEntityCallack(const void* context, UConverterFromUnicod
eArgs* fromUArgs, const UChar* codeUnits, int32_t length, |
445 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) | 477 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) |
446 { | 478 { |
447 if (reason == UCNV_UNASSIGNED) { | 479 if (reason == UCNV_UNASSIGNED) { |
448 if (UChar outChar = fallbackForGBK(codePoint)) { | 480 if (UChar outChar = fallbackForGBK(codePoint)) { |
449 const UChar* source = &outChar; | 481 const UChar* source = &outChar; |
450 *err = U_ZERO_ERROR; | 482 *err = U_ZERO_ERROR; |
451 ucnv_cbFromUWriteUChars(fromUArgs, &source, source + 1, 0, err); | 483 ucnv_cbFromUWriteUChars(fromUArgs, &source, source + 1, 0, err); |
452 return; | 484 return; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 ucnv_setFromUCallBack(m_converterICU, m_needsGBKFallbacks ? gbkCallbackE
scape : UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_XML_DEC, 0, 0, &err); | 552 ucnv_setFromUCallBack(m_converterICU, m_needsGBKFallbacks ? gbkCallbackE
scape : UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_XML_DEC, 0, 0, &err); |
521 #endif | 553 #endif |
522 break; | 554 break; |
523 case URLEncodedEntitiesForUnencodables: | 555 case URLEncodedEntitiesForUnencodables: |
524 #if !defined(USING_SYSTEM_ICU) | 556 #if !defined(USING_SYSTEM_ICU) |
525 ucnv_setFromUCallBack(m_converterICU, urlEscapedEntityCallback, 0, 0, 0,
&err); | 557 ucnv_setFromUCallBack(m_converterICU, urlEscapedEntityCallback, 0, 0, 0,
&err); |
526 #else | 558 #else |
527 ucnv_setFromUCallBack(m_converterICU, m_needsGBKFallbacks ? gbkUrlEscape
dEntityCallack : urlEscapedEntityCallback, 0, 0, 0, &err); | 559 ucnv_setFromUCallBack(m_converterICU, m_needsGBKFallbacks ? gbkUrlEscape
dEntityCallack : urlEscapedEntityCallback, 0, 0, 0, &err); |
528 #endif | 560 #endif |
529 break; | 561 break; |
| 562 case CSSEncodedEntitiesForUnencodables: |
| 563 #if !defined(USING_SYSTEM_ICU) |
| 564 ucnv_setFromUCallBack(m_converterICU, cssEscapedEntityCallback, 0, 0, 0,
&err); |
| 565 #else |
| 566 ucnv_setFromUCallBack(m_converterICU, m_needsGBKFallbacks ? gbkCssEscape
dEntityCallack : cssEscapedEntityCallback, 0, 0, 0, &err); |
| 567 #endif |
| 568 break; |
530 } | 569 } |
531 | 570 |
532 ASSERT(U_SUCCESS(err)); | 571 ASSERT(U_SUCCESS(err)); |
533 if (U_FAILURE(err)) | 572 if (U_FAILURE(err)) |
534 return CString(); | 573 return CString(); |
535 | 574 |
536 Vector<char> result; | 575 Vector<char> result; |
537 size_t size = 0; | 576 size_t size = 0; |
538 do { | 577 do { |
539 char buffer[ConversionBufferSize]; | 578 char buffer[ConversionBufferSize]; |
(...skipping 29 matching lines...) Expand all Loading... |
569 { | 608 { |
570 return encodeCommon(characters, length, handling); | 609 return encodeCommon(characters, length, handling); |
571 } | 610 } |
572 | 611 |
573 CString TextCodecICU::encode(const LChar* characters, size_t length, Unencodable
Handling handling) | 612 CString TextCodecICU::encode(const LChar* characters, size_t length, Unencodable
Handling handling) |
574 { | 613 { |
575 return encodeCommon(characters, length, handling); | 614 return encodeCommon(characters, length, handling); |
576 } | 615 } |
577 | 616 |
578 } // namespace WTF | 617 } // namespace WTF |
OLD | NEW |