diff --git a/ChangeLog b/ChangeLog index 7c2bbe02f..6829fc306 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-03-10 Mike Kestner + + * glib/Marshaller.cs : don't use g_utf8_strlen to determine the byte + count to be copied, it returns chars, not bytes. + * glib/glue/unichar.c : implement a quick and dirty strlen glue func. + 2005-03-10 Mike Kestner * gtk/Style.custom : add bg_pixmap accessors. remove IntPtr[] vars diff --git a/glib/Marshaller.cs b/glib/Marshaller.cs index 45fa0f19d..9a67fe199 100644 --- a/glib/Marshaller.cs +++ b/glib/Marshaller.cs @@ -37,15 +37,15 @@ namespace GLib { g_free (ptr); } - [DllImport("libglib-2.0-0.dll")] - static extern IntPtr g_utf8_strlen (IntPtr mem, int size); + [DllImport("glibsharpglue-2")] + static extern UIntPtr glibsharp_strlen (IntPtr mem); public static string Utf8PtrToString (IntPtr ptr) { if (ptr == IntPtr.Zero) return null; - int len = (int) g_utf8_strlen (ptr, -1); + int len = (int) (uint)glibsharp_strlen (ptr); byte[] bytes = new byte [len]; Marshal.Copy (ptr, bytes, 0, len); return System.Text.Encoding.UTF8.GetString (bytes); diff --git a/glib/glue/unichar.c b/glib/glue/unichar.c index b9faf9f9b..b0f361dd9 100644 --- a/glib/glue/unichar.c +++ b/glib/glue/unichar.c @@ -25,6 +25,7 @@ /* Forward declarations */ gchar *gtksharp_unichar_to_utf8_string (gunichar chr); gunichar glibsharp_utf16_to_unichar (guint16 chr); +gssize glibsharp_strlen (gchar *s); /* */ gchar * @@ -48,3 +49,11 @@ glibsharp_utf16_to_unichar (guint16 chr) return result; } +gssize +glibsharp_strlen (gchar *s) +{ + gssize cnt = 0; + for (cnt = 0; *s; s++, cnt++); + return cnt; +} +