Commit ec39a33e authored by Nick Wellnhofer's avatar Nick Wellnhofer

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.
parent de1fca61
......@@ -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);
}
......
<?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>
<?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>
<?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>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment