improve sprintf on %s and %c 91/15691/5
Antoine ELIAS [Thu, 11 Dec 2014 10:55:12 +0000 (11:55 +0100)]
test_run("output_stream","sprintf",["no_check_error_output" ]);
test_run("output_stream","msprintf",["no_check_error_output" ]);

Change-Id: I0b28d8e8df38e63131eaab8c082e542ef87355f2

scilab/modules/output_stream/includes/scilab_sprintf.hxx
scilab/modules/output_stream/sci_gateway/cpp/output_stream_gw/output_stream_gw.vcxproj
scilab/modules/output_stream/sci_gateway/cpp/output_stream_gw/output_stream_gw.vcxproj.filters
scilab/modules/output_stream/src/cpp/scilab_sprintf.cpp
scilab/modules/string/Makefile.am
scilab/modules/string/Makefile.in
scilab/modules/string/includes/os_wtoi.h [new file with mode: 0644]
scilab/modules/string/src/c/string.vcxproj
scilab/modules/string/src/c/string.vcxproj.filters
scilab/modules/string/src/cpp/os_wtoi.cpp [new file with mode: 0644]

index 0c7c0b4..a27532e 100644 (file)
@@ -21,6 +21,9 @@ typedef struct
     wchar_t* pwstToken;
     types::InternalType::ScilabType outputType;
     bool bLengthFlag;
+    int width;
+    int prec;
+    int typePos;
 } TokenDef;
 
 
index e33bce9..0717c6e 100644 (file)
       <Project>{ecffeb0c-1eda-45ee-9a10-b18143852e17}</Project>
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
     </ProjectReference>
+    <ProjectReference Include="..\..\..\..\string\src\c\string.vcxproj">
+      <Project>{8d45767a-9b03-4905-97f6-d2f3f79141ea}</Project>
+    </ProjectReference>
     <ProjectReference Include="..\..\..\..\threads\threads.vcxproj">
       <Project>{50a1ffc8-adc2-4d9e-a2d0-5dcd63188ae9}</Project>
     </ProjectReference>
index 14a59bd..e4feadd 100644 (file)
@@ -5,14 +5,14 @@
       <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
       <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
     </Filter>
-    <Filter Include="Source Files\Resource Files">
-      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
-      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
-    </Filter>
     <Filter Include="Header Files">
       <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
       <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
     </Filter>
+    <Filter Include="Resource Files">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\output_stream_gw.cpp">
index 7ccda39..3b06701 100644 (file)
@@ -13,7 +13,7 @@
  */
 
 #include <stdio.h>
-
+#include <cmath>
 #include "types.hxx"
 #include "double.hxx"
 #include "string.hxx"
@@ -28,6 +28,8 @@ extern "C"
 #include "localization.h"
 #include "charEncoding.h"
 #include "os_wcsdup.h"
+#include "os_wtoi.h"
+#include "os_swprintf.h"
 }
 
 #define NanString L"Nan"
@@ -35,15 +37,16 @@ extern "C"
 #define NegInfString L"-Inf"
 
 static wchar_t* replaceAndCountLines(const wchar_t* _pwstInput, int* _piLines, int* _piNewLine);
-
+static wchar_t* addl(TokenDef* token);
+static void updatel(TokenDef* token);
 wchar_t** scilab_sprintf(const char* _pstName, const wchar_t* _pwstInput, typed_list &in, ArgumentPosition* _pArgs, int _iArgsCount, int* _piOutputRows, int* _piNewLine)
 {
     /* Force Windows display to have two-digit exponent. */
 #ifdef _MSC_VER
     _set_output_format(_TWO_DIGIT_EXPONENT);
 #endif
-    wchar_t** pwstOutput        = NULL;
-    wchar_t* pwstFirstOutput    = NULL;
+    wchar_t** pwstOutput = NULL;
+    wchar_t* pwstFirstOutput = NULL;
     *_piNewLine = 0;
     size_t pos = 0;
 
@@ -62,15 +65,15 @@ wchar_t** scilab_sprintf(const char* _pstName, const wchar_t* _pwstInput, typed_
         //pwstToken[1] : "%s bla2 "
         //pwstToken[2] : "%d bla3"
 
-        size_t iStart   = 0;
-        size_t iEnd     = 0;
-        int iToken      = 0;
-        int iPosArg     = 0;
+        size_t iStart = 0;
+        size_t iEnd = 0;
+        int iToken = 0;
+        int iPosArg = 0;
 
         TokenDef* pToken = new TokenDef[_iArgsCount + 1];
-        wchar_t* pwstStart  = pwstFirstOutput;
+        wchar_t* pwstStart = pwstFirstOutput;
 
-        bool bFinish         = false;
+        bool bFinish = false;
         bool bPercentPercent = false;
 
         while (!bFinish)
@@ -87,7 +90,7 @@ wchar_t** scilab_sprintf(const char* _pstName, const wchar_t* _pwstInput, typed_
                     if (pwstEnd == NULL)
                     {
                         //end of string
-                        iEnd    = wcslen(pwstFirstOutput);
+                        iEnd = wcslen(pwstFirstOutput);
                         bFinish = true;
                     }
                     else
@@ -107,7 +110,7 @@ wchar_t** scilab_sprintf(const char* _pstName, const wchar_t* _pwstInput, typed_
             else
             {
                 //end of string
-                iEnd    = wcslen(pwstFirstOutput);
+                iEnd = wcslen(pwstFirstOutput);
                 bFinish = true;
             }
 
@@ -134,6 +137,7 @@ wchar_t** scilab_sprintf(const char* _pstName, const wchar_t* _pwstInput, typed_
                 }
 
                 //looking for width
+                pToken[iToken].width = -1;
                 if (*(pwstPercent + 1) == L'*')
                 {
                     pwstPercent++;
@@ -141,19 +145,29 @@ wchar_t** scilab_sprintf(const char* _pstName, const wchar_t* _pwstInput, typed_
                 else
                 {
                     //number
-                    while (iswdigit(*(pwstPercent + 1)))
+                    if (iswdigit(*(pwstPercent + 1)))
                     {
-                        pwstPercent++;
+                        pToken[iToken].width = os_wtoi(pwstPercent + 1);
+                        while (iswdigit(*(pwstPercent + 1)))
+                        {
+                            pwstPercent++;
+                        }
                     }
                 }
 
                 //looking for precision
+                pToken[iToken].prec = -1;
                 if (*(pwstPercent + 1) == L'.')
                 {
                     pwstPercent++;
-                    while (iswdigit(*(pwstPercent + 1)))
+
+                    if (iswdigit(*(pwstPercent + 1)))
                     {
-                        pwstPercent++;
+                        pToken[iToken].prec = os_wtoi(pwstPercent + 1);
+                        while (iswdigit(*(pwstPercent + 1)))
+                        {
+                            pwstPercent++;
+                        }
                     }
                 }
 
@@ -171,6 +185,7 @@ wchar_t** scilab_sprintf(const char* _pstName, const wchar_t* _pwstInput, typed_
                 }
 
                 wchar_t wcType = *(pwstPercent + 1);
+                pToken[iToken].typePos = (pwstPercent + 1) - pToken[iToken].pwstToken;
                 switch (wcType)
                 {
                     case L'i' : //integer
@@ -186,15 +201,7 @@ wchar_t** scilab_sprintf(const char* _pstName, const wchar_t* _pwstInput, typed_
                             return NULL;
                         }
 
-                        if (finite(in[iPosArg + 1]->getAs<types::Double>()->get(0)) == false)
-                        {
-                            pToken[iToken].outputType = InternalType::ScilabString;
-                            *(pwstPercent + 1) = L's';
-                        }
-                        else
-                        {
-                            pToken[iToken].outputType = InternalType::ScilabInt32;
-                        }
+                        pToken[iToken].outputType = InternalType::ScilabInt32;
 
                         iPosArg++;
                         break;
@@ -210,15 +217,7 @@ wchar_t** scilab_sprintf(const char* _pstName, const wchar_t* _pwstInput, typed_
                             return NULL;
                         }
 
-                        if (finite(in[iPosArg + 1]->getAs<types::Double>()->get(0)) == false)
-                        {
-                            pToken[iToken].outputType = InternalType::ScilabString;
-                            *(pwstPercent + 1) = L's';
-                        }
-                        else
-                        {
-                            pToken[iToken].outputType = InternalType::ScilabDouble;
-                        }
+                        pToken[iToken].outputType = InternalType::ScilabDouble;
                         iPosArg++;
                         break;
                     case L's' :
@@ -230,6 +229,11 @@ wchar_t** scilab_sprintf(const char* _pstName, const wchar_t* _pwstInput, typed_
                             return NULL;
                         }
 
+                        if (pToken[iToken].bLengthFlag == false)
+                        {
+                            updatel(&(pToken[iToken]));
+                        }
+
                         pToken[iToken].outputType = InternalType::ScilabString;
                         iPosArg++;
                         break;
@@ -281,7 +285,29 @@ wchar_t** scilab_sprintf(const char* _pstName, const wchar_t* _pwstInput, typed_
                 {
                     wchar_t pwstTemp[bsiz];
                     double dblVal = in[_pArgs[iPosArg].iArg]->getAs<Double>()->get(j, _pArgs[iPosArg].iPos);
-                    swprintf(pwstTemp, bsiz, pToken[i].pwstToken, dblVal);
+
+                    if (finite(dblVal))
+                    {
+                        os_swprintf(pwstTemp, bsiz, pToken[i].pwstToken, dblVal);
+                    }
+                    else
+                    {
+                        wchar_t* newToken = addl(&pToken[i]);
+                        if (ISNAN(dblVal))
+                        {
+                            os_swprintf(pwstTemp, bsiz, newToken, NanString);
+                        }
+                        else if (std::signbit(dblVal))
+                        {
+                            os_swprintf(pwstTemp, bsiz, newToken, NegInfString);
+                        }
+                        else
+                        {
+                            os_swprintf(pwstTemp, bsiz, newToken, InfString);
+                        }
+
+                        delete[] newToken;
+                    }
                     iPosArg++;
                     oFirstOutput << pwstTemp;
                 }
@@ -289,7 +315,7 @@ wchar_t** scilab_sprintf(const char* _pstName, const wchar_t* _pwstInput, typed_
                 {
                     wchar_t pwstTemp[bsiz];
                     double dblVal = in[_pArgs[iPosArg].iArg]->getAs<Double>()->get(j, _pArgs[iPosArg].iPos);
-                    swprintf(pwstTemp, bsiz, pToken[i].pwstToken, (int)dblVal);
+                    os_swprintf(pwstTemp, bsiz, pToken[i].pwstToken, (int)dblVal);
                     iPosArg++;
                     oFirstOutput << pwstTemp;
                 }
@@ -320,21 +346,44 @@ wchar_t** scilab_sprintf(const char* _pstName, const wchar_t* _pwstInput, typed_
                     int posC = (int)wcscspn(pToken[i].pwstToken, L"c");
                     int posS = (int)wcscspn(pToken[i].pwstToken, L"s");
 
-                    if (!posS || !posC)
+                    if (posS == 0 || posC == 0)
                     {
                         *_piOutputRows = 0;
                         return NULL;
                     }
 
-                    if (posC < posS)
+                    bool bC = posC < posS;
+                    int len = 1;
+                    if (pToken[i].prec == -1)
+                    {
+                        if (bC == false)
+                        {
+                            len = (int)wcslen(pwstStr);
+                        }
+                    }
+                    else
+                    {
+                        if (bC == false)
+                        {
+                            len = std::min(pToken[i].prec, (int)wcslen(pwstStr));
+                        }
+                    }
+
+                    len += (int)wcslen(pToken[i].pwstToken);
+                    len = std::max(len, pToken[i].width);
+                    wchar_t* pwstTemp = (wchar_t*)MALLOC((len + 1) * sizeof(wchar_t));
+
+                    if (bC)
                     {
-                        oFirstOutput << pwstStr[0];
+                        os_swprintf(pwstTemp, len + 1, pToken[i].pwstToken, pwstStr[0]);
                     }
-                    else //'s'
+                    else
                     {
-                        oFirstOutput << pwstStr;
+                        os_swprintf(pwstTemp, len + 1, pToken[i].pwstToken, pwstStr);
                     }
 
+                    oFirstOutput << pwstTemp;
+                    FREE(pwstTemp);
                     iPosArg++;
                 }
                 else
@@ -346,7 +395,6 @@ wchar_t** scilab_sprintf(const char* _pstName, const wchar_t* _pwstInput, typed_
         }
 
         pwstFirstOutput = os_wcsdup((wchar_t*)oFirstOutput.str().c_str());
-
     }
 
     pwstOutput = (wchar_t**)MALLOC((*_piOutputRows) * sizeof(wchar_t*));
@@ -446,3 +494,25 @@ static wchar_t* replaceAndCountLines(const wchar_t* _pwstInput, int* _piLines, i
     return pwstFirstOutput;
 }
 /*--------------------------------------------------------------------------*/
+wchar_t* addl(TokenDef* token)
+{
+    //replace %s or %c by %ls or %lc to wide char compatibility
+    int iPos = token->typePos;
+    int sizeTotal = (int)wcslen(token->pwstToken);
+    wchar_t* pwstToken = new wchar_t[sizeTotal + 2];
+
+    wcsncpy(pwstToken, token->pwstToken, iPos);
+    pwstToken[iPos] = L'l';
+    pwstToken[iPos + 1] = L's';
+    wcsncpy(&pwstToken[iPos + 2], token->pwstToken + iPos + 1, sizeTotal - (iPos + 1));
+    pwstToken[sizeTotal + 1]  = L'\0';
+
+    return pwstToken;
+}
+/*--------------------------------------------------------------------------*/
+void updatel(TokenDef* token)
+{
+    wchar_t* newToken = addl(token);
+    delete[] token->pwstToken;
+    token->pwstToken = newToken;
+}
index 8a7a663..7e85251 100644 (file)
@@ -5,7 +5,8 @@
 
 STRING_CPP_SOURCES = \
     src/cpp/stripblanks.cpp \
-    src/cpp/sort_inter.cpp
+    src/cpp/sort_inter.cpp \
+    src/cpp/os_wtoi.cpp
 
 STRING_C_SOURCES = \
     src/c/convstr.c \
index 1ea27d0..33201df 100644 (file)
@@ -193,7 +193,8 @@ am__objects_1 = src/c/libscistring_algo_la-convstr.lo \
        src/c/libscistring_algo_la-isascii.lo \
        src/c/libscistring_algo_la-isnum.lo
 am__objects_2 = src/cpp/libscistring_algo_la-stripblanks.lo \
-       src/cpp/libscistring_algo_la-sort_inter.lo
+       src/cpp/libscistring_algo_la-sort_inter.lo \
+       src/cpp/libscistring_algo_la-os_wtoi.lo
 am_libscistring_algo_la_OBJECTS = $(am__objects_1) $(am__objects_2)
 libscistring_algo_la_OBJECTS = $(am_libscistring_algo_la_OBJECTS)
 AM_V_lt = $(am__v_lt_@AM_V@)
@@ -611,7 +612,8 @@ top_srcdir = @top_srcdir@
 yacc_present = @yacc_present@
 STRING_CPP_SOURCES = \
     src/cpp/stripblanks.cpp \
-    src/cpp/sort_inter.cpp
+    src/cpp/sort_inter.cpp \
+    src/cpp/os_wtoi.cpp
 
 STRING_C_SOURCES = \
     src/c/convstr.c \
@@ -991,6 +993,8 @@ src/cpp/libscistring_algo_la-stripblanks.lo: src/cpp/$(am__dirstamp) \
        src/cpp/$(DEPDIR)/$(am__dirstamp)
 src/cpp/libscistring_algo_la-sort_inter.lo: src/cpp/$(am__dirstamp) \
        src/cpp/$(DEPDIR)/$(am__dirstamp)
+src/cpp/libscistring_algo_la-os_wtoi.lo: src/cpp/$(am__dirstamp) \
+       src/cpp/$(DEPDIR)/$(am__dirstamp)
 
 libscistring-algo.la: $(libscistring_algo_la_OBJECTS) $(libscistring_algo_la_DEPENDENCIES) $(EXTRA_libscistring_algo_la_DEPENDENCIES) 
        $(AM_V_CXXLD)$(CXXLINK) $(am_libscistring_algo_la_rpath) $(libscistring_algo_la_OBJECTS) $(libscistring_algo_la_LIBADD) $(LIBS)
@@ -1157,6 +1161,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscistring_algo_la-strsplit.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscistring_algo_la-strsubst.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscistring_algo_la-tokens.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscistring_algo_la-os_wtoi.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscistring_algo_la-sort_inter.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscistring_algo_la-stripblanks.Plo@am__quote@
 
@@ -1397,6 +1402,13 @@ src/cpp/libscistring_algo_la-sort_inter.lo: src/cpp/sort_inter.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscistring_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libscistring_algo_la-sort_inter.lo `test -f 'src/cpp/sort_inter.cpp' || echo '$(srcdir)/'`src/cpp/sort_inter.cpp
 
+src/cpp/libscistring_algo_la-os_wtoi.lo: src/cpp/os_wtoi.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscistring_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/libscistring_algo_la-os_wtoi.lo -MD -MP -MF src/cpp/$(DEPDIR)/libscistring_algo_la-os_wtoi.Tpo -c -o src/cpp/libscistring_algo_la-os_wtoi.lo `test -f 'src/cpp/os_wtoi.cpp' || echo '$(srcdir)/'`src/cpp/os_wtoi.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/$(DEPDIR)/libscistring_algo_la-os_wtoi.Tpo src/cpp/$(DEPDIR)/libscistring_algo_la-os_wtoi.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='src/cpp/os_wtoi.cpp' object='src/cpp/libscistring_algo_la-os_wtoi.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscistring_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libscistring_algo_la-os_wtoi.lo `test -f 'src/cpp/os_wtoi.cpp' || echo '$(srcdir)/'`src/cpp/os_wtoi.cpp
+
 sci_gateway/cpp/libscistring_la-sci_stripblanks.lo: sci_gateway/cpp/sci_stripblanks.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscistring_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscistring_la-sci_stripblanks.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscistring_la-sci_stripblanks.Tpo -c -o sci_gateway/cpp/libscistring_la-sci_stripblanks.lo `test -f 'sci_gateway/cpp/sci_stripblanks.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_stripblanks.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscistring_la-sci_stripblanks.Tpo sci_gateway/cpp/$(DEPDIR)/libscistring_la-sci_stripblanks.Plo
diff --git a/scilab/modules/string/includes/os_wtoi.h b/scilab/modules/string/includes/os_wtoi.h
new file mode 100644 (file)
index 0000000..be18d05
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ *  Copyright (C) 2014 - Scilab Enterprises - Cedric Delamarre
+ *
+ *  This file must be used under the terms of the CeCILL.
+ *  This source file is licensed as described in the file COPYING, which
+ *  you should have received as part of this distribution.  The terms
+ *  are also available at
+ *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#ifndef __OS_WTOI_H__
+#define __OS_WTOI_H__
+
+#include <string.h>
+#include "dynlib_string.h"
+
+STRING_IMPEXP int os_wtoi(const wchar_t* pwcsStr);
+
+#endif /* !__OS_WTOI_H__ */
index c867c07..e2d96c3 100644 (file)
@@ -252,6 +252,7 @@ lib /DEF:"$(ProjectDir)localization_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Pl
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClCompile Include="..\cpp\os_wtoi.cpp" />
     <ClCompile Include="..\cpp\sort_inter.cpp" />
     <ClCompile Include="convstr.c" />
     <ClCompile Include="cvstr.c" />
@@ -324,6 +325,7 @@ lib /DEF:"$(ProjectDir)localization_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Pl
     <ClInclude Include="..\..\includes\os_wcsdup.h" />
     <ClInclude Include="..\..\includes\os_wcsicmp.h" />
     <ClInclude Include="..\..\includes\os_wcstok.h" />
+    <ClInclude Include="..\..\includes\os_wtoi.h" />
     <ClInclude Include="..\..\includes\pcre_private.h" />
     <ClInclude Include="..\..\includes\scistrtostr.h" />
     <ClInclude Include="..\..\includes\stricmp.h" />
index b462c08..3623b21 100644 (file)
     <ClCompile Include="..\cpp\sort_inter.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\cpp\os_wtoi.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <None Include="core_import.def">
     <ClInclude Include="..\cpp\sort_inter.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\includes\os_wtoi.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <Library Include="..\..\..\..\bin\blasplus.lib" />
diff --git a/scilab/modules/string/src/cpp/os_wtoi.cpp b/scilab/modules/string/src/cpp/os_wtoi.cpp
new file mode 100644 (file)
index 0000000..9daf9f8
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ *  Copyright (C) 2014 - Scilab Enterprises - Cedric Delamarre
+ *
+ *  This file must be used under the terms of the CeCILL.
+ *  This source file is licensed as described in the file COPYING, which
+ *  you should have received as part of this distribution.  The terms
+ *  are also available at
+ *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include <sstream>
+#include <string>
+#include <iostream>
+
+extern "C"
+{
+#include "os_wtoi.h"
+}
+
+int os_wtoi(const wchar_t *_pwcsSource)
+{
+    std::wstring wstr(_pwcsSource);
+    std::wistringstream wstrm(wstr);
+    int num;
+    wstrm >> num;
+    return num;
+}
+
+