Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(374)

Side by Side Diff: third_party/WebKit/Source/wtf/text/TextCodecICU.cpp

Issue 1709293002: Add support for CSS unicod encoding to the text codec. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/text/TextCodec.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 return 0xE7C8; // mapped to xA8xBF by ICU. 407 return 0xE7C8; // mapped to xA8xBF by ICU.
408 case 0x1E3F: 408 case 0x1E3F:
409 return 0xE7C7; // mapped to xA8xBC by ICU. 409 return 0xE7C7; // mapped to xA8xBC by ICU.
410 } 410 }
411 return 0; 411 return 0;
412 } 412 }
413 #endif 413 #endif
414 414
415 // Invalid character handler when writing escaped entities for unrepresentable 415 // Invalid character handler when writing escaped entities for unrepresentable
416 // characters. See the declaration of TextCodec::encode for more. 416 // characters. See the declaration of TextCodec::encode for more.
417 static void cssEscapedEntityCallback(const void* context, UConverterFromUnicodeA rgs* fromUArgs, const UChar* codeUnits, int32_t length,
Dmitry Titov 2016/02/18 21:26:48 These two new functions are not really trivial cop
418 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err)
419 {
420 if (reason == UCNV_UNASSIGNED) {
421 *err = U_ZERO_ERROR;
422
423 UnencodableReplacementArray entity;
424 int entityLen = TextCodec::getUnencodableReplacement(codePoint, CSSEncod edEntitiesForUnencodables, entity);
425 ucnv_cbFromUWriteBytes(fromUArgs, entity, entityLen, 0, err);
426 } else {
427 UCNV_FROM_U_CALLBACK_ESCAPE(context, fromUArgs, codeUnits, length, codeP oint, reason, err);
428 }
429 }
430
431 // Invalid character handler when writing escaped entities for unrepresentable
432 // characters. See the declaration of TextCodec::encode for more.
417 static void urlEscapedEntityCallback(const void* context, UConverterFromUnicodeA rgs* fromUArgs, const UChar* codeUnits, int32_t length, 433 static void urlEscapedEntityCallback(const void* context, UConverterFromUnicodeA rgs* fromUArgs, const UChar* codeUnits, int32_t length,
418 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) 434 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err)
419 { 435 {
420 if (reason == UCNV_UNASSIGNED) { 436 if (reason == UCNV_UNASSIGNED) {
421 *err = U_ZERO_ERROR; 437 *err = U_ZERO_ERROR;
422 438
423 UnencodableReplacementArray entity; 439 UnencodableReplacementArray entity;
424 int entityLen = TextCodec::getUnencodableReplacement(codePoint, URLEncod edEntitiesForUnencodables, entity); 440 int entityLen = TextCodec::getUnencodableReplacement(codePoint, URLEncod edEntitiesForUnencodables, entity);
425 ucnv_cbFromUWriteBytes(fromUArgs, entity, entityLen, 0, err); 441 ucnv_cbFromUWriteBytes(fromUArgs, entity, entityLen, 0, err);
426 } else { 442 } else {
427 UCNV_FROM_U_CALLBACK_ESCAPE(context, fromUArgs, codeUnits, length, codeP oint, reason, err); 443 UCNV_FROM_U_CALLBACK_ESCAPE(context, fromUArgs, codeUnits, length, codeP oint, reason, err);
428 } 444 }
429 } 445 }
430 446
431 #if defined(USING_SYSTEM_ICU) 447 #if defined(USING_SYSTEM_ICU)
432 // Substitutes special GBK characters, escaping all other unassigned entities. 448 // Substitutes special GBK characters, escaping all other unassigned entities.
433 static void gbkCallbackEscape(const void* context, UConverterFromUnicodeArgs* fr omUArgs, const UChar* codeUnits, int32_t length, 449 static void gbkCallbackEscape(const void* context, UConverterFromUnicodeArgs* fr omUArgs, const UChar* codeUnits, int32_t length,
434 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) 450 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err)
435 { 451 {
436 UChar outChar; 452 UChar outChar;
437 if (reason == UCNV_UNASSIGNED && (outChar = fallbackForGBK(codePoint))) { 453 if (reason == UCNV_UNASSIGNED && (outChar = fallbackForGBK(codePoint))) {
438 const UChar* source = &outChar; 454 const UChar* source = &outChar;
439 *err = U_ZERO_ERROR; 455 *err = U_ZERO_ERROR;
440 ucnv_cbFromUWriteUChars(fromUArgs, &source, source + 1, 0, err); 456 ucnv_cbFromUWriteUChars(fromUArgs, &source, source + 1, 0, err);
441 return; 457 return;
442 } 458 }
443 UCNV_FROM_U_CALLBACK_ESCAPE(context, fromUArgs, codeUnits, length, codePoint , reason, err); 459 UCNV_FROM_U_CALLBACK_ESCAPE(context, fromUArgs, codeUnits, length, codePoint , reason, err);
444 } 460 }
445 461
462 // Combines both gbkCssEscapedEntityCallback and GBK character substitution.
463 static void gbkCssEscapedEntityCallack(const void* context, UConverterFromUnicod eArgs* fromUArgs, const UChar* codeUnits, int32_t length,
464 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err)
465 {
466 if (reason == UCNV_UNASSIGNED) {
467 if (UChar outChar = fallbackForGBK(codePoint)) {
468 const UChar* source = &outChar;
469 *err = U_ZERO_ERROR;
470 ucnv_cbFromUWriteUChars(fromUArgs, &source, source + 1, 0, err);
471 return;
472 }
473 cssEscapedEntityCallback(context, fromUArgs, codeUnits, length, codePoin t, reason, err);
474 return;
475 }
476 UCNV_FROM_U_CALLBACK_ESCAPE(context, fromUArgs, codeUnits, length, codePoint , reason, err);
477 }
478
446 // Combines both gbkUrlEscapedEntityCallback and GBK character substitution. 479 // Combines both gbkUrlEscapedEntityCallback and GBK character substitution.
447 static void gbkUrlEscapedEntityCallack(const void* context, UConverterFromUnicod eArgs* fromUArgs, const UChar* codeUnits, int32_t length, 480 static void gbkUrlEscapedEntityCallack(const void* context, UConverterFromUnicod eArgs* fromUArgs, const UChar* codeUnits, int32_t length,
448 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) 481 UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err)
449 { 482 {
450 if (reason == UCNV_UNASSIGNED) { 483 if (reason == UCNV_UNASSIGNED) {
451 if (UChar outChar = fallbackForGBK(codePoint)) { 484 if (UChar outChar = fallbackForGBK(codePoint)) {
452 const UChar* source = &outChar; 485 const UChar* source = &outChar;
453 *err = U_ZERO_ERROR; 486 *err = U_ZERO_ERROR;
454 ucnv_cbFromUWriteUChars(fromUArgs, &source, source + 1, 0, err); 487 ucnv_cbFromUWriteUChars(fromUArgs, &source, source + 1, 0, err);
455 return; 488 return;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 ucnv_setFromUCallBack(m_converterICU, m_needsGBKFallbacks ? gbkCallbackE scape : UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_XML_DEC, 0, 0, &err); 556 ucnv_setFromUCallBack(m_converterICU, m_needsGBKFallbacks ? gbkCallbackE scape : UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_XML_DEC, 0, 0, &err);
524 #endif 557 #endif
525 break; 558 break;
526 case URLEncodedEntitiesForUnencodables: 559 case URLEncodedEntitiesForUnencodables:
527 #if !defined(USING_SYSTEM_ICU) 560 #if !defined(USING_SYSTEM_ICU)
528 ucnv_setFromUCallBack(m_converterICU, urlEscapedEntityCallback, 0, 0, 0, &err); 561 ucnv_setFromUCallBack(m_converterICU, urlEscapedEntityCallback, 0, 0, 0, &err);
529 #else 562 #else
530 ucnv_setFromUCallBack(m_converterICU, m_needsGBKFallbacks ? gbkUrlEscape dEntityCallack : urlEscapedEntityCallback, 0, 0, 0, &err); 563 ucnv_setFromUCallBack(m_converterICU, m_needsGBKFallbacks ? gbkUrlEscape dEntityCallack : urlEscapedEntityCallback, 0, 0, 0, &err);
531 #endif 564 #endif
532 break; 565 break;
566 case CSSEncodedEntitiesForUnencodables:
567 #if !defined(USING_SYSTEM_ICU)
568 ucnv_setFromUCallBack(m_converterICU, cssEscapedEntityCallback, 0, 0, 0, &err);
569 #else
570 ucnv_setFromUCallBack(m_converterICU, m_needsGBKFallbacks ? gbkCssEscape dEntityCallack : cssEscapedEntityCallback, 0, 0, 0, &err);
571 #endif
572 break;
533 } 573 }
534 574
535 ASSERT(U_SUCCESS(err)); 575 ASSERT(U_SUCCESS(err));
536 if (U_FAILURE(err)) 576 if (U_FAILURE(err))
537 return CString(); 577 return CString();
538 578
539 Vector<char> result; 579 Vector<char> result;
540 size_t size = 0; 580 size_t size = 0;
541 do { 581 do {
542 char buffer[ConversionBufferSize]; 582 char buffer[ConversionBufferSize];
(...skipping 29 matching lines...) Expand all
572 { 612 {
573 return encodeCommon(characters, length, handling); 613 return encodeCommon(characters, length, handling);
574 } 614 }
575 615
576 CString TextCodecICU::encode(const LChar* characters, size_t length, Unencodable Handling handling) 616 CString TextCodecICU::encode(const LChar* characters, size_t length, Unencodable Handling handling)
577 { 617 {
578 return encodeCommon(characters, length, handling); 618 return encodeCommon(characters, length, handling);
579 } 619 }
580 620
581 } // namespace WTF 621 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/TextCodec.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698