// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/i18n/icu_string_conversions.h" #include <stddef.h> #include <stdint.h> #include <memory> #include <string_view> #include "base/check.h" #include "base/types/fixed_array.h" #include "base/notreached.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "third_party/icu/source/common/unicode/normalizer2.h" #include "third_party/icu/source/common/unicode/ucnv.h" #include "third_party/icu/source/common/unicode/ucnv_cb.h" #include "third_party/icu/source/common/unicode/ucnv_err.h" #include "third_party/icu/source/common/unicode/ustring.h" namespace base { namespace { // ToUnicodeCallbackSubstitute() is based on UCNV_TO_U_CALLBACK_SUBSTITUTE // in source/common/ucnv_err.c. // Copyright (c) 1995-2006 International Business Machines Corporation // and others // // All rights reserved. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, and/or // sell copies of the Software, and to permit persons to whom the Software // is furnished to do so, provided that the above copyright notice(s) and // this permission notice appear in all copies of the Software and that // both the above copyright notice(s) and this permission notice appear in // supporting documentation. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT // OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS // INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT // OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS // OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE // OR PERFORMANCE OF THIS SOFTWARE. // // Except as contained in this notice, the name of a copyright holder // shall not be used in advertising or otherwise to promote the sale, use // or other dealings in this Software without prior written authorization // of the copyright holder. // ___________________________________________________________________________ // // All trademarks and registered trademarks mentioned herein are the property // of their respective owners. void ToUnicodeCallbackSubstitute(const void* context, UConverterToUnicodeArgs *to_args, const char* code_units, int32_t length, UConverterCallbackReason reason, UErrorCode * err) { … } bool ConvertFromUTF16(UConverter* converter, std::u16string_view src, OnStringConversionError::Type on_error, std::string* encoded) { … } // Set up our error handler for ToUTF-16 converters void SetUpErrorHandlerForToUChars(OnStringConversionError::Type on_error, UConverter* converter, UErrorCode* status) { … } } // namespace // Codepage <-> Wide/UTF-16 --------------------------------------------------- bool UTF16ToCodepage(std::u16string_view utf16, const char* codepage_name, OnStringConversionError::Type on_error, std::string* encoded) { … } bool CodepageToUTF16(std::string_view encoded, const char* codepage_name, OnStringConversionError::Type on_error, std::u16string* utf16) { … } bool ConvertToUtf8AndNormalize(std::string_view text, const std::string& charset, std::string* result) { … } } // namespace base