jni_string.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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
  3. // found in the LICENSE file.
  4. #ifndef BASE_ANDROID_JNI_STRING_H_
  5. #define BASE_ANDROID_JNI_STRING_H_
  6. #include <jni.h>
  7. #include <string>
  8. #include "base/android/scoped_java_ref.h"
  9. #include "base/base_export.h"
  10. #include "base/strings/string_piece.h"
  11. namespace base {
  12. namespace android {
  13. // Convert a Java string to UTF8. Returns a std string.
  14. BASE_EXPORT void ConvertJavaStringToUTF8(JNIEnv* env,
  15. jstring str,
  16. std::string* result);
  17. BASE_EXPORT std::string ConvertJavaStringToUTF8(JNIEnv* env, jstring str);
  18. BASE_EXPORT std::string ConvertJavaStringToUTF8(const JavaRef<jstring>& str);
  19. BASE_EXPORT std::string ConvertJavaStringToUTF8(JNIEnv* env,
  20. const JavaRef<jstring>& str);
  21. // Convert a std string to Java string.
  22. BASE_EXPORT ScopedJavaLocalRef<jstring> ConvertUTF8ToJavaString(
  23. JNIEnv* env,
  24. const base::StringPiece& str);
  25. // Convert a Java string to UTF16. Returns a string16.
  26. BASE_EXPORT void ConvertJavaStringToUTF16(JNIEnv* env,
  27. jstring str,
  28. string16* result);
  29. BASE_EXPORT string16 ConvertJavaStringToUTF16(JNIEnv* env, jstring str);
  30. BASE_EXPORT string16 ConvertJavaStringToUTF16(const JavaRef<jstring>& str);
  31. BASE_EXPORT string16 ConvertJavaStringToUTF16(JNIEnv* env,
  32. const JavaRef<jstring>& str);
  33. // Convert a string16 to a Java string.
  34. BASE_EXPORT ScopedJavaLocalRef<jstring> ConvertUTF16ToJavaString(
  35. JNIEnv* env,
  36. const base::StringPiece16& str);
  37. } // namespace android
  38. } // namespace base
  39. #endif // BASE_ANDROID_JNI_STRING_H_