[svn:parrot] r46533 - in trunk: . src/ops t/op

NotFound at svn.parrot.org NotFound at svn.parrot.org
Wed May 12 14:55:37 UTC 2010


Author: NotFound
Date: Wed May 12 14:55:36 2010
New Revision: 46533
URL: https://trac.parrot.org/parrot/changeset/46533

Log:
experimental op find_codepoint

Modified:
   trunk/DEPRECATED.pod
   trunk/src/ops/experimental.ops
   trunk/t/op/stringu.t

Modified: trunk/DEPRECATED.pod
==============================================================================
--- trunk/DEPRECATED.pod	Wed May 12 13:23:38 2010	(r46532)
+++ trunk/DEPRECATED.pod	Wed May 12 14:55:36 2010	(r46533)
@@ -218,6 +218,12 @@
 
 L<https://trac.parrot.org/parrot/ticket/1540>
 
+=item find_codepoint [experimental]
+
+Intended to replace the CodeString charname_to_ord method.
+
+(Trac ticket coming soon).
+
 =back
 
 =head1 Bytecode

Modified: trunk/src/ops/experimental.ops
==============================================================================
--- trunk/src/ops/experimental.ops	Wed May 12 13:23:38 2010	(r46532)
+++ trunk/src/ops/experimental.ops	Wed May 12 14:55:36 2010	(r46533)
@@ -3,6 +3,14 @@
 ** experimental.ops
 */
 
+BEGIN_OPS_PREAMBLE
+
+#if PARROT_HAS_ICU
+#  include <unicode/uchar.h>
+#endif
+
+END_OPS_PREAMBLE
+
 =head1 NAME
 
 experimental.ops - Experimental Opcodes
@@ -304,8 +312,6 @@
 
 =item B<root_new>(out PMC, in PMC, in INT)
 
-=back
-
 =cut
 
 op root_new(out PMC, in PMC, in INT) {
@@ -340,6 +346,28 @@
     }
 }
 
+=item B<find_codepoint>(out INT, in STR)
+
+Set $1 to the codepoint with the name given in $2, or -1 if there is none.
+Requires ICU lib, otherwise exception is thrown.
+
+=cut
+
+op find_codepoint(out INT, in STR) {
+#if PARROT_HAS_ICU
+    UErrorCode   err       = U_ZERO_ERROR;
+    char * const cstr      = Parrot_str_to_cstring(interp, $2);
+    UChar32      codepoint = u_charFromName(U_EXTENDED_CHAR_NAME, cstr, &err);
+    Parrot_str_free_cstring(cstr);
+    $1 = U_SUCCESS(err) ? (INTVAL) codepoint : -1;
+#else
+    Parrot_ex_throw_from_op_args(INTERP, NULL, EXCEPTION_LIBRARY_ERROR,
+        "no ICU lib loaded");
+#endif
+}
+
+=back
+
 =head1 COPYRIGHT
 
 Copyright (C) 2001-2010, Parrot Foundation.

Modified: trunk/t/op/stringu.t
==============================================================================
--- trunk/t/op/stringu.t	Wed May 12 13:23:38 2010	(r46532)
+++ trunk/t/op/stringu.t	Wed May 12 14:55:36 2010	(r46533)
@@ -6,7 +6,7 @@
 use warnings;
 use lib qw( . lib ../lib ../../lib );
 use Test::More;
-use Parrot::Test tests => 32;
+use Parrot::Test tests => 33;
 use Parrot::Config;
 
 =head1 NAME
@@ -574,6 +574,17 @@
 equal
 OUT
 
+SKIP: {
+    skip( 'no ICU lib', 1 ) unless $PConfig{has_icu};
+pir_output_is( <<'CODE', <<'OUT', 'find_codepoint opcode (experimental)');
+.sub 'main'
+    $I1 = find_codepoint 'THISISNOTTHENAMEOFNOTHING'
+    say $I1
+.end
+CODE
+-1
+OUT
+}
 
 # Local Variables:
 #   mode: cperl


More information about the parrot-commits mailing list