google / jni-bind

JNI Bind is a set of advanced syntactic sugar for writing efficient correct JNI Code in C++17 (and up).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UTF-8 string conversion methods

paulocoutinhox opened this issue · comments

Hi,

I want suggest to add string convertion methods, example:
https://github.com/xplpc/xplpc/blob/main/jni/lib/src/xplpc/jni/support.cpp

Since this library will solve JNI problems, why not methods to work with String convertions :)

Thanks.

Ok, you're specifically referring to UTF8 correct?

If so, could you update the bug title to reflect that? I assume you're aware that there are already string conversions for existing char*, std::string etc.

So, I took a pass through your conversion code, and had a chance to think a bit on this myself.

I think your conversion may be simple a subset of the behaviour LocalString already supports.

The former case is a function that takes in a std::string and performs a conversion to UTF16 from UTF8. I believe just using a regular ctor is equivalent?

The latter converts from a UTF16 string to a regular std::string, however, LocalString just directly asks for a UTF8 string, so you're probably just making your conversion explicit, or making an unnecessary one (I don't know what the JVM does internally).

That said, in C++20, UTF16 has its own view std::filesystem::path::u16string. Here, calling GetUtfString could actually be efficiently represented. So, I think this should be revisited when C++20 support is added, but I think your conversion methods are already covered.