Author: damjan
Date: Mon Apr  4 04:11:07 2016
New Revision: 1737624

URL: http://svn.apache.org/viewvc?rev=1737624&view=rev
Log:
#i126901# CSV import: values with + or - followed by thousand separator and
3 digits (eg. +,123) are imported as a number

Do not allow numbers parsed from CVS files when "Detect special numbers" is
off, to contain thousand separators before digits, even if after a +/- sign
(eg. -,123 or +,789). Treat these as strings instead.

Also added unit tests for this and exported the ScStringUtil class so it
can be tested.

Patch by: me


Added:
    openoffice/trunk/main/sc/test/
    openoffice/trunk/main/sc/test/main.cxx
    openoffice/trunk/main/sc/test/makefile.mk
    openoffice/trunk/main/sc/test/stringutiltests.cxx
Modified:
    openoffice/trunk/main/sc/inc/stringutil.hxx
    openoffice/trunk/main/sc/prj/build.lst
    openoffice/trunk/main/sc/source/core/tool/stringutil.cxx

Modified: openoffice/trunk/main/sc/inc/stringutil.hxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sc/inc/stringutil.hxx?rev=1737624&r1=1737623&r2=1737624&view=diff
==============================================================================
--- openoffice/trunk/main/sc/inc/stringutil.hxx (original)
+++ openoffice/trunk/main/sc/inc/stringutil.hxx Mon Apr  4 04:11:07 2016
@@ -25,8 +25,9 @@
 #define SC_STRINGUTIL_HXX
 
 #include "rtl/ustring.hxx"
+#include "scdllapi.h"
 
-class ScStringUtil
+class SC_DLLPUBLIC ScStringUtil
 {
 public:
     /** 

Modified: openoffice/trunk/main/sc/prj/build.lst
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sc/prj/build.lst?rev=1737624&r1=1737623&r2=1737624&view=diff
==============================================================================
--- openoffice/trunk/main/sc/prj/build.lst (original)
+++ openoffice/trunk/main/sc/prj/build.lst Mon Apr  4 04:11:07 2016
@@ -48,6 +48,7 @@ sc    sc\addin\datefunc                                       
nmake   -       all     sc_
 sc     sc\addin\rot13                                          nmake   -       
all     sc_adrot sc_add sc_sdi sc_inc NULL
 sc     sc\addin\util                                           nmake   -       
all     sc_adutil sc_addfu sc_adrot sc_sdi sc_inc NULL
 sc     sc\util                                                 nmake   -       
all     sc_util sc_addfu sc_adrot sc_adutil sc_app sc_attr sc_cctrl sc_cosrc 
sc_data sc_dbgui sc_dif sc_docsh sc_drfnc sc_excel sc_form sc_html sc_lotus 
sc_qpro sc_misc sc_name sc_nvipi sc_opt sc_page sc_rtf sc_scalc sc_style 
sc_tool sc_uisrc sc_sidebar sc_undo sc_unobj sc_view sc_xcl97 sc_xml sc_acc 
sc_ftools sc_inc sc_vba NULL
+sc     sc\test                                                 nmake   -       
all     sc_test sc_util NULL
 
 # remarked due to the fact, key press is need in this test.
 # sc      sc\qa\complex\calcPreview                               nmake   -    
   all     qa_calcpreview   NULL

Modified: openoffice/trunk/main/sc/source/core/tool/stringutil.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sc/source/core/tool/stringutil.cxx?rev=1737624&r1=1737623&r2=1737624&view=diff
==============================================================================
--- openoffice/trunk/main/sc/source/core/tool/stringutil.cxx (original)
+++ openoffice/trunk/main/sc/source/core/tool/stringutil.cxx Mon Apr  4 
04:11:07 2016
@@ -45,6 +45,7 @@ bool ScStringUtil::parseSimpleNumber(
     const sal_Unicode* p = rStr.getStr();
     sal_Int32 nPosDSep = -1, nPosGSep = -1;
     sal_uInt32 nDigitCount = 0;
+    bool haveSeenDigit = false;
 
     for (sal_Int32 i = 0; i < n; ++i)
     {
@@ -57,6 +58,7 @@ bool ScStringUtil::parseSimpleNumber(
         {
             // this is a digit.
             aBuf.append(c);
+            haveSeenDigit = true;
             ++nDigitCount;
         }
         else if (c == dsep)
@@ -81,8 +83,8 @@ bool ScStringUtil::parseSimpleNumber(
         {
             // this is a group (thousand) separator.
 
-            if (i == 0)
-                // not allowed as the first character.
+            if (!haveSeenDigit)
+                // not allowed before digits.
                 return false;
 
             if (nPosDSep >= 0)

Added: openoffice/trunk/main/sc/test/main.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sc/test/main.cxx?rev=1737624&view=auto
==============================================================================
--- openoffice/trunk/main/sc/test/main.cxx (added)
+++ openoffice/trunk/main/sc/test/main.cxx Mon Apr  4 04:11:07 2016
@@ -0,0 +1,30 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+#include "precompiled_sc.hxx"
+
+#include "gtest/gtest.h"
+
+int main(int argc, char **argv)
+{
+    ::testing::InitGoogleTest(&argc, argv);
+    return RUN_ALL_TESTS();
+}

Added: openoffice/trunk/main/sc/test/makefile.mk
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sc/test/makefile.mk?rev=1737624&view=auto
==============================================================================
--- openoffice/trunk/main/sc/test/makefile.mk (added)
+++ openoffice/trunk/main/sc/test/makefile.mk Mon Apr  4 04:11:07 2016
@@ -0,0 +1,68 @@
+#**************************************************************
+#  
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#  
+#    http://www.apache.org/licenses/LICENSE-2.0
+#  
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+#  
+#**************************************************************
+
+
+
+PRJ=..
+
+PRJNAME=sc
+TARGET=tests
+
+ENABLE_EXCEPTIONS=TRUE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE :  settings.mk
+
+.IF "$(ENABLE_UNIT_TESTS)" != "YES"
+
+all:
+       @echo "unit tests are disabled. Nothing do do."
+
+.ELSE
+
+
+# --- Common ----------------------------------------------------------
+
+APP1OBJS=  \
+       $(SLO)$/main.obj           \
+       $(SLO)$/stringutiltests.obj     
+
+APP1TARGET= sc_tests
+APP1STDLIBS= \
+                               $(ISCLIB) \
+                               $(SALLIB) \
+                               $(GTESTLIB)
+
+APP1RPATH = NONE
+APP1TEST = enabled
+
+# END ------------------------------------------------------------------
+
+# --- Targets ------------------------------------------------------
+
+.ENDIF # "$(ENABLE_UNIT_TESTS)" != "YES"
+
+.INCLUDE : target.mk
+
+.IF "$(verbose)"!="" || "$(VERBOSE)"!=""
+CDEFS+= -DVERBOSE
+.ENDIF

Added: openoffice/trunk/main/sc/test/stringutiltests.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sc/test/stringutiltests.cxx?rev=1737624&view=auto
==============================================================================
--- openoffice/trunk/main/sc/test/stringutiltests.cxx (added)
+++ openoffice/trunk/main/sc/test/stringutiltests.cxx Mon Apr  4 04:11:07 2016
@@ -0,0 +1,40 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+#include "precompiled_sc.hxx"
+
+#include "gtest/gtest.h"
+
+#include "stringutil.hxx"
+
+
+namespace
+{
+
+TEST(StringUtilsTest, TestSignThenThousandSeparator)
+{
+    ScStringUtil stringUtil;
+    double doubleValue;
+    
EXPECT_FALSE(stringUtil.parseSimpleNumber(::rtl::OUString::createFromAscii("+,123"),
 sal_Unicode('.'), sal_Unicode(','), doubleValue));
+    
EXPECT_FALSE(stringUtil.parseSimpleNumber(::rtl::OUString::createFromAscii("-,123"),
 sal_Unicode('.'), sal_Unicode(','), doubleValue));
+}
+
+}


Reply via email to