[email protected] | fe0f1ab | 2012-02-09 21:02:27 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef BASE_ANDROID_JNI_STRING_H_ | ||||
6 | #define BASE_ANDROID_JNI_STRING_H_ | ||||
7 | |||||
8 | #include <jni.h> | ||||
9 | #include <string> | ||||
10 | |||||
[email protected] | fe0f1ab | 2012-02-09 21:02:27 | [diff] [blame] | 11 | #include "base/android/scoped_java_ref.h" |
[email protected] | be363b2 | 2012-11-01 17:38:47 | [diff] [blame] | 12 | #include "base/base_export.h" |
[email protected] | eb62f726 | 2013-03-30 14:29:00 | [diff] [blame] | 13 | #include "base/strings/string_piece.h" |
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 14 | |
15 | namespace base { | ||||
16 | namespace android { | ||||
17 | |||||
18 | // Convert a Java string to UTF8. Returns a std string. | ||||
[email protected] | df0d714 | 2012-12-14 01:31:17 | [diff] [blame] | 19 | BASE_EXPORT void ConvertJavaStringToUTF8(JNIEnv* env, |
20 | jstring str, | ||||
21 | std::string* result); | ||||
[email protected] | be363b2 | 2012-11-01 17:38:47 | [diff] [blame] | 22 | BASE_EXPORT std::string ConvertJavaStringToUTF8(JNIEnv* env, jstring str); |
23 | BASE_EXPORT std::string ConvertJavaStringToUTF8(const JavaRef<jstring>& str); | ||||
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 24 | |
25 | // Convert a std string to Java string. | ||||
[email protected] | be363b2 | 2012-11-01 17:38:47 | [diff] [blame] | 26 | BASE_EXPORT ScopedJavaLocalRef<jstring> ConvertUTF8ToJavaString( |
[email protected] | 053a96d | 2012-06-12 03:25:44 | [diff] [blame] | 27 | JNIEnv* env, |
28 | const base::StringPiece& str); | ||||
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 29 | |
30 | // Convert a Java string to UTF16. Returns a string16. | ||||
[email protected] | df0d714 | 2012-12-14 01:31:17 | [diff] [blame] | 31 | BASE_EXPORT void ConvertJavaStringToUTF16(JNIEnv* env, |
32 | jstring str, | ||||
33 | string16* result); | ||||
[email protected] | be363b2 | 2012-11-01 17:38:47 | [diff] [blame] | 34 | BASE_EXPORT string16 ConvertJavaStringToUTF16(JNIEnv* env, jstring str); |
35 | BASE_EXPORT string16 ConvertJavaStringToUTF16(const JavaRef<jstring>& str); | ||||
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 36 | |
37 | // Convert a string16 to a Java string. | ||||
[email protected] | be363b2 | 2012-11-01 17:38:47 | [diff] [blame] | 38 | BASE_EXPORT ScopedJavaLocalRef<jstring> ConvertUTF16ToJavaString( |
[email protected] | 053a96d | 2012-06-12 03:25:44 | [diff] [blame] | 39 | JNIEnv* env, |
40 | const base::StringPiece16& str); | ||||
[email protected] | 61c86c6 | 2011-08-02 16:11:16 | [diff] [blame] | 41 | |
42 | } // namespace android | ||||
43 | } // namespace base | ||||
44 | |||||
45 | #endif // BASE_ANDROID_JNI_STRING_H_ |