[Kde-bindings] KDE/kdebindings/csharp/qyoto/src
Arno Rehn
kde at arnorehn.de
Wed Oct 21 13:41:03 UTC 2009
SVN commit 1038599 by arnorehn:
Handle unicode strings correctly.
CCMAIL: kde-bindings at kde.org
M +2 -2 SmokeMarshallers.cs
M +9 -5 handlers.cpp
M +1 -1 qyoto.h
--- trunk/KDE/kdebindings/csharp/qyoto/src/SmokeMarshallers.cs #1038598:1038599
@@ -32,10 +32,10 @@
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
public static extern IntPtr StringArrayToCharStarStar(int length, string[] strArray);
- [DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ [DllImport("libqyoto", CharSet=CharSet.Unicode)]
public static extern IntPtr StringToQString(string str);
- [DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ [DllImport("libqyoto", CharSet=CharSet.Unicode)]
public static extern string StringFromQString(IntPtr ptr);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
--- trunk/KDE/kdebindings/csharp/qyoto/src/handlers.cpp #1038598:1038599
@@ -785,17 +785,21 @@
}
Q_DECL_EXPORT void *
-StringToQString(char *str)
+StringToQString(const ushort *str)
{
- QString * result = new QString(QString::fromUtf8(str));
+ QString * result = new QString(QString::fromUtf16(str));
return (void *) result;
}
-Q_DECL_EXPORT char *
+Q_DECL_EXPORT const ushort *
StringFromQString(void *ptr)
{
- QByteArray ba = ((QString *) ptr)->toUtf8();
- return strdup(ba.constData());
+ QString* str = (QString*) ptr;
+ int len = str->length() + 1; // include the terminating \0
+ ushort *copy = new ushort[len];
+ memcpy(copy, str->utf16(), sizeof(ushort) * len);
+ // return a copy of the string - the runtime will take ownership of it and care about deletion
+ return copy;
}
Q_DECL_EXPORT void *
--- trunk/KDE/kdebindings/csharp/qyoto/src/qyoto.h #1038598:1038599
@@ -148,7 +148,7 @@
extern ConstructDict ConstructDictionary;
extern DictToHash DictionaryToQHash;
extern DictToMap DictionaryToQMap;
-extern char *StringFromQString(void *ptr);
+extern const ushort *StringFromQString(void *ptr);
extern InvokeMethodFn AddObjectObjectToDictionary;
extern Q_DECL_EXPORT GetIntPtr IntPtrToCharStarStar;
More information about the Kde-bindings
mailing list