开发者

Solution for missing std::wstring support in Android NDK?

I have a game which uses std::wstring as its basic string type in thousand of places as well as doing operations with wchar_t and its functions: wcsicmp() wcslen() vsprintf(), etc.

The problem is wstring is not supported in R5c (latest ndk at the time of this writting).

I can't change the code to use std::string because of internationalization and I would be breaking the game engine which is used by many games ...

Which options do I have?

1 - Replace string and wstring with my own string classes

This would give me better platform independency, but it is ridiculous to reimplement the wheel. I've already started with a COW implementation of strings. I need it to be COW because I use them as keys in hash_maps. This is of course lots of work and error prone ... but it seems it is something I can do.

2 - Try to fix the NDK recompiling the STLPort with my own implementations of the wide char string functions of the C standart libr开发者_Go百科ary (wcslen, mbstowcs ... )

This would be the preferable way ... but I have no idea how to do it :(

How do I replace a function (lets say wcslen) in the libstdc++.a or libstlport_static.a? (not sure where they are :()

And as well I'm not sure which functions I need to reimplement, I know wcslen is not working so I guess they should be all ...

3 - Do you have any other idea?

I can't wait for an official fix for this and I will have to go with option #1 if I can't realize how to do #2.

I've read somewhere that if you target 2.3 you can use wstrings, but I ought to target Android 2.1.

PS: Forgot to say I need to use STL of course, but no RTTI and I can live without exceptions.

Thanks in advance!


Try out CrystaX's NDK. It has had stl support long before the official google one. The current version (r5), which is based off the of the official ndk r5, is still beta 3, but it does have wchar_t support.

http://www.crystax.net/android/ndk-r5.php


I'm suffering from the same problem as you, but my only other thought is to load the strings via the JNI (as jstring* in native land), then convert them to UTF characters as necessary. Take a look at the available JNI string functions here:
http://download.oracle.com/javase/1.5.0/docs/guide/jni/spec/functions.html#string_operations


Qt provides an excellent copy-on-write, international-friendly string implementation, QString, that is LGPLed.

You could, in theory extract it from the Qt source and use it in your own project. You will find the QString implementation in src/corelib/tools/qstring.h and .cpp in a Qt source download. You would also need the QChar, QByteArray, QAtomic, and QNamespace includes/classes (all under the corelib folder,) and you should define QT_NO_STL_WCHAR when compiling. (For this I would compile by hand or using my own script/Makefile.) Not simple, but once you get it up and running your life will be a lot simpler. It's better than reinventing the wheel, because it comes with loads of convenience functions and features.

Rather than stripping out just QString, you could also just use the QtCore module as a whole. See the android-lighthouse project for a Qt port to Android. (Also, it might be better to get your sources from there than from the above "vanilla" link, regardless of what you do.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜