Chromium Code Reviews| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 return target - targetStart; | 304 return target - targetStart; |
| 305 } | 305 } |
| 306 | 306 |
| 307 class ErrorCallbackSetter final { | 307 class ErrorCallbackSetter final { |
| 308 STACK_ALLOCATED(); | 308 STACK_ALLOCATED(); |
| 309 public: | 309 public: |
| 310 ErrorCallbackSetter(UConverter* converter, bool stopOnError) | 310 ErrorCallbackSetter(UConverter* converter, bool stopOnError) |
| 311 : m_converter(converter) | 311 : m_converter(converter) |
| 312 , m_shouldStopOnEncodingErrors(stopOnError) | 312 , m_shouldStopOnEncodingErrors(stopOnError) |
| 313 { | 313 { |
| 314 if (m_shouldStopOnEncodingErrors) { | 314 UErrorCode err = U_ZERO_ERROR; |
| 315 UErrorCode err = U_ZERO_ERROR; | 315 if (m_shouldStopOnEncodingErrors) |
| 316 ucnv_setToUCallBack(m_converter, UCNV_TO_U_CALLBACK_SUBSTITUTE, | 316 ucnv_setToUCallBack(m_converter, UCNV_TO_U_CALLBACK_STOP, 0, &m_save dAction, &m_savedContext, &err); |
| 317 UCNV_SUB_STOP_ON_ILLEGAL, &m_savedAction, | 317 else |
| 318 &m_savedContext, &err); | 318 ucnv_setToUCallBack(m_converter, UCNV_TO_U_CALLBACK_SUBSTITUTE, 0, & m_savedAction, &m_savedContext, &err); |
|
jsbell
2016/08/09 22:27:24
Maybe we only want the `if (m_shouldStopOnEncoding
jungshik at Google
2016/08/12 07:20:41
Indeed, confusing.
https://cs.chromium.org/chrom
| |
| 319 ASSERT(err == U_ZERO_ERROR); | 319 DCHECK_EQ(err, U_ZERO_ERROR); |
| 320 } | |
| 321 } | 320 } |
| 322 ~ErrorCallbackSetter() | 321 ~ErrorCallbackSetter() |
| 323 { | 322 { |
| 324 if (m_shouldStopOnEncodingErrors) { | 323 UErrorCode err = U_ZERO_ERROR; |
| 325 UErrorCode err = U_ZERO_ERROR; | 324 const void* oldContext; |
| 326 const void* oldContext; | 325 UConverterToUCallback oldAction; |
| 327 UConverterToUCallback oldAction; | 326 ucnv_setToUCallBack(m_converter, m_savedAction, m_savedContext, &oldActi on, &oldContext, &err); |
| 328 ucnv_setToUCallBack(m_converter, m_savedAction, m_savedContext, &old Action, &oldContext, &err); | 327 DCHECK_EQ(oldAction, m_shouldStopOnEncodingErrors ? UCNV_TO_U_CALLBACK_S TOP : UCNV_TO_U_CALLBACK_SUBSTITUTE); |
| 329 ASSERT(oldAction == UCNV_TO_U_CALLBACK_SUBSTITUTE); | 328 DCHECK(!oldContext); |
| 330 ASSERT(!strcmp(static_cast<const char*>(oldContext), UCNV_SUB_STOP_O N_ILLEGAL)); | 329 DCHECK_EQ(err, U_ZERO_ERROR); |
| 331 ASSERT(err == U_ZERO_ERROR); | |
| 332 } | |
| 333 } | 330 } |
| 334 | 331 |
| 335 private: | 332 private: |
| 336 UConverter* m_converter; | 333 UConverter* m_converter; |
| 337 bool m_shouldStopOnEncodingErrors; | 334 bool m_shouldStopOnEncodingErrors; |
| 338 const void* m_savedContext; | 335 const void* m_savedContext; |
| 339 UConverterToUCallback m_savedAction; | 336 UConverterToUCallback m_savedAction; |
| 340 }; | 337 }; |
| 341 | 338 |
| 342 String TextCodecICU::decode(const char* bytes, size_t length, FlushBehavior flus h, bool stopOnError, bool& sawError) | 339 String TextCodecICU::decode(const char* bytes, size_t length, FlushBehavior flus h, bool stopOnError, bool& sawError) |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 610 { | 607 { |
| 611 return encodeCommon(characters, length, handling); | 608 return encodeCommon(characters, length, handling); |
| 612 } | 609 } |
| 613 | 610 |
| 614 CString TextCodecICU::encode(const LChar* characters, size_t length, Unencodable Handling handling) | 611 CString TextCodecICU::encode(const LChar* characters, size_t length, Unencodable Handling handling) |
| 615 { | 612 { |
| 616 return encodeCommon(characters, length, handling); | 613 return encodeCommon(characters, length, handling); |
| 617 } | 614 } |
| 618 | 615 |
| 619 } // namespace WTF | 616 } // namespace WTF |
| OLD | NEW |