summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorWinfried Donkers <winfrieddonkers@libreoffice.org>2017-11-16 16:40:25 +0100
committerEike Rathke <erack@redhat.com>2017-11-24 21:10:37 +0100
commit09455734727daa3774158795febd910b33b1d784 (patch)
tree4d89e70c402e0a3214ec8b7d0caea60bb78e3f72 /sc
parente78f508997f9384518c2dd1a005c5306ccd24783 (diff)
tdf#97198 Make Calc function RIGHT work with Unicode non-BMP characters.
Change-Id: I775bc50d8e5948a2af9efb77dcea9d7cae7293d5 Reviewed-on: https://gerrit.libreoffice.org/44834 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/qa/unit/data/functions/text/fods/right.fods112
-rw-r--r--sc/source/core/tool/interpr1.cxx26
2 files changed, 108 insertions, 30 deletions
diff --git a/sc/qa/unit/data/functions/text/fods/right.fods b/sc/qa/unit/data/functions/text/fods/right.fods
index 9f4b97f1f8b3..fff9ffc855cc 100644
--- a/sc/qa/unit/data/functions/text/fods/right.fods
+++ b/sc/qa/unit/data/functions/text/fods/right.fods
@@ -1251,9 +1251,12 @@
<table:table-cell table:style-name="ce17" office:value-type="string" calcext:value-type="string">
<text:p>un</text:p>
</table:table-cell>
+ <table:table-cell table:style-name="ce49" table:formula="of:=[.A11]=[.B11]" office:value-type="boolean" office:boolean-value="true" calcext:value-type="boolean">
+ <text:p>TRUE</text:p>
+ </table:table-cell>
<table:table-cell table:style-name="ce29"/>
<table:table-cell table:style-name="ce11"/>
- <table:table-cell table:number-columns-repeated="4"/>
+ <table:table-cell table:number-columns-repeated="3"/>
<table:table-cell office:value-type="string" calcext:value-type="string">
<text:p>b</text:p>
</table:table-cell>
@@ -1282,55 +1285,110 @@
</table:table-cell>
</table:table-row>
<table:table-row table:style-name="ro5">
- <table:table-cell table:style-name="ce14"/>
- <table:table-cell table:style-name="ce17"/>
- <table:table-cell table:style-name="ce29"/>
- <table:table-cell table:style-name="ce11"/>
- <table:table-cell table:number-columns-repeated="4"/>
+ <table:table-cell table:style-name="ce14" table:formula="of:=RIGHT(&quot;ab😂de𝔖gh𝕬𝖈𝖍𝖙𝖚𝖓𝖌!&quot;;11)" office:value-type="string" office:string-value="𝔖gh𝕬𝖈𝖍𝖙𝖚𝖓𝖌!" calcext:value-type="string">
+ <text:p>𝔖gh𝕬𝖈𝖍𝖙𝖚𝖓𝖌!</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce41" office:value-type="string" calcext:value-type="string">
+ <text:p>𝔖gh𝕬𝖈𝖍𝖙𝖚𝖓𝖌!</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce45" table:formula="of:=[.A12]=[.B12]" office:value-type="boolean" office:boolean-value="true" calcext:value-type="boolean">
+ <text:p>TRUE</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce11" table:formula="of:=FORMULA([.A12])" office:value-type="string" office:string-value="=RIGHT(&quot;ab😂de𝔖gh𝕬𝖈𝖍𝖙𝖚𝖓𝖌!&quot;;11)" calcext:value-type="string">
+ <text:p>=RIGHT(&quot;ab😂de𝔖gh𝕬𝖈𝖍𝖙𝖚𝖓𝖌!&quot;;11)</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="string" calcext:value-type="string">
+ <text:p>Excel 2016 returns 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>c</text:p>
</table:table-cell>
<table:table-cell table:number-columns-repeated="22"/>
</table:table-row>
<table:table-row table:style-name="ro5">
- <table:table-cell table:style-name="ce14"/>
- <table:table-cell table:style-name="ce17"/>
- <table:table-cell table:style-name="ce29"/>
- <table:table-cell table:style-name="ce11"/>
- <table:table-cell table:number-columns-repeated="4"/>
+ <table:table-cell table:style-name="ce14" table:formula="of:=RIGHT(&quot;ab😂&quot;;2)" office:value-type="string" office:string-value="b😂" calcext:value-type="string">
+ <text:p>b😂</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce41" office:value-type="string" calcext:value-type="string">
+ <text:p>b😂</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce46" table:formula="of:=[.A13]=[.B13]" office:value-type="boolean" office:boolean-value="true" calcext:value-type="boolean">
+ <text:p>TRUE</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce11" table:formula="of:=FORMULA([.A13])" office:value-type="string" office:string-value="=RIGHT(&quot;ab😂&quot;;2)" calcext:value-type="string">
+ <text:p>=RIGHT(&quot;ab😂&quot;;2)</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="string" calcext:value-type="string">
+ <text:p>Excel 2016 returns 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>d</text:p>
</table:table-cell>
<table:table-cell table:number-columns-repeated="22"/>
</table:table-row>
<table:table-row table:style-name="ro5">
- <table:table-cell table:style-name="ce14"/>
- <table:table-cell table:style-name="ce17"/>
- <table:table-cell table:style-name="ce29"/>
- <table:table-cell table:style-name="ce11"/>
- <table:table-cell table:number-columns-repeated="4"/>
+ <table:table-cell table:style-name="ce14" table:formula="of:=RIGHT(&quot;&quot;&quot;𧌒𧀬&quot;&quot;&quot;;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="ce41" office:value-type="string" calcext:value-type="string">
+ <text:p>𧀬&quot;</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce47" table:formula="of:=[.A14]=[.B14]" office:value-type="boolean" office:boolean-value="true" calcext:value-type="boolean">
+ <text:p>TRUE</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce11" table:formula="of:=FORMULA([.A14])" office:value-type="string" office:string-value="=RIGHT(&quot;&quot;&quot;𧌒𧀬&quot;&quot;&quot;;2)" calcext:value-type="string">
+ <text:p>=RIGHT(&quot;&quot;&quot;𧌒𧀬&quot;&quot;&quot;;2)</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="string" calcext:value-type="string">
+ <text:p>Excel 2016 returns 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>E</text:p>
</table:table-cell>
<table:table-cell table:number-columns-repeated="22"/>
</table:table-row>
<table:table-row table:style-name="ro5">
- <table:table-cell table:style-name="ce14"/>
- <table:table-cell table:style-name="ce17"/>
- <table:table-cell table:style-name="ce29"/>
- <table:table-cell table:style-name="ce11"/>
- <table:table-cell table:number-columns-repeated="4"/>
+ <table:table-cell table:style-name="ce14" table:formula="of:=RIGHT(&quot;&quot;&quot;üë&quot;&quot;&quot;;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="ce41" office:value-type="string" calcext:value-type="string">
+ <text:p>̈&quot;</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce48" table:formula="of:=[.A15]=[.B15]" office:value-type="boolean" office:boolean-value="true" calcext:value-type="boolean">
+ <text:p>TRUE</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce11" table:formula="of:=FORMULA([.A15])" office:value-type="string" office:string-value="=RIGHT(&quot;&quot;&quot;üë&quot;&quot;&quot;;2)" calcext:value-type="string">
+ <text:p>=RIGHT(&quot;&quot;&quot;üë&quot;&quot;&quot;;2)</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="string" calcext:value-type="string">
+ <text:p>Excel 2016 returns 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>f</text:p>
</table:table-cell>
<table:table-cell table:number-columns-repeated="22"/>
</table:table-row>
<table:table-row table:style-name="ro5">
- <table:table-cell table:style-name="ce14"/>
- <table:table-cell table:style-name="ce17"/>
- <table:table-cell table:style-name="ce29"/>
- <table:table-cell table:style-name="ce11"/>
- <table:table-cell table:number-columns-repeated="4"/>
+ <table:table-cell table:style-name="ce14" table:formula="of:=RIGHT(&quot;𝕬𝖈𝖍𝖙𝖚𝖓𝖌!&quot;;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="ce41" office:value-type="string" calcext:value-type="string">
+ <text:p>𝖚𝖓𝖌!</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce49" table:formula="of:=[.A16]=[.B16]" office:value-type="boolean" office:boolean-value="true" calcext:value-type="boolean">
+ <text:p>TRUE</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce11" table:formula="of:=FORMULA([.A16])" office:value-type="string" office:string-value="=RIGHT(&quot;𝕬𝖈𝖍𝖙𝖚𝖓𝖌!&quot;;4)" calcext:value-type="string">
+ <text:p>=RIGHT(&quot;𝕬𝖈𝖍𝖙𝖚𝖓𝖌!&quot;;4)</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="string" calcext:value-type="string">
+ <text:p>Excel 2016 returns 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>g</text:p>
</table:table-cell>
@@ -1488,4 +1546,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 d53c00f9fcd7..2f2955b52927 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -8867,9 +8867,29 @@ void ScInterpreter::ScRight()
else
n = 1;
OUString aStr = GetString().getString();
- if( n < aStr.getLength() )
- aStr = aStr.copy( aStr.getLength() - n );
- PushString( aStr );
+ sal_Int32 nLen = aStr.getLength();
+ sal_Int32 nIdx = 0;
+ sal_Int32 nCnt = 0;
+ while ( nIdx < nLen )
+ {
+ aStr.iterateCodePoints( &nIdx );
+ ++nCnt;
+ }
+ if ( nCnt <= n )
+ PushString( aStr );
+ else
+ {
+ sal_Int32 nCLen = nCnt;
+ nIdx = 0;
+ nCnt = 0;
+ while ( nIdx < nLen && n < ( nCLen - nCnt ) )
+ {
+ aStr.iterateCodePoints( &nIdx );
+ ++nCnt;
+ }
+ aStr = aStr.copy( nIdx, nLen - nIdx );
+ PushString( aStr );
+ }
}
}