[svn:parrot] r39369 - trunk/src/pmc
NotFound at svn.parrot.org
NotFound at svn.parrot.org
Wed Jun 3 17:05:19 UTC 2009
Author: NotFound
Date: Wed Jun 3 17:05:18 2009
New Revision: 39369
URL: https://trac.parrot.org/parrot/changeset/39369
Log:
[cage] cleaning and refactoring, no functional changes
Modified:
trunk/src/pmc/stringhandle.pmc
Modified: trunk/src/pmc/stringhandle.pmc
==============================================================================
--- trunk/src/pmc/stringhandle.pmc Wed Jun 3 14:56:33 2009 (r39368)
+++ trunk/src/pmc/stringhandle.pmc Wed Jun 3 17:05:18 2009 (r39369)
@@ -11,15 +11,40 @@
The StringHandle PMC performs I/O operations, but on an internal string rather
than an external file. Commonly used as a mock FileHandle for testing.
-=head2 Vtable Functions
+=cut
+
+*/
+
+#include "../src/io/io_private.h"
+
+PARROT_INLINE
+static int encoding_is_utf8(PARROT_INTERP, ARGIN_NULLOK(STRING *s));
+
+/*
+
+=head2 Internal Functions
=over 4
+=item C<static int encoding_is_utf8()>
+
+Helper function for internal usage. Return 1 if the string argument is
+not null and has utf8 encoding, 0 otherwise.
+
+=back
+
=cut
*/
-#include "../src/io/io_private.h"
+PARROT_INLINE
+static int encoding_is_utf8(PARROT_INTERP, ARGIN_NULLOK(STRING *s))
+{
+ if (STRING_IS_NULL(s))
+ return 0;
+ else
+ return Parrot_str_equal(interp, s, CONST_STRING(interp, "utf8"));
+}
pmclass StringHandle need_ext {
ATTR INTVAL flags; /* Filehandle flags */
@@ -31,6 +56,10 @@
/*
+=head2 Vtable Functions
+
+=over 4
+
=item C<void init()>
Initializes a newly created StringHandle object.
@@ -176,8 +205,7 @@
STRING *encoding;
GET_ATTR_encoding(INTERP, SELF, encoding);
- if (!STRING_IS_NULL(encoding)
- && Parrot_str_equal(INTERP, encoding, CONST_STRING(INTERP, "utf8")))
+ if (encoding_is_utf8(INTERP, encoding))
new_string = string_make(INTERP, "", 0, "unicode", 0);
else
new_string = Parrot_str_new(INTERP, "", 0);
@@ -343,9 +371,7 @@
if (STRING_IS_NULL(string_result)) {
STRING *encoding;
GET_ATTR_encoding(INTERP, SELF, encoding);
- if (!STRING_IS_NULL(encoding) &&
- Parrot_str_equal(INTERP, encoding,
- Parrot_str_new_constant(INTERP, "utf8")))
+ if (encoding_is_utf8(INTERP, encoding))
string_result = string_make(INTERP, "", 0, "unicode", 0);
else
string_result = Parrot_str_new_constant(INTERP, "");
@@ -432,9 +458,9 @@
METHOD buffer_type(STRING *new_type :optional, INTVAL got_type :opt_flag) {
INTVAL flags;
- STRING * const nobuffer_string = Parrot_str_new_constant(INTERP, "unbuffered");
- STRING * const linebuffer_string = Parrot_str_new_constant(INTERP, "line-buffered");
- STRING * const fullbuffer_string = Parrot_str_new_constant(INTERP, "full-buffered");
+ STRING * const nobuffer_string = CONST_STRING(INTERP, "unbuffered");
+ STRING * const linebuffer_string = CONST_STRING(INTERP, "line-buffered");
+ STRING * const fullbuffer_string = CONST_STRING(INTERP, "full-buffered");
GET_ATTR_flags(INTERP, SELF, flags);
More information about the parrot-commits
mailing list