1. Shlomi Fish
  2. perl-XML-LibXML

Commits

ph...@9ae0c189-cd1f-4510-a509-f4891f5cf20d  committed 25881cd

Log: Modified Files:
perl-libxml-mm.c
o some cleanups

  • Participants
  • Parent commits 3077f5f
  • Branches default

Comments (0)

Files changed (1)

File perl-libxml-mm.c

View file
         }
 
         len = xmlStrlen( string );
+        retval = newSVpvn( (const char *)string, xmlStrlen(string) );
+   
         if ( enc == XML_CHAR_ENCODING_UTF8 ) {
             /* create an UTF8 string. */       
-            xs_warn("C2Sv: set UTF8 string\n");
-            /* create the SV */
-            /* string[len] = 0; */
-
-            retval = NEWSV(0, len+1); 
-            sv_setpvn(retval, (const char*) string, len );
 #ifdef HAVE_UTF8
             xs_warn("C2Sv: set UTF8-SV-flag\n");
             SvUTF8_on(retval);
 #endif            
         }
-        else {
-            /* just create an ordinary string. */
-            xs_warn("C2Sv: set ordinary string\n");
-            retval = newSVpvn( (const char *)string, xmlStrlen(string) );
-        }
     }
 
     return retval;
     if ( refnode != NULL ) {
         xmlDocPtr real_doc = refnode->doc;
         if ( real_doc != NULL && real_doc->encoding != NULL ) {
+            xs_warn( " encode node !!" );
+            /* The following statement is to handle bad
+               values set by XML::LibXSLT */
+            if ( PmmNodeEncoding(real_doc) == XML_CHAR_ENCODING_NONE ) {
+                PmmNodeEncoding(real_doc) = XML_CHAR_ENCODING_UTF8;
+            }
             xmlChar * decoded = PmmFastDecodeString( PmmNodeEncoding(real_doc) ,
                                                      (const xmlChar *)string,
                                                      (const xmlChar*)real_doc->encoding);
+            xs_warn( "push decoded string into SV" );
             len = xmlStrlen( decoded );
+            retval = newSVpvn( (const char *)decoded, len );
+            xmlFree( decoded );
+
             if ( PmmNodeEncoding( real_doc ) == XML_CHAR_ENCODING_UTF8 ) {
-		 /* most probably true, since libxml2 always 
-                  * sets doc->charset to UTF8, see tree.c:
-                  *
-		  * The in memory encoding is always UTF8
-		  * This field will never change and would
-		  * be obsolete if not for binary compatibility.
-		  */
-                /* create an UTF8 string. */       
-                xs_warn("nodeC2Sv: set UTF8 string\n");
-                /* create the SV */
-                /* warn( "string is %s\n", string ); */
-
-                retval = newSVpvn( (const char *)decoded, len );
+                /* most probably true, since libxml2 always 
+                 * sets doc->charset to UTF8, see tree.c:
+                 *
+                 * The in memory encoding is always UTF8
+                 * This field will never change and would
+                 * be obsolete if not for binary compatibility.
+                 */
 #ifdef HAVE_UTF8
                 xs_warn("nodeC2Sv: set UTF8-SV-flag\n");
                 SvUTF8_on(retval);
 #endif            
             }
-            else {
-                /* just create an ordinary string. */
-                xs_warn("nodeC2Sv: set ordinary string\n");
-                retval = newSVpvn( (const char *)decoded, len );
-            }
-
-            /* retval = C2Sv( decoded, real_doc->encoding ); */
-            xmlFree( decoded );
-        }
-        else {
-            retval = newSVpvn( (const char *)string, xmlStrlen(string) );
+           
+            return retval;
         }
     }
-    else {
-        retval = newSVpvn( (const char *)string, xmlStrlen(string) );
-    }
 
-    return retval;
+    return C2Sv(string, NULL );
 }
 
 xmlChar *
 #endif
 		    {
                         xs_warn( "nodeSv2C:     domEncodeString!\n" );
-                      /*  if ( string == NULL || *string == 0 ) warn("string is empty" ); */
+                        /*  if ( string == NULL || *string == 0 ) warn("string is empty" ); */
+                        /* The following statement is to handle bad
+                           values set by XML::LibXSLT */
+                        if ( PmmNodeEncoding(real_dom) == XML_CHAR_ENCODING_NONE ) {
+                            PmmNodeEncoding(real_dom) = XML_CHAR_ENCODING_UTF8;
+                        }
+
                         ts= PmmFastEncodeString( PmmNodeEncoding(real_dom),
                                                  string,
                                                  (const xmlChar*)real_dom->encoding );