| 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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 *err = U_ZERO_ERROR; | 417 *err = U_ZERO_ERROR; |
| 418 | 418 |
| 419 UnencodableReplacementArray entity; | 419 UnencodableReplacementArray entity; |
| 420 int entityLen = TextCodec::getUnencodableReplacement(codePoint, handling
, entity); | 420 int entityLen = TextCodec::getUnencodableReplacement(codePoint, handling
, entity); |
| 421 ucnv_cbFromUWriteBytes(fromUArgs, entity, entityLen, 0, err); | 421 ucnv_cbFromUWriteBytes(fromUArgs, entity, entityLen, 0, err); |
| 422 } else { | 422 } else { |
| 423 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); |
| 424 } | 424 } |
| 425 } | 425 } |
| 426 | 426 |
| 427 static void numericEntityCallback(const void* context, UConverterFromUnicodeArgs
* fromUArgs, const UChar* codeUnits, int32_t length, |
| 428 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) |
| 429 { |
| 430 formatEscapedEntityCallback(context, fromUArgs, codeUnits, length, codePoint
, reason, err, EntitiesForUnencodables); |
| 431 } |
| 432 |
| 427 // Invalid character handler when writing escaped entities in CSS encoding for | 433 // Invalid character handler when writing escaped entities in CSS encoding for |
| 428 // unrepresentable characters. See the declaration of TextCodec::encode for more
. | 434 // 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, | 435 static void cssEscapedEntityCallback(const void* context, UConverterFromUnicodeA
rgs* fromUArgs, const UChar* codeUnits, int32_t length, |
| 430 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) | 436 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) |
| 431 { | 437 { |
| 432 formatEscapedEntityCallback(context, fromUArgs, codeUnits, length, codePoint
, reason, err, CSSEncodedEntitiesForUnencodables); | 438 formatEscapedEntityCallback(context, fromUArgs, codeUnits, length, codePoint
, reason, err, CSSEncodedEntitiesForUnencodables); |
| 433 } | 439 } |
| 434 | 440 |
| 435 // Invalid character handler when writing escaped entities in HTML/XML encoding
for | 441 // Invalid character handler when writing escaped entities in HTML/XML encoding
for |
| 436 // unrepresentable characters. See the declaration of TextCodec::encode for more
. | 442 // 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, | 443 static void urlEscapedEntityCallback(const void* context, UConverterFromUnicodeA
rgs* fromUArgs, const UChar* codeUnits, int32_t length, |
| 438 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) | 444 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) |
| 439 { | 445 { |
| 440 formatEscapedEntityCallback(context, fromUArgs, codeUnits, length, codePoint
, reason, err, URLEncodedEntitiesForUnencodables); | 446 formatEscapedEntityCallback(context, fromUArgs, codeUnits, length, codePoint
, reason, err, URLEncodedEntitiesForUnencodables); |
| 441 } | 447 } |
| 442 | 448 |
| 443 #if defined(USING_SYSTEM_ICU) | 449 #if defined(USING_SYSTEM_ICU) |
| 444 // Substitutes special GBK characters, escaping all other unassigned entities. | 450 // Substitutes special GBK characters, escaping all other unassigned entities. |
| 445 static void gbkCallbackEscape(const void* context, UConverterFromUnicodeArgs* fr
omUArgs, const UChar* codeUnits, int32_t length, | 451 static void gbkCallbackEscape(const void* context, UConverterFromUnicodeArgs* fr
omUArgs, const UChar* codeUnits, int32_t length, |
| 446 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) | 452 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) |
| 447 { | 453 { |
| 448 UChar outChar; | 454 UChar outChar; |
| 449 if (reason == UCNV_UNASSIGNED && (outChar = fallbackForGBK(codePoint))) { | 455 if (reason == UCNV_UNASSIGNED && (outChar = fallbackForGBK(codePoint))) { |
| 450 const UChar* source = &outChar; | 456 const UChar* source = &outChar; |
| 451 *err = U_ZERO_ERROR; | 457 *err = U_ZERO_ERROR; |
| 452 ucnv_cbFromUWriteUChars(fromUArgs, &source, source + 1, 0, err); | 458 ucnv_cbFromUWriteUChars(fromUArgs, &source, source + 1, 0, err); |
| 453 return; | 459 return; |
| 454 } | 460 } |
| 455 UCNV_FROM_U_CALLBACK_ESCAPE(context, fromUArgs, codeUnits, length, codePoint
, reason, err); | 461 numericEntityCallback(context, fromUArgs, codeUnits, length, codePoint, reas
on, err); |
| 456 } | 462 } |
| 457 | 463 |
| 458 // Combines both gbkCssEscapedEntityCallback and GBK character substitution. | 464 // Combines both gbkCssEscapedEntityCallback and GBK character substitution. |
| 459 static void gbkCssEscapedEntityCallack(const void* context, UConverterFromUnicod
eArgs* fromUArgs, const UChar* codeUnits, int32_t length, | 465 static void gbkCssEscapedEntityCallack(const void* context, UConverterFromUnicod
eArgs* fromUArgs, const UChar* codeUnits, int32_t length, |
| 460 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) | 466 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) |
| 461 { | 467 { |
| 462 if (reason == UCNV_UNASSIGNED) { | 468 if (reason == UCNV_UNASSIGNED) { |
| 463 if (UChar outChar = fallbackForGBK(codePoint)) { | 469 if (UChar outChar = fallbackForGBK(codePoint)) { |
| 464 const UChar* source = &outChar; | 470 const UChar* source = &outChar; |
| 465 *err = U_ZERO_ERROR; | 471 *err = U_ZERO_ERROR; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 case QuestionMarksForUnencodables: | 546 case QuestionMarksForUnencodables: |
| 541 ucnv_setSubstChars(m_converterICU, "?", 1, &err); | 547 ucnv_setSubstChars(m_converterICU, "?", 1, &err); |
| 542 #if !defined(USING_SYSTEM_ICU) | 548 #if !defined(USING_SYSTEM_ICU) |
| 543 ucnv_setFromUCallBack(m_converterICU, UCNV_FROM_U_CALLBACK_SUBSTITUTE, 0
, 0, 0, &err); | 549 ucnv_setFromUCallBack(m_converterICU, UCNV_FROM_U_CALLBACK_SUBSTITUTE, 0
, 0, 0, &err); |
| 544 #else | 550 #else |
| 545 ucnv_setFromUCallBack(m_converterICU, m_needsGBKFallbacks ? gbkCallbackS
ubstitute : UCNV_FROM_U_CALLBACK_SUBSTITUTE, 0, 0, 0, &err); | 551 ucnv_setFromUCallBack(m_converterICU, m_needsGBKFallbacks ? gbkCallbackS
ubstitute : UCNV_FROM_U_CALLBACK_SUBSTITUTE, 0, 0, 0, &err); |
| 546 #endif | 552 #endif |
| 547 break; | 553 break; |
| 548 case EntitiesForUnencodables: | 554 case EntitiesForUnencodables: |
| 549 #if !defined(USING_SYSTEM_ICU) | 555 #if !defined(USING_SYSTEM_ICU) |
| 550 ucnv_setFromUCallBack(m_converterICU, UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_
ESCAPE_XML_DEC, 0, 0, &err); | 556 ucnv_setFromUCallBack(m_converterICU, numericEntityCallback, 0, 0, 0, &e
rr); |
| 551 #else | 557 #else |
| 552 ucnv_setFromUCallBack(m_converterICU, m_needsGBKFallbacks ? gbkCallbackE
scape : UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_XML_DEC, 0, 0, &err); | 558 ucnv_setFromUCallBack(m_converterICU, m_needsGBKFallbacks ? gbkCallbackE
scape : numericEntityCallback, 0, 0, 0, &err); |
| 553 #endif | 559 #endif |
| 554 break; | 560 break; |
| 555 case URLEncodedEntitiesForUnencodables: | 561 case URLEncodedEntitiesForUnencodables: |
| 556 #if !defined(USING_SYSTEM_ICU) | 562 #if !defined(USING_SYSTEM_ICU) |
| 557 ucnv_setFromUCallBack(m_converterICU, urlEscapedEntityCallback, 0, 0, 0,
&err); | 563 ucnv_setFromUCallBack(m_converterICU, urlEscapedEntityCallback, 0, 0, 0,
&err); |
| 558 #else | 564 #else |
| 559 ucnv_setFromUCallBack(m_converterICU, m_needsGBKFallbacks ? gbkUrlEscape
dEntityCallack : urlEscapedEntityCallback, 0, 0, 0, &err); | 565 ucnv_setFromUCallBack(m_converterICU, m_needsGBKFallbacks ? gbkUrlEscape
dEntityCallack : urlEscapedEntityCallback, 0, 0, 0, &err); |
| 560 #endif | 566 #endif |
| 561 break; | 567 break; |
| 562 case CSSEncodedEntitiesForUnencodables: | 568 case CSSEncodedEntitiesForUnencodables: |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 { | 614 { |
| 609 return encodeCommon(characters, length, handling); | 615 return encodeCommon(characters, length, handling); |
| 610 } | 616 } |
| 611 | 617 |
| 612 CString TextCodecICU::encode(const LChar* characters, size_t length, Unencodable
Handling handling) | 618 CString TextCodecICU::encode(const LChar* characters, size_t length, Unencodable
Handling handling) |
| 613 { | 619 { |
| 614 return encodeCommon(characters, length, handling); | 620 return encodeCommon(characters, length, handling); |
| 615 } | 621 } |
| 616 | 622 |
| 617 } // namespace WTF | 623 } // namespace WTF |
| OLD | NEW |