+2007-06-03 Kamil Skalski <nazgul@nemerle.org>
+
+ * SQLiteConvert.cs: Port function for converting native UTF8 string\r
+ into managed string from the old SqliteClient implementation.\r
+ Use it instead of PtrToStrAuto, which fails on Windows.
+\r
2007-02-20 Marek Habersack <grendello@gmail.com>
* SQLite3.cs: handle sqlite3_prepare_v2 absent from the library,
/// <returns>A string containing the translated character(s)</returns>
public virtual string UTF8ToString(IntPtr nativestring)
{
- return Marshal.PtrToStringAuto (nativestring);
+ if (nativestring == IntPtr.Zero)
+ return null;
+
+ // This assumes a single byte terminates the string.
+
+ int len = 0;
+ while (Marshal.ReadByte (nativestring, len) != 0)
+ checked {++len;}
+\r
+ unsafe { \r
+ string s = new string ((sbyte*) nativestring, 0, len, _utf8);
+ len = s.Length;
+ while (len > 0 && s [len-1] == 0)
+ --len;
+ if (len == s.Length)
+ return s;
+ return s.Substring (0, len);\r
+ }
}