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

Side by Side Diff: base/strings/utf_string_conversions.cc

Issue 1125773004: Pull in ASCII<->UTF16 from Chromium (Closed) Base URL: https://chromium.googlesource.com/chromium/mini_chromium@master
Patch Set: Created 5 years, 7 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
OLDNEW
1 // Copyright 2009 The Chromium Authors. All rights reserved. 1 // Copyright 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/logging.h"
11 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversion_utils.h" 14 #include "base/strings/utf_string_conversion_utils.h"
13 15
14 namespace { 16 namespace {
15 17
16 template<typename SRC_CHAR, typename DEST_STRING> 18 template<typename SRC_CHAR, typename DEST_STRING>
17 bool ConvertUnicode(const SRC_CHAR* src, 19 bool ConvertUnicode(const SRC_CHAR* src,
18 size_t src_len, 20 size_t src_len,
19 DEST_STRING* output) { 21 DEST_STRING* output) {
20 bool success = true; 22 bool success = true;
21 int32_t src_len32 = static_cast<int32_t>(src_len); 23 int32_t src_len32 = static_cast<int32_t>(src_len);
(...skipping 29 matching lines...) Expand all
51 base::PrepareForUTF8Output(src, src_len, output); 53 base::PrepareForUTF8Output(src, src_len, output);
52 return ConvertUnicode(src, src_len, output); 54 return ConvertUnicode(src, src_len, output);
53 } 55 }
54 56
55 std::string UTF16ToUTF8(const string16& utf16) { 57 std::string UTF16ToUTF8(const string16& utf16) {
56 std::string ret; 58 std::string ret;
57 UTF16ToUTF8(utf16.data(), utf16.length(), &ret); 59 UTF16ToUTF8(utf16.data(), utf16.length(), &ret);
58 return ret; 60 return ret;
59 } 61 }
60 62
63 string16 ASCIIToUTF16(const StringPiece& ascii) {
64 DCHECK(IsStringASCII(ascii)) << ascii;
65 return string16(ascii.begin(), ascii.end());
66 }
67
68 std::string UTF16ToASCII(const string16& utf16) {
69 DCHECK(IsStringASCII(utf16)) << UTF16ToUTF8(utf16);
70 return std::string(utf16.begin(), utf16.end());
71 }
61 } // namespace 72 } // namespace
OLDNEW
« base/strings/string_util.cc ('K') | « base/strings/utf_string_conversions.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698