summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWinfried Donkers <winfrieddonkers@libreoffice.org>2017-11-21 16:08:32 +0100
committerEike Rathke <erack@redhat.com>2017-11-24 21:10:16 +0100
commite78f508997f9384518c2dd1a005c5306ccd24783 (patch)
tree8392c42f922e228eb522582d256156f50fb193ce
parent0b202dbdc8b4eae8bcf083c7850480d4c6bcdb24 (diff)
tdf#97198 Make calc function MID work with Unicode non-BMP characters.
Change-Id: Ic86344495490d6ca942f9fd2752874da22ef531f Reviewed-on: https://gerrit.libreoffice.org/45040 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Eike Rathke <erack@redhat.com>
-rw-r--r--sc/qa/unit/data/functions/text/fods/mid.fods175
-rw-r--r--sc/source/core/tool/interpr1.cxx28
2 files changed, 166 insertions, 37 deletions
diff --git a/sc/qa/unit/data/functions/text/fods/mid.fods b/sc/qa/unit/data/functions/text/fods/mid.fods
index 56fcd55d3f27..68c7feb10299 100644
--- a/sc/qa/unit/data/functions/text/fods/mid.fods
+++ b/sc/qa/unit/data/functions/text/fods/mid.fods
@@ -1054,41 +1054,158 @@
</table:table-cell>
<table:table-cell table:number-columns-repeated="5"/>
</table:table-row>
- <table:table-row table:style-name="ro5">
- <table:table-cell/>
- <table:table-cell table:style-name="ce17"/>
- <table:table-cell table:style-name="ce27"/>
- <table:table-cell table:style-name="ce11"/>
- <table:table-cell table:number-columns-repeated="5"/>
+ <table:table-row table:style-name="ro2">
+ <table:table-cell table:formula="of:=MID([.I2];12;8)">
+ <text:p/>
+ </table:table-cell>
+ <table:table-cell table:formula="of:=MID([.J2];12;8)">
+ <text:p/>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce38" table:formula="of:=[.A6]=[.B6]" 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([.A6])" office:value-type="string" office:string-value="=MID(I2;12;8)" calcext:value-type="string">
+ <text:p>=MID(I2;12;8)</text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="7"/>
</table:table-row>
<table:table-row table:style-name="ro2">
- <table:table-cell table:style-name="ce9" table:number-columns-repeated="2"/>
- <table:table-cell table:style-name="ce27"/>
- <table:table-cell table:style-name="ce11"/>
- <table:table-cell table:number-columns-repeated="5"/>
+ <table:table-cell table:formula="of:=MID([.I2];0;3)" office:value-type="string" office:string-value="" calcext:value-type="error">
+ <text:p>Err:502</text:p>
+ </table:table-cell>
+ <table:table-cell table:formula="of:#ERR502!" office:value-type="string" office:string-value="" calcext:value-type="error">
+ <text:p>Err:502</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce39" table:formula="of:=ISERROR([.A7])" 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([.A7])" office:value-type="string" office:string-value="=MID(I2;0;3)" calcext:value-type="string">
+ <text:p>=MID(I2;0;3)</text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="7"/>
</table:table-row>
<table:table-row table:style-name="ro2">
- <table:table-cell table:number-columns-repeated="2"/>
- <table:table-cell table:style-name="ce27"/>
- <table:table-cell table:style-name="ce11"/>
- <table:table-cell table:number-columns-repeated="5"/>
+ <table:table-cell table:formula="of:=MID([.I8];[.J8];[.K8])" 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="ce35" office:value-type="string" calcext:value-type="string">
+ <text:p>bπŸ˜‚</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce40" table:formula="of:=[.A8]=[.B8]" 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([.A8])" office:value-type="string" office:string-value="=MID(I8;J8;K8)" calcext:value-type="string">
+ <text:p>=MID(I8;J8;K8)</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="string" calcext:value-type="string">
+ <text:p>result Excel 2016 is bπŸ˜‚</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>ab<text:span text:style-name="T1">πŸ˜‚de𝔖ghπ•¬π–ˆπ–π–™π–šπ–“π–Œ!</text:span></text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="2" table:style-name="ce46" office:value-type="float" office:value="2" calcext:value-type="float">
+ <text:p>2</text:p>
+ </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="ce27"/>
- <table:table-cell table:style-name="ce11"/>
- <table:table-cell table:number-columns-repeated="5"/>
+ <table:table-row table:style-name="ro2">
+ <table:table-cell table:formula="of:=MID([.I9];[.J9];[.K9])" 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="ce35" office:value-type="string" calcext:value-type="string">
+ <text:p>b</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce41" table:formula="of:=[.A9]=[.B9]" 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([.A9])" office:value-type="string" office:string-value="=MID(I9;J9;K9)" calcext:value-type="string">
+ <text:p>=MID(I9;J9;K9)</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="string" calcext:value-type="string">
+ <text:p>result Excel 2016 is b</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>abπŸ˜‚</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce46" office:value-type="float" office:value="2" calcext:value-type="float">
+ <text:p>2</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce46" office:value-type="float" office:value="1" calcext:value-type="float">
+ <text:p>1</text:p>
+ </table:table-cell>
</table:table-row>
- <table:table-row table:style-name="ro5">
- <table:table-cell table:style-name="ce16"/>
- <table:table-cell table:style-name="ce17"/>
- <table:table-cell table:style-name="ce27"/>
- <table:table-cell table:style-name="ce11"/>
- <table:table-cell table:number-columns-repeated="4"/>
- <table:table-cell table:style-name="ce17"/>
+ <table:table-row table:style-name="ro6">
+ <table:table-cell table:formula="of:=MID([.I10];[.J10];[.K10])" office:value-type="string" office:string-value="π§Œ’π§€¬" calcext:value-type="string">
+ <text:p>π§Œ’π§€¬</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce35" office:value-type="string" calcext:value-type="string">
+ <text:p>π§Œ’π§€¬</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce42" table:formula="of:=[.A10]=[.B10]" 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([.A10])" office:value-type="string" office:string-value="=MID(I10;J10;K10)" calcext:value-type="string">
+ <text:p>=MID(I10;J10;K10)</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="string" calcext:value-type="string">
+ <text:p>result Excel 2016 is π§Œ’</text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="3"/>
+ <table:table-cell table:style-name="ce47" office:value-type="string" calcext:value-type="string"><text:p>&quot;<text:span text:style-name="T2">π§Œ’π§€¬</text:span>&quot;</text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="2" table:style-name="ce46" office:value-type="float" office:value="2" calcext:value-type="float">
+ <text:p>2</text:p>
+ </table:table-cell>
+ </table:table-row>
+ <table:table-row table:style-name="ro3">
+ <table:table-cell table:formula="of:=MID([.I11];[.J11];[.K11])" office:value-type="string" office:string-value="ü" calcext:value-type="string">
+ <text:p>ü</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce35" office:value-type="string" calcext:value-type="string">
+ <text:p>ü</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce43" 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="ce11" table:formula="of:=FORMULA([.A11])" office:value-type="string" office:string-value="=MID(I11;J11;K11)" calcext:value-type="string">
+ <text:p>=MID(I11;J11;K11)</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="string" calcext:value-type="string">
+ <text:p>result Excel 2016 is identical</text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="3"/>
+ <table:table-cell table:style-name="ce48" office:value-type="string" calcext:value-type="string">
+ <text:p>&quot;üë&quot;</text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="2" table:style-name="ce46" office:value-type="float" office:value="2" calcext:value-type="float">
+ <text:p>2</text:p>
+ </table:table-cell>
+ </table:table-row>
+ <table:table-row table:style-name="ro2">
+ <table:table-cell table:formula="of:=MID([.I12];[.J12];[.K12])" office:value-type="string" office:string-value="π–π–™π–š" calcext:value-type="string">
+ <text:p>π–π–™π–š</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce35" office:value-type="string" calcext:value-type="string">
+ <text:p>π–π–™π–š</text:p>
+ </table:table-cell>
+ <table:table-cell table:style-name="ce44" 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="=MID(I12;J12;K12)" calcext:value-type="string">
+ <text:p>=MID(I12;J12;K12)</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="string" calcext:value-type="string">
+ <text:p>result Excel 2016 is π–ˆ</text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="3"/>
+ <table:table-cell table:style-name="ce49" office:value-type="string" calcext:value-type="string">
+ <text:p>π•¬π–ˆπ–π–™π–šπ–“π–Œ!</text:p>
+ </table:table-cell>
+ <table:table-cell table:number-columns-repeated="2" table:style-name="ce46" office:value-type="float" office:value="3" calcext:value-type="float">
+ <text:p>3</text:p>
+ </table:table-cell>
</table:table-row>
- <table:table-row table:style-name="ro5" table:number-rows-repeated="27">
+ <table:table-row table:style-name="ro5" table:number-rows-repeated="25">
<table:table-cell table:style-name="ce14"/>
<table:table-cell table:style-name="ce17"/>
<table:table-cell table:style-name="ce27"/>
@@ -1130,4 +1247,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 5bb02e6e363d..d53c00f9fcd7 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -8914,18 +8914,30 @@ void ScInterpreter::ScMid()
{
if ( MustHaveParamCount( GetByte(), 3 ) )
{
- double fCnt = GetStringPositionArgument();
- double fAnfang = GetStringPositionArgument();
+ sal_Int32 nSubLen = ( sal_Int32 )GetStringPositionArgument();
+ sal_Int32 nStart = ( sal_Int32 )GetStringPositionArgument();
OUString aStr = GetString().getString();
- if (fAnfang < 1.0 || fCnt < 0.0)
+ if ( nStart < 1 || nSubLen < 0 )
PushIllegalArgument();
else
{
- sal_Int32 nCharacters = std::min<sal_Int32>(static_cast<sal_Int32>(fCnt), aStr.getLength() - fAnfang + 1);
- OUString sRes;
- if (nCharacters > 0)
- sRes = aStr.copy(static_cast<sal_Int32>(fAnfang-1), nCharacters);
- PushString(sRes);
+ sal_Int32 nLen = aStr.getLength();
+ sal_Int32 nIdx = 0;
+ sal_Int32 nCnt = 0;
+ while ( nIdx < nLen && nStart - 1 > nCnt )
+ {
+ aStr.iterateCodePoints( &nIdx );
+ ++nCnt;
+ }
+ sal_Int32 nIdx0 = nIdx; //start position
+
+ while ( nIdx < nLen && nStart + nSubLen - 1 > nCnt )
+ {
+ aStr.iterateCodePoints( &nIdx );
+ ++nCnt;
+ }
+ aStr = aStr.copy( nIdx0, nIdx - nIdx0 );
+ PushString( aStr );
}
}
}