Author: leo
Date: Fri Nov 11 09:45:37 2005
New Revision: 9906

Modified:
   trunk/charset/iso-8859-1.c
   trunk/t/op/string_cs.t
Log:
enable inplace iso-8859-1.to_charset; test

Modified: trunk/charset/iso-8859-1.c
==============================================================================
--- trunk/charset/iso-8859-1.c  (original)
+++ trunk/charset/iso-8859-1.c  Fri Nov 11 09:45:37 2005
@@ -42,21 +42,23 @@ set_graphemes(Interp *interpreter, STRIN
 static STRING *
 to_latin1(Interp *interpreter, STRING *src, STRING *dest)
 {
-    UINTVAL offs, c;
+    UINTVAL offs, c, src_len;
     String_iter iter;
 
+    ENCODING_ITER_INIT(interpreter, src, &iter);
+    src_len = src->strlen;
     if (dest) {
-        Parrot_reallocate_string(interpreter, dest, src->strlen);
-        dest->bufused = src->strlen;
-        dest->strlen  = src->strlen;
-        dest->charset = Parrot_iso_8859_1_charset_ptr;
-        dest->encoding = Parrot_fixed_8_encoding_ptr;
+        Parrot_reallocate_string(interpreter, dest, src_len);
+        dest->strlen  = src_len;
     }
-    else
-        internal_exception(UNIMPLEMENTED,
-                "to_charset inplace for latin1 not implemented");
-    ENCODING_ITER_INIT(interpreter, src, &iter);
-    for (offs = 0; offs < src->strlen; ++offs) {
+    else {
+        /* latin1 is never bigger then source */
+        dest = src;
+    }
+    dest->bufused = src_len;
+    dest->charset = Parrot_iso_8859_1_charset_ptr;
+    dest->encoding = Parrot_fixed_8_encoding_ptr;
+    for (offs = 0; offs < src_len; ++offs) {
         c = iter.get_and_advance(interpreter, &iter);
         if (c >= 0x100) {
             EXCEPTION(LOSSY_CONVERSION, "lossy conversion to ascii");

Modified: trunk/t/op/string_cs.t
==============================================================================
--- trunk/t/op/string_cs.t      (original)
+++ trunk/t/op/string_cs.t      Fri Nov 11 09:45:37 2005
@@ -16,7 +16,7 @@ Tests charset support.
 
 =cut
 
-use Parrot::Test tests => 43;
+use Parrot::Test tests => 44;
 use Parrot::Config;
 use Test::More;
 
@@ -507,7 +507,7 @@ abcdefg
 OUTPUT
 
 SKIP: {
-  skip('no ICU lib', 12) unless $PConfig{has_icu};
+  skip('no ICU lib', 13) unless $PConfig{has_icu};
 output_is( <<'CODE', <<"OUTPUT", "unicode downcase");
     set S0, iso-8859-1:"T�TSCH"
     find_charset I0, "unicode"
@@ -522,6 +522,19 @@ CODE
 t\xc3\xb6tsch
 OUTPUT
 
+output_is( <<'CODE', <<"OUTPUT", "unicode downcase, trans_charset_s_i");
+    set S0, iso-8859-1:"T�TSCH"
+    find_charset I0, "unicode"
+    trans_charset S1, S0, I0
+    downcase S1
+    find_charset I0, "iso-8859-1"
+    trans_charset S1, I0
+    print S1
+    print "\n"
+    end
+CODE
+t\xf6tsch
+OUTPUT
 output_is( <<'CODE', <<"OUTPUT", "unicode downcase - transcharset");
     set S0, iso-8859-1:"T�TSCH"
     find_charset I0, "unicode"

Reply via email to