Fix emulator build error
[platform/framework/web/chromium-efl.git] / base / i18n / icu_string_conversions.cc
index 6ec9980..434c6e8 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// 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.
 
@@ -8,9 +8,9 @@
 #include <stdint.h>
 
 #include <memory>
-#include <vector>
 
-#include "base/logging.h"
+#include "base/check.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"
@@ -80,11 +80,12 @@ void ToUnicodeCallbackSubstitute(const void* context,
   // else ignore the reset, close and clone calls.
 }
 
-bool ConvertFromUTF16(UConverter* converter, const UChar* uchar_src,
-                      int uchar_len, OnStringConversionError::Type on_error,
+bool ConvertFromUTF16(UConverter* converter,
+                      base::StringPiece16 src,
+                      OnStringConversionError::Type on_error,
                       std::string* encoded) {
-  int encoded_max_length = UCNV_GET_MAX_BYTES_FOR_STRING(uchar_len,
-      ucnv_getMaxCharSize(converter));
+  int encoded_max_length = UCNV_GET_MAX_BYTES_FOR_STRING(
+      src.length(), ucnv_getMaxCharSize(converter));
   encoded->resize(encoded_max_length);
 
   UErrorCode status = U_ZERO_ERROR;
@@ -100,13 +101,12 @@ bool ConvertFromUTF16(UConverter* converter, const UChar* uchar_src,
       ucnv_setFromUCallBack(converter, UCNV_FROM_U_CALLBACK_SKIP, nullptr,
                             nullptr, nullptr, &status);
       break;
-    default:
-      NOTREACHED();
   }
 
   // ucnv_fromUChars returns size not including terminating null
-  int actual_size = ucnv_fromUChars(converter, &(*encoded)[0],
-      encoded_max_length, uchar_src, uchar_len, &status);
+  int actual_size =
+      ucnv_fromUChars(converter, &(*encoded)[0], encoded_max_length, src.data(),
+                      src.length(), &status);
   encoded->resize(actual_size);
   ucnv_close(converter);
   if (U_SUCCESS(status))
@@ -131,8 +131,6 @@ void SetUpErrorHandlerForToUChars(OnStringConversionError::Type on_error,
       ucnv_setToUCallBack(converter, ToUnicodeCallbackSubstitute, nullptr,
                           nullptr, nullptr, status);
       break;
-    default:
-      NOTREACHED();
   }
 }
 
@@ -140,7 +138,7 @@ void SetUpErrorHandlerForToUChars(OnStringConversionError::Type on_error,
 
 // Codepage <-> Wide/UTF-16  ---------------------------------------------------
 
-bool UTF16ToCodepage(const string16& utf16,
+bool UTF16ToCodepage(base::StringPiece16 utf16,
                      const char* codepage_name,
                      OnStringConversionError::Type on_error,
                      std::string* encoded) {
@@ -151,14 +149,13 @@ bool UTF16ToCodepage(const string16& utf16,
   if (!U_SUCCESS(status))
     return false;
 
-  return ConvertFromUTF16(converter, utf16.c_str(),
-                          static_cast<int>(utf16.length()), on_error, encoded);
+  return ConvertFromUTF16(converter, utf16, on_error, encoded);
 }
 
-bool CodepageToUTF16(const std::string& encoded,
+bool CodepageToUTF16(base::StringPiece encoded,
                      const char* codepage_name,
                      OnStringConversionError::Type on_error,
-                     string16* utf16) {
+                     std::u16string* utf16) {
   utf16->clear();
 
   UErrorCode status = U_ZERO_ERROR;
@@ -177,10 +174,10 @@ bool CodepageToUTF16(const std::string& encoded,
   size_t uchar_max_length = encoded.length() + 1;
 
   SetUpErrorHandlerForToUChars(on_error, converter, &status);
-  std::unique_ptr<char16[]> buffer(new char16[uchar_max_length]);
-  int actual_size = ucnv_toUChars(converter, buffer.get(),
-      static_cast<int>(uchar_max_length), encoded.data(),
-      static_cast<int>(encoded.length()), &status);
+  std::unique_ptr<char16_t[]> buffer(new char16_t[uchar_max_length]);
+  int actual_size = ucnv_toUChars(
+      converter, buffer.get(), static_cast<int>(uchar_max_length),
+      encoded.data(), static_cast<int>(encoded.length()), &status);
   ucnv_close(converter);
   if (!U_SUCCESS(status)) {
     utf16->clear();  // Make sure the output is empty on error.
@@ -191,13 +188,13 @@ bool CodepageToUTF16(const std::string& encoded,
   return true;
 }
 
-bool ConvertToUtf8AndNormalize(const std::string& text,
+bool ConvertToUtf8AndNormalize(base::StringPiece text,
                                const std::string& charset,
                                std::string* result) {
   result->clear();
-  string16 utf16;
-  if (!CodepageToUTF16(
-      text, charset.c_str(), OnStringConversionError::FAIL, &utf16))
+  std::u16string utf16;
+  if (!CodepageToUTF16(text, charset.c_str(), OnStringConversionError::FAIL,
+                       &utf16))
     return false;
 
   UErrorCode status = U_ZERO_ERROR;