sc/source/core/data/column3.cxx |   27 +++++++++++++++++++--------
 sc/source/ui/view/tabvwsha.cxx  |   12 ++++++++++--
 2 files changed, 29 insertions(+), 10 deletions(-)

New commits:
commit 484448bc04edfbe22db784d2c68a679a3f98fbb9
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Tue Jul 5 18:37:54 2022 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Tue Jul 5 20:14:29 2022 +0200

    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 <er...@redhat.com>
    Tested-by: Jenkins

diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 019a8b58283a..91d5c4eaef2e 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 f559732fff74..67cd905341f0 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;
                 }
             }

Reply via email to