Resolves: tdf#149665 Strip first ' also for multiple '' if following is numeric

... and prepend accordingly when editing content.

Change-Id: I9b35c4e370323966400e8e7ef3bce95026052f10
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136837
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 019a8b5..91d5c4eaef 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -2078,14 +2078,25 @@ bool ScColumn::ParseString(
        bool bNumeric = false;
        if (aParam.mbHandleApostrophe)
        {
            // Cell format is not 'Text', and the first char
            // is an apostrophe. Check if the input is considered a number.
            OUString aTest = rString.copy(1);
            double fTest;
            bNumeric = aParam.mpNumFormatter->IsNumberFormat(aTest, nIndex, fTest);
            if (bNumeric)
                // This is a number. Strip out the first char.
                rCell.set(rPool.intern(aTest));
            // Cell format is not 'Text', and the first char is an apostrophe.
            // Check if the input is considered a number with all leading
            // apostrophes removed. All because ''1 should produce '1 not ''1,
            // thus '''1 be ''1 and so on.
            // NOTE: this corresponds with sc/source/ui/view/tabvwsha.cxx
            // ScTabViewShell::UpdateInputHandler() prepending an apostrophe if
            // necessary.
            sal_Int32 i = 1;
            while (i < rString.getLength() && rString[i] == '\'')
                ++i;
            if (i < rString.getLength())
            {
                OUString aTest = rString.copy(i);
                double fTest;
                bNumeric = aParam.mpNumFormatter->IsNumberFormat(aTest, nIndex, fTest);
                if (bNumeric)
                    // This is a number. Strip out the first apostrophe.
                    rCell.set(rPool.intern(rString.copy(1)));
            }
        }
        if (!bNumeric)
            // This is normal text. Take it as-is.
diff --git a/sc/source/ui/view/tabvwsha.cxx b/sc/source/ui/view/tabvwsha.cxx
index f559732..67cd905 100644
--- a/sc/source/ui/view/tabvwsha.cxx
+++ b/sc/source/ui/view/tabvwsha.cxx
@@ -722,11 +722,19 @@ void ScTabViewShell::UpdateInputHandler( bool bForce /* = sal_False */, bool bSt
                aString = ScCellFormat::GetInputString( rCell, nNumFmt, *pFormatter, rDoc );
                if (rCell.getType() == CELLTYPE_STRING)
                {
                    sal_Int32 i = 0;
                    while (i < aString.getLength() && aString[i] == '\'')
                        ++i;
                    OUString aTest((i && i < aString.getLength()) ? aString.copy(i) : aString);
                    // Put a ' in front if necessary, so that the string is not
                    // unintentionally interpreted as a number, and to show the
                    // user that it is a string (#35060#).
                    //! also for numberformat "Text"? -> then remove when editing
                    if ( pFormatter->IsNumberFormat(aString, nNumFmt, o3tl::temporary(double())) )
                    // NOTE: this corresponds with
                    // sc/source/core/data/column3.cxx ScColumn::ParseString()
                    // removing one apostrophe also for multiple consecutive
                    // apostrophes.
                    // For number format 'Text' this never results in numeric.
                    if (pFormatter->IsNumberFormat(aTest, nNumFmt, o3tl::temporary(double())))
                        aString = "'" + aString;
                }
            }