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

Side by Side Diff: base/android/jni_string.cc

Issue 109863003: Use StringPiece for UTF string conversions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | base/i18n/icu_string_conversions.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/android/jni_string.h" 5 #include "base/android/jni_string.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 10
(...skipping 16 matching lines...) Expand all
27 if (!str) { 27 if (!str) {
28 LOG(WARNING) << "ConvertJavaStringToUTF8 called with null string."; 28 LOG(WARNING) << "ConvertJavaStringToUTF8 called with null string.";
29 result->clear(); 29 result->clear();
30 return; 30 return;
31 } 31 }
32 // JNI's GetStringUTFChars() returns strings in Java "modified" UTF8, so 32 // JNI's GetStringUTFChars() returns strings in Java "modified" UTF8, so
33 // instead get the String in UTF16 and convert using chromium's conversion 33 // instead get the String in UTF16 and convert using chromium's conversion
34 // function that yields plain (non Java-modified) UTF8. 34 // function that yields plain (non Java-modified) UTF8.
35 const jchar* chars = env->GetStringChars(str, NULL); 35 const jchar* chars = env->GetStringChars(str, NULL);
36 DCHECK(chars); 36 DCHECK(chars);
37 UTF16ToUTF8(chars, env->GetStringLength(str), result); 37 UTF16ToUTF8(base::StringPiece(chars, env->GetStringLength(str)), result);
38 env->ReleaseStringChars(str, chars); 38 env->ReleaseStringChars(str, chars);
39 CheckException(env); 39 CheckException(env);
40 } 40 }
41 41
42 std::string ConvertJavaStringToUTF8(JNIEnv* env, jstring str) { 42 std::string ConvertJavaStringToUTF8(JNIEnv* env, jstring str) {
43 std::string result; 43 std::string result;
44 ConvertJavaStringToUTF8(env, str, &result); 44 ConvertJavaStringToUTF8(env, str, &result);
45 return result; 45 return result;
46 } 46 }
47 47
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 ScopedJavaLocalRef<jstring> ConvertUTF16ToJavaString( 91 ScopedJavaLocalRef<jstring> ConvertUTF16ToJavaString(
92 JNIEnv* env, 92 JNIEnv* env,
93 const base::StringPiece16& str) { 93 const base::StringPiece16& str) {
94 return ScopedJavaLocalRef<jstring>(env, 94 return ScopedJavaLocalRef<jstring>(env,
95 ConvertUTF16ToJavaStringImpl(env, str)); 95 ConvertUTF16ToJavaStringImpl(env, str));
96 } 96 }
97 97
98 } // namespace android 98 } // namespace android
99 } // namespace base 99 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/i18n/icu_string_conversions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698