summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWinfried Donkers <winfrieddonkers@libreoffice.org>2017-11-13 15:43:00 +0100
committerEike Rathke <erack@redhat.com>2017-11-24 21:14:37 +0100
commit4e3530b4f870e0470c23ae89cdb8b9a09af54d59 (patch)
treec041c08b39ff63f105c5abdbce6eb1bad86a2f05
parent78b7e5f76e72647e0cab662ad2c9342d4538704f (diff)
tdf#97198 Make Calc function LEFT work with Unicode non-BMP characters
Change-Id: I66d24dd962f824079fd0aea2827bd5b975ffe698 Reviewed-on: https://gerrit.libreoffice.org/44684 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Eike Rathke <erack@redhat.com>
-rw-r--r--sc/qa/unit/data/functions/text/fods/left.fods88
-rw-r--r--sc/source/core/tool/interpr1.cxx7
2 files changed, 92 insertions, 3 deletions
diff --git a/sc/qa/unit/data/functions/text/fods/left.fods b/sc/qa/unit/data/functions/text/fods/left.fods
index 535eff455432..45d659aab04e 100644
--- a/sc/qa/unit/data/functions/text/fods/left.fods
+++ b/sc/qa/unit/data/functions/text/fods/left.fods
@@ -1152,6 +1152,92 @@
<table:table-cell table:style-name="ce17"/>
<table:table-cell table:number-columns-repeated="4"/>
</table:table-row>
+ <table:table-row table:style-name="ro5">
+ <table:table-cell table:style-name="ce14" table:formula="of:=LEFT([.I11];4)" office:value-type="string" office:string-value="abπŸ˜‚d" calcext:value-type="string">
+ <text:p>abπŸ˜‚d</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce17" office:value-type="string" calcext:value-type="string">
+ <text:p>abπŸ˜‚d</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce38" table:formula="of:=[.A11]=[.B11]" office:value-type="boolean" office:boolean-value="true" calcext:value-type="boolean">
+ <text:p>WAAR</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce11" table:formula="of:=FORMULA([.A11])" office:value-type="string" office:string-value="=LEFT(I11;4)" calcext:value-type="string">
+ <text:p>=LEFT(I11;4)</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="string" calcext:value-type="string">
+ <text:p>Excel 2016 returns the same result</text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="3"/>
+ <table:table-cell office:value-type="string" calcext:value-type="string"><text:p>ab<text:span text:style-name="T1">πŸ˜‚de𝔖ghπ•¬π–ˆπ–π–™π–šπ–“π–Œ!</text:span></text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="4"/>
+ </table:table-row>
+ <table:table-row table:style-name="ro6">
+ <table:table-cell table:style-name="ce14" table:formula="of:=LEFT([.I12];2)" office:value-type="string" office:string-value="&quot;π§Œ’" calcext:value-type="string">
+ <text:p>&quot;π§Œ’</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce17" office:value-type="string" calcext:value-type="string">
+ <text:p>&quot;π§Œ’</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce39" table:formula="of:=[.A12]=[.B12]" office:value-type="boolean" office:boolean-value="true" calcext:value-type="boolean">
+ <text:p>WAAR</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce11" table:formula="of:=FORMULA([.A12])" office:value-type="string" office:string-value="=LEFT(I12;2)" calcext:value-type="string">
+ <text:p>=LEFT(I12;2)</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="string" calcext:value-type="string">
+ <text:p>Excel 2016 returns the same result</text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="3"/>
+ <table:table-cell table:style-name="ce44" office:value-type="string" calcext:value-type="string"><text:p><text:span text:style-name="T2">&quot;</text:span><text:span text:style-name="T3">π§Œ’π§€¬</text:span><text:span text:style-name="T4">&quot;</text:span></text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="4"/>
+ </table:table-row>
+ <table:table-row table:style-name="ro3">
+ <table:table-cell table:style-name="ce14" table:formula="of:=LEFT([.I13];2)" office:value-type="string" office:string-value="&quot;u" calcext:value-type="string">
+ <text:p>&quot;u</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce17" office:value-type="string" calcext:value-type="string">
+ <text:p>&quot;u</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce40" table:formula="of:=[.A13]=[.B13]" office:value-type="boolean" office:boolean-value="true" calcext:value-type="boolean">
+ <text:p>WAAR</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce11" table:formula="of:=FORMULA([.A13])" office:value-type="string" office:string-value="=LEFT(I13;2)" calcext:value-type="string">
+ <text:p>=LEFT(I13;2)</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="string" calcext:value-type="string">
+ <text:p>Excel 2016 returns the same result</text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="3"/>
+ <table:table-cell table:style-name="ce45" office:value-type="string" calcext:value-type="string">
+ <text:p>&quot;üë&quot;</text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="4"/>
+ </table:table-row>
+ <table:table-row table:style-name="ro5">
+ <table:table-cell table:style-name="ce14" table:formula="of:=LEFT([.I14];4)" office:value-type="string" office:string-value="π•¬π–ˆπ–π–™" calcext:value-type="string">
+ <text:p>π•¬π–ˆπ–π–™</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce17" office:value-type="string" calcext:value-type="string">
+ <text:p>π•¬π–ˆπ–π–™</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce41" table:formula="of:=[.A14]=[.B14]" office:value-type="boolean" office:boolean-value="true" calcext:value-type="boolean">
+ <text:p>WAAR</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce11" table:formula="of:=FORMULA([.A14])" office:value-type="string" office:string-value="=LEFT(I14;4)" calcext:value-type="string">
+ <text:p>=LEFT(I14;4)</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="string" calcext:value-type="string">
+ <text:p>Excel 2016 returns the same result</text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="3"/>
+ <table:table-cell table:style-name="ce46" office:value-type="string" calcext:value-type="string">
+ <text:p>π•¬π–ˆπ–π–™π–šπ–“π–Œ!</text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="4"/>
+ </table:table-row>
<table:table-row table:style-name="ro5" table:number-rows-repeated="27">
<table:table-cell table:style-name="ce14"/>
<table:table-cell table:style-name="ce17"/>
@@ -1195,4 +1281,4 @@
</table:named-expressions>
</office:spreadsheet>
</office:body>
-</office:document> \ No newline at end of file
+</office:document>
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 88b1fd43759d..2895c93f2a2e 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -8579,8 +8579,11 @@ void ScInterpreter::ScLeft()
else
n = 1;
OUString aStr = GetString().getString();
- n = std::min(n, aStr.getLength());
- aStr = aStr.copy( 0, n );
+ sal_Int32 nIdx = 0;
+ sal_Int32 nCnt = 0;
+ while ( nIdx < aStr.getLength() && n > nCnt++ )
+ aStr.iterateCodePoints( &nIdx );
+ aStr = aStr.copy( 0, nIdx );
PushString( aStr );
}
}