[perl-Glib-Object-Introspection] Implement SV ↔ unichar



commit bfebac797d5c6056a6743e2934592f887688b71f
Author: Torsten Schönfeld <kaffeetisch gmx de>
Date:   Sun Dec 12 20:57:24 2010 +0100

    Implement SV â?? unichar

 GObjectIntrospection.xs |   14 ++++++++++++++
 t/00-basic-types.t      |    4 +++-
 2 files changed, 17 insertions(+), 1 deletions(-)
---
diff --git a/GObjectIntrospection.xs b/GObjectIntrospection.xs
index cfcb498..507c5fd 100644
--- a/GObjectIntrospection.xs
+++ b/GObjectIntrospection.xs
@@ -1332,6 +1332,10 @@ sv_to_arg (SV * sv,
 		arg->v_double = SvNV (sv);
 		break;
 
+	    case GI_TYPE_TAG_UNICHAR:
+		arg->v_uint32 = g_utf8_get_char (SvGChar (sv));
+		break;
+
 	    case GI_TYPE_TAG_GTYPE:
 		/* GType == gsize */
 		arg->v_size = gperl_type_from_package (SvPV_nolen (sv));
@@ -1430,6 +1434,16 @@ arg_to_sv (GIArgument * arg,
 	    case GI_TYPE_TAG_DOUBLE:
 		return newSVnv (arg->v_double);
 
+	    case GI_TYPE_TAG_UNICHAR:
+	    {
+		SV *sv;
+		gchar buffer[6];
+		gint length = g_unichar_to_utf8 (arg->v_uint32, buffer);
+		sv = newSVpv (buffer, length);
+		SvUTF8_on (sv);
+		return sv;
+	    }
+
 	    case GI_TYPE_TAG_GTYPE: {
 		/* GType == gsize */
 		const char *package = gperl_package_from_type (arg->v_size);
diff --git a/t/00-basic-types.t b/t/00-basic-types.t
index e7c516d..478b56b 100644
--- a/t/00-basic-types.t
+++ b/t/00-basic-types.t
@@ -8,7 +8,7 @@ use warnings;
 use utf8;
 use POSIX qw(FLT_MIN FLT_MAX DBL_MIN DBL_MAX);
 
-plan tests => 30;
+plan tests => 31;
 
 ok (test_boolean (1));
 ok (!test_boolean (0));
@@ -25,6 +25,8 @@ delta_ok (test_float (FLT_MAX), FLT_MAX);
 delta_ok (test_double (DBL_MIN), DBL_MIN);
 delta_ok (test_double (DBL_MAX), DBL_MAX);
 
+is (test_unichar ('â?µ'), 'â?µ');
+
 is (test_gtype ('Glib::Object'), 'Glib::Object');
 TODO: {
   local $TODO = 'Is that how we want to handle unregistered GTypes?';



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]