[libxslt] Fix str:align with UTF-8 strings



commit ec39a33e02d3b337f3f25602659a33d4b30aa31a
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Sat Oct 4 12:16:59 2014 +0200

    Fix str:align with UTF-8 strings
    
    The offset computation for left-aligned strings containing UTF-8 was
    wrong. Fixes bug #588544:
    
        https://bugzilla.gnome.org/show_bug.cgi?id=588544
    
    Also add some test cases.

 libexslt/strings.c              |    2 +-
 tests/exslt/strings/align.1.out |    8 ++++++++
 tests/exslt/strings/align.1.xml |    9 +++++++++
 tests/exslt/strings/align.1.xsl |   22 ++++++++++++++++++++++
 4 files changed, 40 insertions(+), 1 deletions(-)
---
diff --git a/libexslt/strings.c b/libexslt/strings.c
index 3c702ad..f5f2d3c 100644
--- a/libexslt/strings.c
+++ b/libexslt/strings.c
@@ -447,7 +447,7 @@ exsltStrAlignFunction (xmlXPathParserContextPtr ctxt, int nargs) {
        } else {
            int str_s;
 
-           str_s = xmlStrlen (str);
+           str_s = xmlUTF8Strsize(padding, str_l);
            ret = xmlStrdup (str);
            ret = xmlStrcat (ret, padding + str_s);
        }
diff --git a/tests/exslt/strings/align.1.out b/tests/exslt/strings/align.1.out
new file mode 100644
index 0000000..0b639e5
--- /dev/null
+++ b/tests/exslt/strings/align.1.out
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<test-results>
+  <test-result>déja vu––––––</test-result>
+  <test-result>–––déja vu–––</test-result>
+  <test-result>––––––déja vu</test-result>
+  <test-result>déja</test-result>
+  <test-result>déja vu</test-result>
+</test-results>
diff --git a/tests/exslt/strings/align.1.xml b/tests/exslt/strings/align.1.xml
new file mode 100644
index 0000000..f32b2dc
--- /dev/null
+++ b/tests/exslt/strings/align.1.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<test-cases>
+    <test-case string="déja vu" padding="–––––––––––––" alignment="left"/>
+    <test-case string="déja vu" padding="–––––––––––––" alignment="center"/>
+    <test-case string="déja vu" padding="–––––––––––––" alignment="right"/>
+    <test-case string="déja vu" padding="––––" alignment="left"/>
+    <test-case string="déja vu" padding="–––––––" alignment="left"/>
+</test-cases>
+
diff --git a/tests/exslt/strings/align.1.xsl b/tests/exslt/strings/align.1.xsl
new file mode 100644
index 0000000..3de033d
--- /dev/null
+++ b/tests/exslt/strings/align.1.xsl
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0"
+    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
+    xmlns:str="http://exslt.org/strings";
+    exclude-result-prefixes="str">
+
+<xsl:output indent="yes"/>
+
+<xsl:template match="test-cases">
+    <test-results>
+        <xsl:apply-templates select="test-case"/>
+    </test-results>
+</xsl:template>
+
+<xsl:template match="test-case">
+    <test-result>
+        <xsl:value-of select="str:align(@string, @padding, @alignment)"/>
+    </test-result>
+</xsl:template>
+
+</xsl:stylesheet>
+


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