* Bug #12140 fixed - csvRead fails when comma is used as decimal mark. 23/9923/3
Sylvestre Ledru [Tue, 4 Dec 2012 17:48:10 +0000 (18:48 +0100)]
Change-Id: I3c9aa62f0bb4942c601261af5949b67e0fb13f40

12 files changed:
scilab/CHANGES_5.4.X
scilab/modules/spreadsheet/help/en_US/csvRead.xml
scilab/modules/spreadsheet/help/en_US/csvTextscan.xml
scilab/modules/spreadsheet/help/ja_JP/csvRead.xml
scilab/modules/spreadsheet/src/c/csvRead.c
scilab/modules/spreadsheet/tests/nonreg_tests/bug_12140.csv [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_12140.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_12140.tst [new file with mode: 0644]
scilab/modules/spreadsheet/tests/unit_tests/csvRead.dia.ref
scilab/modules/spreadsheet/tests/unit_tests/csvRead.tst
scilab/modules/spreadsheet/tests/unit_tests/csvTextScan.dia.ref
scilab/modules/spreadsheet/tests/unit_tests/csvTextScan.tst

index 528d6fb..593157c 100644 (file)
@@ -160,6 +160,8 @@ Bug fixes
 
 * Bug #11962 fixed - event_handler may be called on wrong figure_id.
 
+* Bug #11965 fixed - Export to SVG converted texts in shapes.
+
 * Bug #11971 fixed - Canceling "Open File" action launched from icon in the
                     toolbar opened SciNotes anyway.
 
@@ -204,12 +206,12 @@ Bug fixes
 
 * Bug #12119 fixed - bar and barh had wrong x/y bounds.
 
+* Bug #12140 fixed - csvRead fails when comma is used as decimal mark.
+
 * Bug #12166 fixed - There was a bad label with drawaxis.
 
 * Bug #12179 fixed - Fix an incompatibility with MPI version of HDF5.
 
-* Bug #11965 fixed - Export to SVG converted texts in shapes.
-
 
                     Changes between version 5.3.3 and 5.4.0
                     =======================================
index 4ec6de3..243be40 100644 (file)
@@ -10,9 +10,6 @@
           xmlns:ns3="http://www.w3.org/1999/xhtml"
           xmlns:mml="http://www.w3.org/1998/Math/MathML"
           xmlns:db="http://docbook.org/ns/docbook">
-    <info>
-        <pubdate>$LastChangedDate$</pubdate>
-    </info>
     
     <refnamediv>
         <refname>csvRead</refname>
@@ -59,6 +56,7 @@
                 
                 <listitem>
                     <para>a 1-by-1 matrix of strings, the decimal used.</para>
+                    <para>If <literal>decimal</literal> is different of <literal>[]</literal> and <literal>conversion</literal> is set to <literal>string</literal>, the decimal conversion will be done.</para>
                 </listitem>
             </varlistentry>
             
@@ -229,7 +227,7 @@ filename = fullfile(TMPDIR , 'foo.csv');
 sep = ",";
 fd = mopen(filename,'wt');
 for i = 1 : size(Astr,"r")
-mfprintf(fd,"%s\n",strcat(Astr(i,:),sep));
+        mfprintf(fd,"%s\n",strcat(Astr(i,:),sep));
 end
 mclose(fd);
 // To see the file : edit(filename)
@@ -242,7 +240,7 @@ filename = fullfile(TMPDIR , 'foo.csv');
 sep = ";";
 fd = mopen(filename,'wt');
 for i = 1 : size(Astr,"r")
-mfprintf(fd,"%s\n",strcat(Astr(i,:),sep));
+        mfprintf(fd,"%s\n",strcat(Astr(i,:),sep));
 end
 mclose(fd);
 
@@ -311,7 +309,7 @@ filename = fullfile(TMPDIR , 'foo.csv');
 sep = ";";
 fd = mopen(filename,'wt');
 for i = 1 : size(Astr,"r")
-mfprintf(fd,"%s\n",strcat(Astr(i,:),sep));
+        mfprintf(fd,"%s\n",strcat(Astr(i,:),sep));
 end
 mclose(fd);
 //
@@ -406,6 +404,13 @@ csvRead(filename, [], [], "double", [], [], [5 3 7 6])
                 <revremark>
                     Function introduced. Based on the 'csv_readwrite' module. The only difference in the behavior compared to <link linkend="read_csv">read_csv</link> is that csvRead will try to convert value to double by default when read_csv will return value as string. 
                 </revremark>
+      <revision>
+        <revnumber>5.4.1</revnumber>
+        <revremark>
+          If <literal>decimal</literal> is different of <literal>[]</literal> and <literal>conversion</literal> is set to <literal>string</literal>, the decimal conversion will be done.
+          </revremark>
+      </revision>
+
             </revision>
         </revhistory>
     </refsection>
index ddb7bfa..53c7312 100644 (file)
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
- * Copyright (C) 2010-2011 - INRIA - Allan CORNET
- * Copyright (C) 2011 - INRIA - Michael Baudin
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- -->
+* Copyright (C) 2010-2011 - INRIA - Allan CORNET
+* Copyright (C) 2011 - INRIA - Michael Baudin
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+-->
 <refentry version="5.0-subset Scilab" xml:id="csvTextScan" xml:lang="en"
           xmlns="http://docbook.org/ns/docbook"
           xmlns:xlink="http://www.w3.org/1999/xlink"
           xmlns:ns3="http://www.w3.org/1999/xhtml"
           xmlns:mml="http://www.w3.org/1998/Math/MathML"
           xmlns:db="http://docbook.org/ns/docbook">
-    <refnamediv>
-        <refname>csvTextScan</refname>
-        
-        <refpurpose>Convert a comma-separated value to a matrix</refpurpose>
-    </refnamediv>
+  <refnamediv>
+    <refname>csvTextScan</refname>
     
-    <refsynopsisdiv>
-        <title>Calling Sequence</title>
-        
-        <synopsis>
-            A = csvTextScan(M)
-            A = csvTextScan(M, separator)
-            A = csvTextScan(M, separator, decimal)
-            A = csvTextScan(M, separator, decimal, conversion)
-            A = csvTextScan(M, separator, decimal, conversion, range)
-        </synopsis>
-    </refsynopsisdiv>
+    <refpurpose>Convert a comma-separated value to a matrix</refpurpose>
+  </refnamediv>
+  
+  <refsynopsisdiv>
+    <title>Calling Sequence</title>
     
-    <refsection>
-        <title>Parameters</title>
-        
-        <variablelist>
-            <varlistentry>
-                <term>M</term>
-                
-                <listitem>
-                    <para>a m-by-1 or 1-by-m matrix of strings.</para>
-                </listitem>
-            </varlistentry>
-            
-            <varlistentry>
-                <term>separator</term>
-                
-                <listitem>
-                    <para>a 1-by-1 matrix of strings, the column separator mark.</para>
-                </listitem>
-            </varlistentry>
-            
-            <varlistentry>
-                <term>decimal</term>
-                
-                <listitem>
-                    <para>a 1-by-1 matrix of strings, the decimal mark. The available
-                        values are "." or ",".
-                    </para>
-                </listitem>
-            </varlistentry>
-            
-            <varlistentry>
-                <term>conversion</term>
-                
-                <listitem>
-                    <para>a 1-by-1 matrix of strings, the type of the output
-                        <literal>A</literal>. Available values are "string" or
-                        "double".
-                    </para>
-                </listitem>
-            </varlistentry>
-            
-            <varlistentry>
-                <term>range</term>
-                
-                <listitem>
-                    <para>a 1-by-4 or 4-by-1 matrix of floating point integers, the
-                        range of rows and columns which must be read (default range=[],
-                        meaning that all the rows and columns). Specify range using the
-                        format <literal>[R1 C1 R2 C2]</literal> where (R1,C1) is the upper
-                        left corner of the data to be read and (R2,C2) is the lower right
-                        corner.
-                    </para>
-                </listitem>
-            </varlistentry>
-            
-            <varlistentry>
-                <term>A</term>
-                
-                <listitem>
-                    <para>a m-by-n matrix of strings or double.</para>
-                </listitem>
-            </varlistentry>
-        </variablelist>
-    </refsection>
+    <synopsis>
+      A = csvTextScan(M)
+      A = csvTextScan(M, separator)
+      A = csvTextScan(M, separator, decimal)
+      A = csvTextScan(M, separator, decimal, conversion)
+      A = csvTextScan(M, separator, decimal, conversion, range)
+    </synopsis>
+  </refsynopsisdiv>
+  
+  <refsection>
+    <title>Parameters</title>
     
-    <refsection>
-        <title>Description</title>
+    <variablelist>
+      <varlistentry>
+        <term>M</term>
         
-        <para>Given an ascii file with delimited fields, this function returns the
-            corresponding Scilab matrix of strings or doubles.
-        </para>
+        <listitem>
+          <para>a m-by-1 or 1-by-m matrix of strings.</para>
+        </listitem>
+      </varlistentry>
+      
+      <varlistentry>
+        <term>separator</term>
         
-        <para>
-            The <literal>csvTextScan</literal> function has the same purpose as
-            <literal>csvRead</literal>, except that <literal>csvTextScan</literal>
-            reads in a string, while <literal>csvRead</literal> reads in a
-            file.
-        </para>
+        <listitem>
+          <para>a 1-by-1 matrix of strings, the column separator mark.</para>
+        </listitem>
+      </varlistentry>
+      
+      <varlistentry>
+        <term>decimal</term>
         
-        <para>The default value of the optional input arguments are defined by the
-            <literal>csvDefault</literal> function.
-        </para>
+        <listitem>
+          <para>a 1-by-1 matrix of strings, the decimal mark. The available
+          values are "." or ",".
+          </para>
+          <para>If <literal>decimal</literal> is different of <literal>[]</literal> and <literal>conversion</literal> is set to <literal>string</literal>, the decimal conversion will be done.</para>
+        </listitem>
+      </varlistentry>
+      
+      <varlistentry>
+        <term>conversion</term>
         
-        <para>Any optional input argument equal to the empty matrix
-            <literal>[]</literal> is set to its default value.
-        </para>
+        <listitem>
+          <para>a 1-by-1 matrix of strings, the type of the output
+          <literal>A</literal>. Available values are "string" or
+          "double".
+          </para>
+        </listitem>
+      </varlistentry>
+      
+      <varlistentry>
+        <term>range</term>
         
-        <para>When input argument "conversion" is equal to "double", strings are
-            converted as NaN.
-        </para>
-    </refsection>
-    
-    <refsection>
-        <title>Examples</title>
+        <listitem>
+          <para>a 1-by-4 or 4-by-1 matrix of floating point integers, the
+          range of rows and columns which must be read (default range=[],
+          meaning that all the rows and columns). Specify range using the
+          format <literal>[R1 C1 R2 C2]</literal> where (R1,C1) is the upper
+          left corner of the data to be read and (R2,C2) is the lower right
+          corner.
+          </para>
+        </listitem>
+      </varlistentry>
+      
+      <varlistentry>
+        <term>A</term>
         
-        <programlisting role="example">      // convert a csv string matrix to splitted string or double matrix
-            A = ["1;3 + i"; "Nan;-Inf"]
-            B = csvTextScan(A,';')
-            C = csvTextScan(A,';',[],'double')
-            //
-            // Configure the decimal mark.
-            Atext = [
-            " 1,000000000D+00; 0,000000000D+00; 2,000000000D+02;             Inf; 0,000000000D+00";
-            " 1,000000000D+00; 1,00000000D-300; 2,000000000D+02;             Inf; 0,000000000D+00";
-            " 1,000000000D+00; 1,00000000D-200; 2,000000000D+02; 3,15000000D+300; 1,020000000D+02";
-            " 9,999999999D-01; 1,00000000D-100; 2,000000000D+02; 2,960000000D+02; 1,170000000D+02";
-            " 1,000000000D+00;             Inf;            -Inf;             Nan; 0,000000000D+00"
-            ];
-            csvTextScan( Atext , ";" , "," )    
-        </programlisting>
-    </refsection>
+        <listitem>
+          <para>a m-by-n matrix of strings or double.</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsection>
+  
+  <refsection>
+    <title>Description</title>
     
-    <refsection>
-        <title>See Also</title>
-        
-        <simplelist type="inline">
-            <member>
-                <link linkend="csvRead">csvRead</link>
-            </member>
-        </simplelist>
-    </refsection>
-    <refsection>
-        <title>History</title>
-        <revhistory>
-            <revision>
-                <revnumber>5.4.0</revnumber>
-                <revremark>Function introduced. Based on the 'csv_readwrite' module.</revremark>
-            </revision>
-        </revhistory>
-    </refsection>
+    <para>Given an ascii file with delimited fields, this function returns the
+    corresponding Scilab matrix of strings or doubles.
+    </para>
+    
+    <para>
+      The <literal>csvTextScan</literal> function has the same purpose as
+      <literal>csvRead</literal>, except that <literal>csvTextScan</literal>
+      reads in a string, while <literal>csvRead</literal> reads in a
+      file.
+    </para>
+    
+    <para>The default value of the optional input arguments are defined by the
+    <literal>csvDefault</literal> function.
+    </para>
+    
+    <para>Any optional input argument equal to the empty matrix
+    <literal>[]</literal> is set to its default value.
+    </para>
+    
+    <para>When input argument "conversion" is equal to "double", strings are
+    converted as NaN.
+    </para>
+  </refsection>
+  
+  <refsection>
+    <title>Examples</title> 
+   
+    <programlisting role="example"><![CDATA[
+// convert a csv string matrix to splitted string or double matrix
+A = ["1;3 + i"; "Nan;-Inf"]
+B = csvTextScan(A,';')
+C = csvTextScan(A,';',[],'double')
+//
+// Configure the decimal mark.
+Atext = [
+" 1,000000000D+00; 0,000000000D+00; 2,000000000D+02; Inf; 0,000000000D+00";
+" 1,000000000D+00; 1,00000000D-300; 2,000000000D+02; Inf; 0,000000000D+00";
+" 1,000000000D+00; 1,00000000D-200; 2,000000000D+02; 3,15000000D+300; 1,020000000D+02";
+" 9,999999999D-01; 1,00000000D-100; 2,000000000D+02; 2,960000000D+02; 1,170000000D+02";
+" 1,000000000D+00; Inf;-Inf; Nan; 0,000000000D+00"
+];
+csvTextScan( Atext , ";" , "," )
+    ]]>
+    </programlisting>
+  </refsection>
+
+  <refsection>
+    <title>See Also</title>
+
+    <simplelist type="inline">
+      <member>
+        <link linkend="csvRead">csvRead</link>
+      </member>
+    </simplelist>
+  </refsection>
+  <refsection>
+    <title>History</title>
+    <revhistory>
+      <revision>
+        <revnumber>5.4.0</revnumber>
+        <revremark>Function introduced. Based on the 'csv_readwrite' module.</revremark>
+      </revision>
+      <revision>
+        <revnumber>5.4.1</revnumber>
+        <revremark>
+          If <literal>decimal</literal> is different of <literal>[]</literal> and <literal>conversion</literal> is set to <literal>string</literal>, the decimal conversion will be done.
+          </revremark>
+      </revision>
+    </revhistory>
+  </refsection>
 </refentry>
 
index d47ba60..b3249db 100644 (file)
@@ -10,9 +10,6 @@
           xmlns:ns3="http://www.w3.org/1999/xhtml"
           xmlns:mml="http://www.w3.org/1998/Math/MathML"
           xmlns:db="http://docbook.org/ns/docbook">
-    <info>
-        <pubdate>$LastChangedDate$</pubdate>
-    </info>
     
     <refnamediv>
         <refname>csvRead</refname>
index 3559a61..475b0aa 100644 (file)
@@ -440,12 +440,14 @@ static char **getStringsFromLines(const char **lines, int sizelines,
             for (j = 0; j < m; j++)
             {
 
-                if (decimal)
+                if (!decimal)
                 {
                     results[i + n * j] = strdup(lineStrings[j]);
                 }
                 else
                 {
+                    /* Proceed to the remplacement of the provided decimal to the default on
+                     * usually, it converts "," => "." */
                     results[i + n * j] = csv_strsubst(lineStrings[j], decimal, getCsvDefaultDecimal());
                 }
 
diff --git a/scilab/modules/spreadsheet/tests/nonreg_tests/bug_12140.csv b/scilab/modules/spreadsheet/tests/nonreg_tests/bug_12140.csv
new file mode 100644 (file)
index 0000000..810d21f
--- /dev/null
@@ -0,0 +1,2 @@
+foo bar;bar foo;plop\r
+280;4,7309E-23;2,86982E-23\r
diff --git a/scilab/modules/spreadsheet/tests/nonreg_tests/bug_12140.dia.ref b/scilab/modules/spreadsheet/tests/nonreg_tests/bug_12140.dia.ref
new file mode 100644 (file)
index 0000000..f06b77c
--- /dev/null
@@ -0,0 +1,30 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - Scilab Enterprises - Sylvestre Ledru
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// 
+// <-- JAVA NOT MANDATORY -->
+//
+// <-- Non-regression test for bug 12140 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=12140
+//
+// <-- Short Description -->
+// csvRead fails when comma is used as decimal mark
+//
+filename=SCI+"/modules/spreadsheet/" + "tests/nonreg_tests/bug_12140.csv";
+[Mss, comments] = csvRead(filename, ";" , "," , "double" , [] ,"/foo bar/");
+assert_checkfalse(Mss(1,2) == %nan);
+assert_checkfalse(Mss(1,3) == %nan);
+Mss_ref=[280,4.730900000000000068D-23, 2.869819999999999938D-23];
+assert_checkalmostequal(Mss(1,:), Mss_ref);
+Mss=mgetl(filename);
+M=csvTextScan(Mss(2:$,:),";",",");
+assert_checkalmostequal(M, Mss_ref);
+[Mss, comments] = csvRead(filename, ";" , "," , "string" , [] ,"/foo bar/");
+assert_checkequal(Mss,["280","4.7309E-23","2.86982E-23"]);
+[Mss, comments] = csvRead(filename, ";" , [] , "string" , [] ,"/foo bar/");
+assert_checkequal(Mss,["280","4,7309E-23","2,86982E-23"]);
diff --git a/scilab/modules/spreadsheet/tests/nonreg_tests/bug_12140.tst b/scilab/modules/spreadsheet/tests/nonreg_tests/bug_12140.tst
new file mode 100644 (file)
index 0000000..7bf1d2a
--- /dev/null
@@ -0,0 +1,34 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - Scilab Enterprises - Sylvestre Ledru
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// 
+// <-- JAVA NOT MANDATORY -->
+//
+// <-- Non-regression test for bug 12140 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=12140
+//
+// <-- Short Description -->
+// csvRead fails when comma is used as decimal mark
+//
+filename=SCI+"/modules/spreadsheet/" + "tests/nonreg_tests/bug_12140.csv";
+
+[Mss, comments] = csvRead(filename, ";" , "," , "double" , [] ,"/foo bar/");
+assert_checkfalse(Mss(1,2) == %nan);
+assert_checkfalse(Mss(1,3) == %nan);
+Mss_ref=[280,4.730900000000000068D-23, 2.869819999999999938D-23];
+
+assert_checkalmostequal(Mss(1,:), Mss_ref);
+Mss=mgetl(filename);
+M=csvTextScan(Mss(2:$,:),";",",");
+assert_checkalmostequal(M, Mss_ref);
+
+[Mss, comments] = csvRead(filename, ";" , "," , "string" , [] ,"/foo bar/");
+assert_checkequal(Mss,["280","4.7309E-23","2.86982E-23"]);
+
+[Mss, comments] = csvRead(filename, ";" , [] , "string" , [] ,"/foo bar/");
+assert_checkequal(Mss,["280","4,7309E-23","2,86982E-23"]);
index 18cbf06..1228293 100644 (file)
@@ -58,9 +58,12 @@ r = csvRead(fullfile(path,"K_2.csv"), ascii(9), [], "string");
 assert_checkequal (r,Kstr);
 //
 r = csvRead(fullfile(path,"K_3.csv"), " ", ",", "string");
-assert_checkequal (r,Kstr2);
+assert_checkequal (r,Kstr);
 //
 r = csvRead(fullfile(path,"K_4.csv"), ";", ",", "string");
+assert_checkequal (r,Kstr);
+//
+r = csvRead(fullfile(path,"K_4.csv"), ";", [], "string");
 assert_checkequal (r,Kstr2);
 // =============================================================================
 S = [
index 8e9a744..9093868 100644 (file)
@@ -58,9 +58,12 @@ r = csvRead(fullfile(path,"K_2.csv"), ascii(9), [], "string");
 assert_checkequal (r,Kstr);
 //
 r = csvRead(fullfile(path,"K_3.csv"), " ", ",", "string");
-assert_checkequal (r,Kstr2);
+assert_checkequal (r,Kstr);
 //
 r = csvRead(fullfile(path,"K_4.csv"), ";", ",", "string");
+assert_checkequal (r,Kstr);
+//
+r = csvRead(fullfile(path,"K_4.csv"), ";", [], "string");
 assert_checkequal (r,Kstr2);
 // =============================================================================
 S = [
index 751fa42..1fd0943 100644 (file)
@@ -84,10 +84,18 @@ assert_checkequal (b,Kstr);
 //
 r = mgetl(fullfile(path,"K_3.csv"));
 b = csvTextScan(r, " ", ",", "string");
+assert_checkequal (b,Kstr);
+//
+r = mgetl(fullfile(path,"K_3.csv"));
+b = csvTextScan(r, " ", [], "string");
 assert_checkequal (b,Kstr2);
 //
 r = mgetl(fullfile(path,"K_4.csv"));
 b = csvTextScan(r, ";", ",", "string");
+assert_checkequal (b,Kstr);
+//
+r = mgetl(fullfile(path,"K_4.csv"));
+b = csvTextScan(r, ";", [], "string");
 assert_checkequal (b,Kstr2);
 // =============================================================================
 S = [
index 0d0f2a0..9c2c44e 100644 (file)
@@ -84,10 +84,18 @@ assert_checkequal (b,Kstr);
 //
 r = mgetl(fullfile(path,"K_3.csv"));
 b = csvTextScan(r, " ", ",", "string");
+assert_checkequal (b,Kstr);
+//
+r = mgetl(fullfile(path,"K_3.csv"));
+b = csvTextScan(r, " ", [], "string");
 assert_checkequal (b,Kstr2);
 //
 r = mgetl(fullfile(path,"K_4.csv"));
 b = csvTextScan(r, ";", ",", "string");
+assert_checkequal (b,Kstr);
+//
+r = mgetl(fullfile(path,"K_4.csv"));
+b = csvTextScan(r, ";", [], "string");
 assert_checkequal (b,Kstr2);
 // =============================================================================
 S = [