sc/qa/unit/data/functions/text/fods/mid.fods | 175 ++++++++++++++++++++++----- sc/source/core/tool/interpr1.cxx | 28 +++- 2 files changed, 166 insertions(+), 37 deletions(-)
New commits: commit e78f508997f9384518c2dd1a005c5306ccd24783 Author: Winfried Donkers <winfrieddonk...@libreoffice.org> Date: Tue Nov 21 16:08:32 2017 +0100 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 <er...@redhat.com> Tested-by: Eike Rathke <er...@redhat.com> 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>"<text:span text:style-name="T2">ð§ð§¬</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="ro3"> + <table:table-cell table:formula="of:=MID([.I11];[.J11];[.K11])" office:value-type="string" office:string-value="uÌ" calcext:value-type="string"> + <text:p>uÌ</text:p> + </table:table-cell> + <table:table-cell table:style-name="ce35" office:value-type="string" calcext:value-type="string"> + <text:p>uÌ</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>"uÌeÌ"</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 ); } } }
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits