summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine ELIAS <antoine.elias@scilab-enterprises.com>2016-01-13 09:02:46 +0100
committerAntoine ELIAS <antoine.elias@scilab-enterprises.com>2016-11-10 08:21:36 +0100
commitc2a4579f1826838f584b303213aa525ba2762e11 (patch)
tree656f970cc3fbeab69a388f6d8655cb71724d4893
parent07b026ce027898048dc6000d211c427e2279fa61 (diff)
downloadscilab-c2a4579f1826838f584b303213aa525ba2762e11.zip
scilab-c2a4579f1826838f584b303213aa525ba2762e11.tar.gz
utf: module string 2
Change-Id: I745ce61fa47f0d4290263ed547b5adb2578b57a4
-rw-r--r--scilab/modules/string/Makefile.am2
-rw-r--r--scilab/modules/string/includes/StringConvert.h1
-rw-r--r--scilab/modules/string/includes/pcre_private.h3
-rw-r--r--scilab/modules/string/includes/stringToComplex.h5
-rw-r--r--scilab/modules/string/includes/stringToDouble.h22
-rw-r--r--scilab/modules/string/includes/strsubst.h7
-rw-r--r--scilab/modules/string/sci_gateway/cpp/sci_ascii.cpp14
-rw-r--r--scilab/modules/string/sci_gateway/cpp/sci_grep.cpp38
-rw-r--r--scilab/modules/string/sci_gateway/cpp/sci_isascii.cpp2
-rw-r--r--scilab/modules/string/sci_gateway/cpp/sci_length.cpp2
-rw-r--r--scilab/modules/string/sci_gateway/cpp/sci_regexp.cpp36
-rw-r--r--scilab/modules/string/sci_gateway/cpp/sci_strcat.cpp8
-rw-r--r--scilab/modules/string/sci_gateway/cpp/sci_strchr.cpp33
-rw-r--r--scilab/modules/string/sci_gateway/cpp/sci_strindex.cpp51
-rw-r--r--scilab/modules/string/sci_gateway/cpp/sci_strncpy.cpp19
-rw-r--r--scilab/modules/string/sci_gateway/cpp/sci_strrchr.cpp31
-rw-r--r--scilab/modules/string/sci_gateway/cpp/sci_strspn.cpp7
-rw-r--r--scilab/modules/string/sci_gateway/cpp/sci_tokens.cpp31
-rw-r--r--scilab/modules/string/src/c/StringConvert.c47
-rw-r--r--scilab/modules/string/src/c/convstr.c47
-rw-r--r--scilab/modules/string/src/c/convstr.h36
-rw-r--r--scilab/modules/string/src/c/isalphanum.c9
-rw-r--r--scilab/modules/string/src/c/isascii.c18
-rw-r--r--scilab/modules/string/src/c/isascii.h2
-rw-r--r--scilab/modules/string/src/c/isdigit.c10
-rw-r--r--scilab/modules/string/src/c/isletter.c47
-rw-r--r--scilab/modules/string/src/c/isletter.h7
-rw-r--r--scilab/modules/string/src/c/isnum.c29
-rw-r--r--scilab/modules/string/src/c/isnum.h5
-rw-r--r--scilab/modules/string/src/c/partfunction.c28
-rw-r--r--scilab/modules/string/src/c/partfunction.h2
-rw-r--r--scilab/modules/string/src/c/pcre_private.c65
-rw-r--r--scilab/modules/string/src/c/string.vcxproj2
-rw-r--r--scilab/modules/string/src/c/string.vcxproj.filters6
-rw-r--r--scilab/modules/string/src/c/stringToComplex.c463
-rw-r--r--scilab/modules/string/src/c/stringToDouble.c124
-rw-r--r--scilab/modules/string/src/c/stringsstrrev.c20
-rw-r--r--scilab/modules/string/src/c/stringsstrrev.h2
-rw-r--r--scilab/modules/string/src/c/strsplit.c65
-rw-r--r--scilab/modules/string/src/c/strsubst.c184
-rw-r--r--scilab/modules/string/src/c/tokens.c40
-rw-r--r--scilab/modules/string/src/c/tokens.h2
42 files changed, 277 insertions, 1295 deletions
diff --git a/scilab/modules/string/Makefile.am b/scilab/modules/string/Makefile.am
index 180f6cd..c35272a 100644
--- a/scilab/modules/string/Makefile.am
+++ b/scilab/modules/string/Makefile.am
@@ -9,7 +9,6 @@ STRING_CPP_SOURCES = \
9 src/cpp/os_wtoi.cpp 9 src/cpp/os_wtoi.cpp
10 10
11STRING_C_SOURCES = \ 11STRING_C_SOURCES = \
12 src/c/convstr.c \
13 src/c/men_Sutils.c \ 12 src/c/men_Sutils.c \
14 src/c/tokens.c \ 13 src/c/tokens.c \
15 src/c/strsplit.c \ 14 src/c/strsplit.c \
@@ -150,7 +149,6 @@ libscistring_la_sci_gateway_DATA = sci_gateway/string_gateway.xml
150libscistring_la_includedir=$(pkgincludedir) 149libscistring_la_includedir=$(pkgincludedir)
151libscistring_la_include_HEADERS = \ 150libscistring_la_include_HEADERS = \
152includes/complex_array.h \ 151includes/complex_array.h \
153includes/convstr.h \
154includes/cvstr.h \ 152includes/cvstr.h \
155includes/dynlib_string_gw.h \ 153includes/dynlib_string_gw.h \
156includes/dynlib_string.h \ 154includes/dynlib_string.h \
diff --git a/scilab/modules/string/includes/StringConvert.h b/scilab/modules/string/includes/StringConvert.h
index 2d7268e..86ccf4d 100644
--- a/scilab/modules/string/includes/StringConvert.h
+++ b/scilab/modules/string/includes/StringConvert.h
@@ -22,6 +22,5 @@
22* @return number of \n found 22* @return number of \n found
23*/ 23*/
24STRING_IMPEXP int StringConvert(char *str); 24STRING_IMPEXP int StringConvert(char *str);
25STRING_IMPEXP int StringConvertW(wchar_t *str);
26 25
27#endif /* __STRINGCONVERT_H__ */ 26#endif /* __STRINGCONVERT_H__ */
diff --git a/scilab/modules/string/includes/pcre_private.h b/scilab/modules/string/includes/pcre_private.h
index c9b9875..dddd7fa 100644
--- a/scilab/modules/string/includes/pcre_private.h
+++ b/scilab/modules/string/includes/pcre_private.h
@@ -36,8 +36,7 @@ typedef enum
36} pcre_error_code; 36} pcre_error_code;
37 37
38 38
39STRING_IMPEXP pcre_error_code pcre_private(char *INPUT_LINE, char *INPUT_PAT, int *Output_Start, int *Output_End, char*** _pstCapturedString, int* _piCapturedStringCount); 39STRING_IMPEXP pcre_error_code pcre_private(const char *INPUT_LINE, const char *INPUT_PAT, int *Output_Start, int *Output_End, char*** _pstCapturedString, int* _piCapturedStringCount);
40STRING_IMPEXP pcre_error_code wide_pcre_private(wchar_t *INPUT_LINE, wchar_t *INPUT_PAT, int *Output_Start, int *Output_End, wchar_t*** _pstCapturedString, int* _piCapturedStringCount);
41 40
42#endif /* __PCRE_PRIVATE_H__ */ 41#endif /* __PCRE_PRIVATE_H__ */
43/*------------------------------------------------------------------------*/ 42/*------------------------------------------------------------------------*/
diff --git a/scilab/modules/string/includes/stringToComplex.h b/scilab/modules/string/includes/stringToComplex.h
index ad1435f..7246ffe 100644
--- a/scilab/modules/string/includes/stringToComplex.h
+++ b/scilab/modules/string/includes/stringToComplex.h
@@ -39,11 +39,6 @@ extern "C" {
39 BOOL bConvertByNAN, 39 BOOL bConvertByNAN,
40 stringToComplexError *ierr); 40 stringToComplexError *ierr);
41 41
42 doublecomplex stringToComplexW(const wchar_t *pSTR,
43 const wchar_t *decimal,
44 BOOL bConvertByNAN,
45 stringToComplexError *ierr);
46
47 STRING_IMPEXP complexArray *stringsToComplexArray(const char **pSTRs, int nbElements, 42 STRING_IMPEXP complexArray *stringsToComplexArray(const char **pSTRs, int nbElements,
48 const char *decimal, 43 const char *decimal,
49 BOOL bConvertByNAN, 44 BOOL bConvertByNAN,
diff --git a/scilab/modules/string/includes/stringToDouble.h b/scilab/modules/string/includes/stringToDouble.h
index 1eb6cf7..c61ef73 100644
--- a/scilab/modules/string/includes/stringToDouble.h
+++ b/scilab/modules/string/includes/stringToDouble.h
@@ -19,47 +19,26 @@
19#include <wchar.h> 19#include <wchar.h>
20 20
21#define NanString "Nan" 21#define NanString "Nan"
22#define NanStringW L"Nan"
23#define InfString "Inf" 22#define InfString "Inf"
24#define InfStringW L"Inf"
25#define NegInfString "-Inf" 23#define NegInfString "-Inf"
26#define NegInfStringW L"-Inf"
27#define PosInfString "+Inf" 24#define PosInfString "+Inf"
28#define PosInfStringW L"+Inf"
29#define NegNanString "-Nan" /* no sense but used by some users */ 25#define NegNanString "-Nan" /* no sense but used by some users */
30#define NegNanStringW L"-Nan" /* no sense but used by some users */
31#define PosNanString "+Nan" /* no sense but used by some users */ 26#define PosNanString "+Nan" /* no sense but used by some users */
32#define PosNanStringW L"+Nan" /* no sense but used by some users */
33#define ScilabNanString "%nan" 27#define ScilabNanString "%nan"
34#define ScilabNanStringW L"%nan"
35#define ScilabInfString "%inf" 28#define ScilabInfString "%inf"
36#define ScilabInfStringW L"%inf"
37#define ScilabNegInfString "-%inf" 29#define ScilabNegInfString "-%inf"
38#define ScilabNegInfStringW L"-%inf"
39#define ScilabPosInfString "+%inf" 30#define ScilabPosInfString "+%inf"
40#define ScilabPosInfStringW L"+%inf"
41#define ScilabNegNanString "-%nan" /* no sense but used by some users */ 31#define ScilabNegNanString "-%nan" /* no sense but used by some users */
42#define ScilabNegNanStringW L"-%nan" /* no sense but used by some users */
43#define ScilabPosNanString "+%nan" /* no sense but used by some users */ 32#define ScilabPosNanString "+%nan" /* no sense but used by some users */
44#define ScilabPosNanStringW L"+%nan" /* no sense but used by some users */
45#define ScilabPiString "%pi" 33#define ScilabPiString "%pi"
46#define ScilabPiStringW L"%pi"
47#define ScilabNegPiString "-%pi" 34#define ScilabNegPiString "-%pi"
48#define ScilabNegPiStringW L"-%pi"
49#define ScilabPosPiString "+%pi" 35#define ScilabPosPiString "+%pi"
50#define ScilabPosPiStringW L"+%pi"
51#define ScilabEString "%e" 36#define ScilabEString "%e"
52#define ScilabEStringW L"%e"
53#define ScilabPosEString "+%e" 37#define ScilabPosEString "+%e"
54#define ScilabPosEStringW L"+%e"
55#define ScilabNegEString "-%e" 38#define ScilabNegEString "-%e"
56#define ScilabNegEStringW L"-%e"
57#define ScilabEpsString "%eps" 39#define ScilabEpsString "%eps"
58#define ScilabEpsStringW L"%eps"
59#define ScilabPosEpsString "+%eps" 40#define ScilabPosEpsString "+%eps"
60#define ScilabPosEpsStringW L"+%eps"
61#define ScilabNegEpsString "-%eps" 41#define ScilabNegEpsString "-%eps"
62#define ScilabNegEpsStringW L"-%eps"
63 42
64#ifdef __cplusplus 43#ifdef __cplusplus
65extern "C" { 44extern "C" {
@@ -82,7 +61,6 @@ extern "C" {
82 * @return <ReturnValue> 61 * @return <ReturnValue>
83 */ 62 */
84 STRING_IMPEXP double stringToDouble(const char *pSTR, BOOL bConvertByNAN, stringToDoubleError *ierr); 63 STRING_IMPEXP double stringToDouble(const char *pSTR, BOOL bConvertByNAN, stringToDoubleError *ierr);
85 STRING_IMPEXP double stringToDoubleW(const wchar_t *pSTR, BOOL bConvertByNAN, stringToDoubleError *ierr);
86 64
87#ifdef __cplusplus 65#ifdef __cplusplus
88} 66}
diff --git a/scilab/modules/string/includes/strsubst.h b/scilab/modules/string/includes/strsubst.h
index 779ae33..4e20d14 100644
--- a/scilab/modules/string/includes/strsubst.h
+++ b/scilab/modules/string/includes/strsubst.h
@@ -40,11 +40,4 @@ STRING_IMPEXP char **strsubst_reg(const char **strings_input, int strings_dim, c
40STRING_IMPEXP char *strsub(const char* input_string, const char* string_to_search, const char* replacement_string); 40STRING_IMPEXP char *strsub(const char* input_string, const char* string_to_search, const char* replacement_string);
41STRING_IMPEXP char *strsub_reg(const char* input_string, const char* string_to_search, const char* replacement_string, int *ierr); 41STRING_IMPEXP char *strsub_reg(const char* input_string, const char* string_to_search, const char* replacement_string, int *ierr);
42 42
43
44STRING_IMPEXP wchar_t **wcssubst(const wchar_t** _pwstInput, int _iInputSize, const wchar_t* _pwstSearch, const wchar_t* _pwstReplace);
45STRING_IMPEXP wchar_t **wcssubst_reg(const wchar_t** _pwstInput, int _iInputSize, const wchar_t* _pwstSearch, const wchar_t* _pwstReplace, int* _piErr);
46
47STRING_IMPEXP wchar_t *wcssub(const wchar_t* _pwstInput, const wchar_t* _pwstSearch, const wchar_t* _pwstReplace);
48STRING_IMPEXP wchar_t *wcssub_reg(const wchar_t* _pwstInput, const wchar_t* _pwstSearch, const wchar_t* _pwstReplace, int* _piErr);
49
50#endif /* __STRSUBST_H__ */ 43#endif /* __STRSUBST_H__ */
diff --git a/scilab/modules/string/sci_gateway/cpp/sci_ascii.cpp b/scilab/modules/string/sci_gateway/cpp/sci_ascii.cpp
index 40c78c6..1f46b6c 100644
--- a/scilab/modules/string/sci_gateway/cpp/sci_ascii.cpp
+++ b/scilab/modules/string/sci_gateway/cpp/sci_ascii.cpp
@@ -151,26 +151,16 @@ types::Double* StringToDouble(types::String* _pst)
151 int iTotalLen = 0; 151 int iTotalLen = 0;
152 int iSize = _pst->getSize(); 152 int iSize = _pst->getSize();
153 153
154 char** pst = new char*[iSize]; 154 char** pst = _pst->get();
155 int* pstLen = new int[iSize]; 155 int* pstLen = new int[iSize];
156 for (int i = 0 ; i < iSize ; i++) 156 for (int i = 0 ; i < iSize ; i++)
157 { 157 {
158 pst[i] = os_strdup(_pst->get(i));
159 pstLen[i] = (int)strlen(pst[i]); 158 pstLen[i] = (int)strlen(pst[i]);
160 iTotalLen += pstLen[i]; 159 iTotalLen += pstLen[i];
161 } 160 }
162 161
163 if (iTotalLen == 0) 162 if (iTotalLen == 0)
164 { 163 {
165 for (int i = 0; i < iSize; ++i)
166 {
167 if (pst[i])
168 {
169 FREE(pst[i]);
170 }
171 }
172
173 delete[] pst;
174 delete[] pstLen; 164 delete[] pstLen;
175 return types::Double::Empty(); 165 return types::Double::Empty();
176 } 166 }
@@ -188,11 +178,9 @@ types::Double* StringToDouble(types::String* _pst)
188 //transform character value as double. 178 //transform character value as double.
189 pdbl[index] = (unsigned char)pst[i][j]; 179 pdbl[index] = (unsigned char)pst[i][j];
190 } 180 }
191 FREE(pst[i]);
192 } 181 }
193 182
194 delete[] pstLen; 183 delete[] pstLen;
195 delete[] pst;
196 return pOut; 184 return pOut;
197} 185}
198/*--------------------------------------------------------------------------*/ 186/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/string/sci_gateway/cpp/sci_grep.cpp b/scilab/modules/string/sci_gateway/cpp/sci_grep.cpp
index 347fdff..b2d32de 100644
--- a/scilab/modules/string/sci_gateway/cpp/sci_grep.cpp
+++ b/scilab/modules/string/sci_gateway/cpp/sci_grep.cpp
@@ -121,38 +121,14 @@ types::Function::ReturnValue sci_grep(types::typed_list &in, int _iRetCount, typ
121 grepresults.positions = NULL; 121 grepresults.positions = NULL;
122 grepresults.values = NULL; 122 grepresults.values = NULL;
123 123
124 char** pStr1 = (char**)MALLOC(sizeof(char*) * pS1->getSize());
125 for (int i = 0 ; i < pS1->getSize() ; i++)
126 {
127 pStr1[i] = os_strdup(pS1->get(i));
128 }
129
130 char** pStr2 = (char**)MALLOC(sizeof(char*) * pS2->getSize());
131 for (int i = 0 ; i < pS2->getSize() ; i++)
132 {
133 pStr2[i] = os_strdup(pS2->get(i));
134 }
135
136 if (bRegularExpression) 124 if (bRegularExpression)
137 { 125 {
138 code_error_grep = GREP_NEW(&grepresults, pStr1, pS1->getSize(), pStr2, pS2->getSize()); 126 code_error_grep = GREP_NEW(&grepresults, pS1->get(), pS1->getSize(), pS2->get(), pS2->getSize());
139 } 127 }
140 else 128 else
141 { 129 {
142 code_error_grep = GREP_OLD(&grepresults, pStr1, pS1->getSize(), pStr2, pS2->getSize()); 130 code_error_grep = GREP_OLD(&grepresults, pS1->get(), pS1->getSize(), pS2->get(), pS2->getSize());
143 }
144
145 for (int i = 0; i < pS1->getSize(); i++)
146 {
147 FREE(pStr1[i]);
148 }
149 FREE(pStr1);
150
151 for (int i = 0; i < pS2->getSize(); i++)
152 {
153 FREE(pStr2[i]);
154 } 131 }
155 FREE(pStr2);
156 132
157 switch (code_error_grep) 133 switch (code_error_grep)
158 { 134 {
@@ -289,7 +265,6 @@ types::Function::ReturnValue sci_grep(types::typed_list &in, int _iRetCount, typ
289static int GREP_NEW(GREPRESULTS *results, char **Inputs_param_one, int mn_one, char **Inputs_param_two, int mn_two) 265static int GREP_NEW(GREPRESULTS *results, char **Inputs_param_one, int mn_one, char **Inputs_param_two, int mn_two)
290{ 266{
291 int x = 0, y = 0; 267 int x = 0, y = 0;
292 char *save = NULL;
293 int iRet = GREP_OK; 268 int iRet = GREP_OK;
294 pcre_error_code answer = PCRE_FINISHED_OK; 269 pcre_error_code answer = PCRE_FINISHED_OK;
295 for (x = 0; x < mn_one ; x++) 270 for (x = 0; x < mn_one ; x++)
@@ -322,8 +297,7 @@ static int GREP_NEW(GREPRESULTS *results, char **Inputs_param_one, int mn_one, c
322 { 297 {
323 int Output_Start = 0; 298 int Output_Start = 0;
324 int Output_End = 0; 299 int Output_End = 0;
325 save = os_strdup(Inputs_param_two[x]); 300 answer = pcre_private(Inputs_param_one[y], Inputs_param_two[x], &Output_Start, &Output_End, NULL, NULL);
326 answer = pcre_private(Inputs_param_one[y], save, &Output_Start, &Output_End, NULL, NULL);
327 301
328 if ( answer == PCRE_FINISHED_OK ) 302 if ( answer == PCRE_FINISHED_OK )
329 { 303 {
@@ -339,12 +313,6 @@ static int GREP_NEW(GREPRESULTS *results, char **Inputs_param_one, int mn_one, c
339 pcre_error("grep", answer); 313 pcre_error("grep", answer);
340 iRet = GREP_ERROR; 314 iRet = GREP_ERROR;
341 } 315 }
342
343 if (save)
344 {
345 FREE(save);
346 save = NULL;
347 }
348 } 316 }
349 } 317 }
350 318
diff --git a/scilab/modules/string/sci_gateway/cpp/sci_isascii.cpp b/scilab/modules/string/sci_gateway/cpp/sci_isascii.cpp
index 6420f75..3144dad 100644
--- a/scilab/modules/string/sci_gateway/cpp/sci_isascii.cpp
+++ b/scilab/modules/string/sci_gateway/cpp/sci_isascii.cpp
@@ -57,7 +57,7 @@ types::Function::ReturnValue sci_isascii(types::typed_list &in, int _iRetCount,
57 } 57 }
58 58
59 int iResultSize = 0; 59 int iResultSize = 0;
60 int* pbResult = (int*)isasciiStringW((wchar_t*)s.c_str(), &iResultSize); 60 int* pbResult = (int*)isasciiString(s.c_str(), &iResultSize);
61 if (pbResult == NULL) 61 if (pbResult == NULL)
62 { 62 {
63 out.push_back(types::Double::Empty()); 63 out.push_back(types::Double::Empty());
diff --git a/scilab/modules/string/sci_gateway/cpp/sci_length.cpp b/scilab/modules/string/sci_gateway/cpp/sci_length.cpp
index c65ca22..ae87fdc 100644
--- a/scilab/modules/string/sci_gateway/cpp/sci_length.cpp
+++ b/scilab/modules/string/sci_gateway/cpp/sci_length.cpp
@@ -112,7 +112,7 @@ static types::Double* lengthStrings(types::String* _pS)
112 112
113 for (int i = 0 ; i < _pS->getSize() ; i++) 113 for (int i = 0 ; i < _pS->getSize() ; i++)
114 { 114 {
115 pdbl[i] = static_cast<double>(strlen(pst[i])); 115 pdbl[i] = static_cast<double>(get_codepoint_count(pst[i]));
116 } 116 }
117 return pD; 117 return pD;
118} 118}
diff --git a/scilab/modules/string/sci_gateway/cpp/sci_regexp.cpp b/scilab/modules/string/sci_gateway/cpp/sci_regexp.cpp
index 5107339..7bd0f23 100644
--- a/scilab/modules/string/sci_gateway/cpp/sci_regexp.cpp
+++ b/scilab/modules/string/sci_gateway/cpp/sci_regexp.cpp
@@ -46,6 +46,7 @@ types::Function::ReturnValue sci_regexp(types::typed_list &in, int _iRetCount, t
46 int iPcreStatus = 0; 46 int iPcreStatus = 0;
47 int iStart = 0; 47 int iStart = 0;
48 int iStep = 0; 48 int iStep = 0;
49 int iwStep = 0;
49 int iEnd = 0; 50 int iEnd = 0;
50 int* piStart = NULL; 51 int* piStart = NULL;
51 int* piEnd = NULL; 52 int* piEnd = NULL;
@@ -133,9 +134,28 @@ types::Function::ReturnValue sci_regexp(types::typed_list &in, int _iRetCount, t
133 { 134 {
134 if (iEnd != iStart) 135 if (iEnd != iStart)
135 { 136 {
136 piStart[iOccurs] = iStart + iStep; 137 //convert strat and end to codepoint value
137 piEnd[iOccurs++] = iEnd + iStep; 138 char* pstTempStart = NULL;
138 iStep += iEnd; 139 char* pstTempEnd = NULL;
140 wchar_t* pwstTempStart = NULL;
141 wchar_t* pwstTempEnd = NULL;
142
143 pstTempStart = os_strdup(pstInput + iStep);
144 pstTempEnd = os_strdup(pstInput + iStep);
145 pstTempEnd[iEnd] = 0;
146 pstTempStart[iStart] = 0;
147
148
149 pwstTempStart = to_wide_string(pstTempStart);
150 pwstTempEnd = to_wide_string(pstTempEnd);
151
152 int iwStart = (int)wcslen(pwstTempStart);
153 int iwEnd = (int)wcslen(pwstTempEnd);
154
155 piStart[iOccurs] = iwStart + iwStep;
156 piEnd[iOccurs++] = iwEnd + iwStep;
157 iStep += iEnd;
158 iwStep += iwEnd;
139 } 159 }
140 else if (iEnd == 0 && pstInput[iStep] != '\0') 160 else if (iEnd == 0 && pstInput[iStep] != '\0')
141 { 161 {
@@ -220,11 +240,15 @@ types::Function::ReturnValue sci_regexp(types::typed_list &in, int _iRetCount, t
220 pS = new types::String(iOccurs, 1); 240 pS = new types::String(iOccurs, 1);
221 for (int i = 0 ; i < iOccurs ; i++) 241 for (int i = 0 ; i < iOccurs ; i++)
222 { 242 {
223 char* pstTemp = new char[piEnd[i] - piStart[i] + 1]; 243 wchar_t* pwstTemp = new wchar_t[piEnd[i] - piStart[i] + 1];
224 strncpy(pstTemp, pstInput + piStart[i], piEnd[i] - piStart[i]); 244 wchar_t* pwstInput = to_wide_string(pstInput);
225 pstTemp[piEnd[i] - piStart[i]] = 0; 245 wcsncpy(pwstTemp, pwstInput + piStart[i], piEnd[i] - piStart[i]);
246 pwstTemp[piEnd[i] - piStart[i]] = 0;
247 char* pstTemp = wide_string_to_UTF8(pwstTemp);
226 pS->set(i, 0, pstTemp); 248 pS->set(i, 0, pstTemp);
227 delete[] pstTemp; 249 delete[] pstTemp;
250 delete[] pwstInput;
251 delete[] pwstTemp;
228 } 252 }
229 } 253 }
230 out.push_back(pS); 254 out.push_back(pS);
diff --git a/scilab/modules/string/sci_gateway/cpp/sci_strcat.cpp b/scilab/modules/string/sci_gateway/cpp/sci_strcat.cpp
index a699796..2628ec0 100644
--- a/scilab/modules/string/sci_gateway/cpp/sci_strcat.cpp
+++ b/scilab/modules/string/sci_gateway/cpp/sci_strcat.cpp
@@ -80,13 +80,13 @@ types::Function::ReturnValue sci_strcat(types::typed_list &in, int _iRetCount, t
80 80
81 if (in.size() == 3) 81 if (in.size() == 3)
82 { 82 {
83 wchar_t wcMode = in[2]->getAs<types::String>()->get(0)[0]; 83 char mode = in[2]->getAs<types::String>()->get(0)[0];
84 switch (wcMode) 84 switch (mode)
85 { 85 {
86 case L'r' : 86 case 'r' :
87 iMode = 1; 87 iMode = 1;
88 break; 88 break;
89 case L'c' : 89 case 'c' :
90 iMode = 2; 90 iMode = 2;
91 break; 91 break;
92 default : 92 default :
diff --git a/scilab/modules/string/sci_gateway/cpp/sci_strchr.cpp b/scilab/modules/string/sci_gateway/cpp/sci_strchr.cpp
index 3309be0..6602df8 100644
--- a/scilab/modules/string/sci_gateway/cpp/sci_strchr.cpp
+++ b/scilab/modules/string/sci_gateway/cpp/sci_strchr.cpp
@@ -84,43 +84,40 @@ types::Function::ReturnValue sci_strchr(types::typed_list &in, int _iRetCount, t
84 { 84 {
85 j = i; /* Input parameter One & two have same dimension */ 85 j = i; /* Input parameter One & two have same dimension */
86 } 86 }
87 int iLen = (int)strlen(pCharSample->get(j)); 87
88 wchar_t* s = to_wide_string(pCharSample->get()[j]);
89 int iLen = (int)wcslen(s);
88 if (iLen != 1) 90 if (iLen != 1)
89 { 91 {
92 FREE(s);
90 Scierror(999, _("%s: Wrong type for input argument #%d: Char(s) expected.\n"), "strchr", 2); 93 Scierror(999, _("%s: Wrong type for input argument #%d: Char(s) expected.\n"), "strchr", 2);
91 delete pOutString; 94 delete pOutString;
92 return types::Function::Error; 95 return types::Function::Error;
93 } 96 }
94 97
95 if (strlen(pString->get(i)) < strlen(pCharSample->get(j))) 98
99 wchar_t* w = to_wide_string(pString->get()[i]);
100 if (wcslen(w) < wcslen(s))
96 { 101 {
97 pOutString->set(i, ""); 102 pOutString->set(i, "");
98 } 103 }
99 else 104 else
100 { 105 {
101 char* ptrstrstr = strchr(pString->get(i), pCharSample->get(j)[0]); 106 wchar_t* sc = wcschr(w, s[0]);
102 if (ptrstrstr) 107 if (sc)
103 { 108 {
104 pOutString->set(i, ptrstrstr); 109 char* output = wide_string_to_UTF8(sc);
105 if (pOutString->get(i) == NULL) 110 pOutString->set(i, output);
106 { 111 FREE(output);
107 delete pOutString;
108 FREE(ptrstrstr);
109 Scierror(999, _("%s: No more memory.\n"), "strchr");
110 return types::Function::Error;
111 }
112 } 112 }
113 else 113 else
114 { 114 {
115 pOutString->set(i, ""); 115 pOutString->set(i, "");
116 if (pOutString->get(i) == NULL)
117 {
118 delete pOutString;
119 Scierror(999, _("%s: No more memory.\n"), "strchr");
120 return types::Function::Error;
121 }
122 } 116 }
123 } 117 }
118
119 FREE(w);
120 FREE(s);
124 } 121 }
125 122
126 out.push_back(pOutString); 123 out.push_back(pOutString);
diff --git a/scilab/modules/string/sci_gateway/cpp/sci_strindex.cpp b/scilab/modules/string/sci_gateway/cpp/sci_strindex.cpp
index fb67ce9..9791320 100644
--- a/scilab/modules/string/sci_gateway/cpp/sci_strindex.cpp
+++ b/scilab/modules/string/sci_gateway/cpp/sci_strindex.cpp
@@ -125,20 +125,40 @@ types::Function::ReturnValue sci_strindex(types::typed_list &in, int _iRetCount,
125 { 125 {
126 //pcre 126 //pcre
127 pcre_error_code iPcreStatus = PCRE_FINISHED_OK; 127 pcre_error_code iPcreStatus = PCRE_FINISHED_OK;
128 for (int i = 0 ; i < pS->getSize() ; i++) 128 for (int i = 0; i < pS->getSize(); i++)
129 { 129 {
130 int iStart = 0; 130 int iStart = 0;
131 int iEnd = 0; 131 int iEnd = 0;
132 int iStep = 0; 132 int iStep = 0;
133 int iwStep = 0;
133 134
134 do 135 do
135 { 136 {
136 iPcreStatus = pcre_private(pstData + iStep, pstSearch[i], &iStart, &iEnd, NULL, NULL); 137 iPcreStatus = pcre_private(pstData + iStep, pstSearch[i], &iStart, &iEnd, NULL, NULL);
137 if (iPcreStatus == PCRE_FINISHED_OK) 138 if (iPcreStatus == PCRE_FINISHED_OK)
138 { 139 {
139 pstrResult[iValues].data = iStart + iStep + 1; 140 //convert strat and end to codepoint value
140 pstrResult[iValues].position = i + 1; 141 char* pstTempStart = NULL;
141 iStep += iEnd; 142 char* pstTempEnd = NULL;
143 wchar_t* pwstTempStart = NULL;
144 wchar_t* pwstTempEnd = NULL;
145
146 pstTempStart = os_strdup(pstData + iStep);
147 pstTempEnd = os_strdup(pstData + iStep);
148 pstTempEnd[iEnd] = 0;
149 pstTempStart[iStart] = 0;
150
151
152 pwstTempStart = to_wide_string(pstTempStart);
153 pwstTempEnd = to_wide_string(pstTempEnd);
154
155 int iwStart = (int)wcslen(pwstTempStart);
156 int iwEnd = (int)wcslen(pwstTempEnd);
157
158 pstrResult[iValues].data = iwStart + iwStep + 1;
159 pstrResult[iValues].position = i + 1;
160 iStep += iEnd;
161 iwStep += iwEnd;
142 iValues++; 162 iValues++;
143 } 163 }
144 else 164 else
@@ -151,27 +171,30 @@ types::Function::ReturnValue sci_strindex(types::typed_list &in, int _iRetCount,
151 } 171 }
152 break; 172 break;
153 } 173 }
154 } 174 } while (iPcreStatus == PCRE_FINISHED_OK && iStart != iEnd);
155 while (iPcreStatus == PCRE_FINISHED_OK && iStart != iEnd);
156 } 175 }
157 } 176 }
158 else 177 else
159 { 178 {
160 for (int i = 0 ; i < pS->getSize() ; i++) 179 for (int i = 0 ; i < pS->getSize() ; i++)
161 { 180 {
162 char* pCur = pstData; 181 wchar_t* pwstData = to_wide_string(pstData);
182 wchar_t* pCur = pwstData;
183 wchar_t* pwstSearch = to_wide_string(pstSearch[i]);
163 do 184 do
164 { 185 {
165 pCur = strstr(pCur, pstSearch[i]); 186 pCur = wcsstr(pCur, pwstSearch);
166 if (pCur != NULL) 187 if (pCur != NULL)
167 { 188 {
168 pstrResult[iValues].data = (int)(pCur - pstData + 1); 189 pstrResult[iValues].data = (int)(pCur - pwstData + 1);
169 pstrResult[iValues].position = i + 1; 190 pstrResult[iValues].position = i + 1;
170 pCur++; 191 pCur++;
171 iValues++; 192 iValues++;
172 } 193 }
173 } 194 } while (pCur != NULL && pCur[0] != L'\0');
174 while (pCur != NULL && pCur[0] != L'\0'); 195
196 FREE(pwstSearch);
197 FREE(pwstData);
175 } 198 }
176 } 199 }
177 200
diff --git a/scilab/modules/string/sci_gateway/cpp/sci_strncpy.cpp b/scilab/modules/string/sci_gateway/cpp/sci_strncpy.cpp
index dcf6d83..d5ff868 100644
--- a/scilab/modules/string/sci_gateway/cpp/sci_strncpy.cpp
+++ b/scilab/modules/string/sci_gateway/cpp/sci_strncpy.cpp
@@ -76,7 +76,8 @@ types::Function::ReturnValue sci_strncpy(types::typed_list &in, int _iRetCount,
76 int j = 0; /* Input parameter two is dimension one */ 76 int j = 0; /* Input parameter two is dimension one */
77 for (int i = 0 ; i < pString->getSize() ; i++) 77 for (int i = 0 ; i < pString->getSize() ; i++)
78 { 78 {
79 char* output = NULL; 79 wchar_t* input = to_wide_string(pString->get(i));
80 wchar_t* output = NULL;
80 int sizeOfCopy = 0; 81 int sizeOfCopy = 0;
81 82
82 if (pDouble->isScalar() == false) 83 if (pDouble->isScalar() == false)
@@ -84,7 +85,7 @@ types::Function::ReturnValue sci_strncpy(types::typed_list &in, int _iRetCount,
84 j = i; /* Input parameter One & two have same dimension */ 85 j = i; /* Input parameter One & two have same dimension */
85 } 86 }
86 87
87 if (pDouble->get(j) < strlen(pString->get(i))) 88 if (pDouble->get(j) < wcslen(input))
88 { 89 {
89 int iLen = (int)pDouble->get(j); 90 int iLen = (int)pDouble->get(j);
90 if (iLen < 0) 91 if (iLen < 0)
@@ -92,27 +93,31 @@ types::Function::ReturnValue sci_strncpy(types::typed_list &in, int _iRetCount,
92 iLen = 0; 93 iLen = 0;
93 } 94 }
94 95
95 output = (char*)MALLOC(sizeof(char) * (iLen + 1)); 96 output = (wchar_t*)MALLOC(sizeof(wchar_t) * (iLen + 1));
96 sizeOfCopy = iLen; 97 sizeOfCopy = iLen;
97 } 98 }
98 else 99 else
99 { 100 {
100 int iLen = (int)strlen(pString->get(i)); 101 int iLen = (int)wcslen(input);
101 output = (char*)MALLOC(sizeof(char) * (iLen + 1)); 102 output = (wchar_t*)MALLOC(sizeof(wchar_t) * (iLen + 1));
102 sizeOfCopy = iLen; 103 sizeOfCopy = iLen;
103 } 104 }
104 105
105 if (output) 106 if (output)
106 { 107 {
107 strncpy(output, pString->get(i), sizeOfCopy); 108 wcsncpy(output, input, sizeOfCopy);
108 output[sizeOfCopy] = '\0'; 109 output[sizeOfCopy] = '\0';
109 110
110 pOutString->set(i, output); 111 char* o = wide_string_to_UTF8(output);
112 pOutString->set(i, o);
113 FREE(input);
114 FREE(o);
111 FREE(output); 115 FREE(output);
112 output = NULL; 116 output = NULL;
113 } 117 }
114 else 118 else
115 { 119 {
120 FREE(input);
116 delete pOutString; 121 delete pOutString;
117 Scierror(999, _("%s: No more memory.\n"), "strncpy"); 122 Scierror(999, _("%s: No more memory.\n"), "strncpy");
118 return types::Function::Error; 123 return types::Function::Error;
diff --git a/scilab/modules/string/sci_gateway/cpp/sci_strrchr.cpp b/scilab/modules/string/sci_gateway/cpp/sci_strrchr.cpp
index b376a05..ee8368c 100644
--- a/scilab/modules/string/sci_gateway/cpp/sci_strrchr.cpp
+++ b/scilab/modules/string/sci_gateway/cpp/sci_strrchr.cpp
@@ -87,43 +87,40 @@ types::Function::ReturnValue sci_strrchr(types::typed_list &in, int _iRetCount,
87 { 87 {
88 j = i; /* Input parameter One & two have same dimension */ 88 j = i; /* Input parameter One & two have same dimension */
89 } 89 }
90 int iLen = (int)strlen(pCharSample->get(j)); 90
91 wchar_t* s = to_wide_string(pCharSample->get()[j]);
92 int iLen = (int)wcslen(s);
91 if (iLen != 1) 93 if (iLen != 1)
92 { 94 {
95 FREE(s);
93 Scierror(999, _("%s: Wrong type for input argument #%d: Char(s) expected.\n"), "strrchr", 2); 96 Scierror(999, _("%s: Wrong type for input argument #%d: Char(s) expected.\n"), "strrchr", 2);
94 delete pOutString; 97 delete pOutString;
95 return types::Function::Error; 98 return types::Function::Error;
96 } 99 }
97 100
98 if (strlen(pString->get(i)) < strlen(pCharSample->get(j))) 101 wchar_t* w = to_wide_string(pString->get()[i]);
102 if (wcslen(w) < wcslen(s))
99 { 103 {
100 pOutString->set(i, ""); 104 pOutString->set(i, "");
101 } 105 }
102 else 106 else
103 { 107 {
108 wchar_t* sc = wcsrchr(w, s[0]);
104 char* ptrstrstr = strrchr(pString->get(i), pCharSample->get(j)[0]); 109 char* ptrstrstr = strrchr(pString->get(i), pCharSample->get(j)[0]);
105 if (ptrstrstr) 110 if (sc)
106 { 111 {
107 pOutString->set(i, ptrstrstr); 112 char* output = wide_string_to_UTF8(sc);
108 if (pOutString->get(i) == NULL) 113 pOutString->set(i, output);
109 { 114 FREE(output);
110 delete pOutString;
111 FREE(ptrstrstr);
112 Scierror(999, _("%s: No more memory.\n"), "strrchr");
113 return types::Function::Error;
114 }
115 } 115 }
116 else 116 else
117 { 117 {
118 pOutString->set(i, ""); 118 pOutString->set(i, "");
119 if (pOutString->get(i) == NULL)
120 {
121 delete pOutString;
122 Scierror(999, _("%s: No more memory.\n"), "strrchr");
123 return types::Function::Error;
124 }
125 } 119 }
126 } 120 }
121
122 FREE(w);
123 FREE(s);
127 } 124 }
128 125
129 out.push_back(pOutString); 126 out.push_back(pOutString);
diff --git a/scilab/modules/string/sci_gateway/cpp/sci_strspn.cpp b/scilab/modules/string/sci_gateway/cpp/sci_strspn.cpp
index 85f426f..7a10a78 100644
--- a/scilab/modules/string/sci_gateway/cpp/sci_strspn.cpp
+++ b/scilab/modules/string/sci_gateway/cpp/sci_strspn.cpp
@@ -71,7 +71,12 @@ types::Function::ReturnValue sci_strspn(types::typed_list &in, int _iRetCount, t
71 j = i; 71 j = i;
72 } 72 }
73 73
74 pOutDouble->set(i, (double)strspn( pString->get(i), pStrSample->get(j))); 74 wchar_t* w = to_wide_string(pString->get()[i]);
75 wchar_t* s = to_wide_string(pStrSample->get()[j]);
76
77 pOutDouble->set(i, (double)wcsspn(w, s));
78 FREE(s);
79 FREE(w);
75 } 80 }
76 81
77 out.push_back(pOutDouble); 82 out.push_back(pOutDouble);
diff --git a/scilab/modules/string/sci_gateway/cpp/sci_tokens.cpp b/scilab/modules/string/sci_gateway/cpp/sci_tokens.cpp
index 877278b..105c634 100644
--- a/scilab/modules/string/sci_gateway/cpp/sci_tokens.cpp
+++ b/scilab/modules/string/sci_gateway/cpp/sci_tokens.cpp
@@ -26,6 +26,7 @@ extern "C"
26#include "core_math.h" 26#include "core_math.h"
27#include "localization.h" 27#include "localization.h"
28#include "Scierror.h" 28#include "Scierror.h"
29#include "charEncoding.h"
29} 30}
30 31
31#include <sciprint.h> 32#include <sciprint.h>
@@ -35,8 +36,9 @@ types::Function::ReturnValue sci_tokens(types::typed_list &in, int _iRetCount, t
35 types::String* pOutString = NULL; 36 types::String* pOutString = NULL;
36 types::String* pString = NULL; 37 types::String* pString = NULL;
37 types::String* pCharSample = NULL; 38 types::String* pCharSample = NULL;
38 char* seps = NULL; 39 wchar_t* seps = NULL;
39 int sizeSeps = 0; 40 wchar_t* input = NULL;
41 int sizeSeps = 0;
40 42
41 if (in.size() > 2 || in.size() == 0) 43 if (in.size() > 2 || in.size() == 0)
42 { 44 {
@@ -84,25 +86,30 @@ types::Function::ReturnValue sci_tokens(types::typed_list &in, int _iRetCount, t
84 return types::Function::Error; 86 return types::Function::Error;
85 } 87 }
86 sizeSeps = pCharSample->getSize(); 88 sizeSeps = pCharSample->getSize();
87 seps = (char*)MALLOC((sizeSeps + 1) * sizeof(char)); 89 seps = (wchar_t*)MALLOC((sizeSeps + 1) * sizeof(wchar_t));
88 for (int i = 0; i < sizeSeps ; i++) 90 for (int i = 0; i < sizeSeps ; i++)
89 { 91 {
90 int iLen = (int)strlen(pCharSample->get(i)); 92 wchar_t* t = to_wide_string(pCharSample->get()[i]);
93 int iLen = (int)wcslen(t);
91 if (iLen > 1 || iLen < 0) 94 if (iLen > 1 || iLen < 0)
92 { 95 {
96 FREE(t);
97 FREE(seps);
93 Scierror(999, _("%s: Wrong type for input argument #%d: Char(s) expected.\n"), "tokens", 2); 98 Scierror(999, _("%s: Wrong type for input argument #%d: Char(s) expected.\n"), "tokens", 2);
94 delete pOutString; 99 delete pOutString;
95 return types::Function::Error; 100 return types::Function::Error;
96 } 101 }
97 seps[i] = pCharSample->get(i)[0]; 102
103 seps[i] = t[0];
104 FREE(t);
98 } 105 }
99 } 106 }
100 else // default delimiters are ' ' and Tabulation 107 else // default delimiters are ' ' and Tabulation
101 { 108 {
102 sizeSeps = 2; 109 sizeSeps = 2;
103 seps = (char*)MALLOC((sizeSeps + 1) * sizeof(char)); 110 seps = (wchar_t*)MALLOC((sizeSeps + 1) * sizeof(wchar_t));
104 seps[0] = ' '; 111 seps[0] = L' ';
105 seps[1] = '\t'; 112 seps[1] = L'\t';
106 } 113 }
107 114
108 seps[sizeSeps] = '\0'; 115 seps[sizeSeps] = '\0';
@@ -111,7 +118,8 @@ types::Function::ReturnValue sci_tokens(types::typed_list &in, int _iRetCount, t
111 int dimsArray[2] = {0, 1}; 118 int dimsArray[2] = {0, 1};
112 int dims = 2; 119 int dims = 2;
113 120
114 char** Output_Strings = stringTokens(pString->get(0), seps, &dimsArray[0]); 121 input = to_wide_string(pString->get()[0]);
122 wchar_t** Output_Strings = stringTokens(input, seps, &dimsArray[0]);
115 FREE(seps); 123 FREE(seps);
116 if (Output_Strings == NULL) 124 if (Output_Strings == NULL)
117 { 125 {
@@ -122,11 +130,12 @@ types::Function::ReturnValue sci_tokens(types::typed_list &in, int _iRetCount, t
122 else 130 else
123 { 131 {
124 pOutString = new types::String(dims, dimsArray); 132 pOutString = new types::String(dims, dimsArray);
125 pOutString->set(Output_Strings);
126
127 for (int i = 0 ; i < dimsArray[0] ; i++) 133 for (int i = 0 ; i < dimsArray[0] ; i++)
128 { 134 {
135 char* c = wide_string_to_UTF8(Output_Strings[i]);
136 pOutString->set(i, c);
129 FREE(Output_Strings[i]); 137 FREE(Output_Strings[i]);
138 FREE(c);
130 } 139 }
131 FREE(Output_Strings); 140 FREE(Output_Strings);
132 } 141 }
diff --git a/scilab/modules/string/src/c/StringConvert.c b/scilab/modules/string/src/c/StringConvert.c
index 8037014..d9ac379 100644
--- a/scilab/modules/string/src/c/StringConvert.c
+++ b/scilab/modules/string/src/c/StringConvert.c
@@ -59,50 +59,3 @@ int StringConvert(char *str)
59 return count; 59 return count;
60} 60}
61/*--------------------------------------------------------------------------*/ 61/*--------------------------------------------------------------------------*/
62int StringConvertW(wchar_t *str)
63/* changes `\``n` --> `\n` idem for \t and \r */
64{
65 wchar_t *str1;
66 int count = 0;
67 str1 = str;
68
69 while ( *str != 0)
70 {
71 if ( *str == L'\\' )
72 {
73 switch ( *(str + 1))
74 {
75 case L'n' :
76 *str1 = L'\n' ;
77 str1++;
78 str += 2;
79 count++;
80 break;
81 case L't' :
82 *str1 = L'\t' ;
83 str1++;
84 str += 2;
85 break;
86 case L'r' :
87 *str1 = L'\r' ;
88 str1++;
89 str += 2;
90 break;
91 default :
92 *str1 = *str;
93 str1++;
94 str++;
95 break;
96 }
97 }
98 else
99 {
100 *str1 = *str;
101 str1++;
102 str++;
103 }
104 }
105 *str1 = L'\0';
106 return count;
107}
108/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/string/src/c/convstr.c b/scilab/modules/string/src/c/convstr.c
deleted file mode 100644
index 07be68a..0000000
--- a/scilab/modules/string/src/c/convstr.c
+++ /dev/null
@@ -1,47 +0,0 @@
1
2/*
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) INRIA - Cong WU
5 * Copyright (C) INRIA - Allan CORNET
6 *
7 * This file must be used under the terms of the CeCILL.
8 * This source file is licensed as described in the file COPYING, which
9 * you should have received as part of this distribution. The terms
10 * are also available at
11 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
12 *
13 */
14
15/*--------------------------------------------------------------------------*/
16#include <string.h>
17#include <stdio.h>
18#include <ctype.h>
19#include <wchar.h>
20#include <wctype.h>
21#include "convstr.h"
22/*--------------------------------------------------------------------------*/
23void convstr(wchar_t **Input_Matrix, wchar_t **Output_Matrix, char typ, int mn)
24{
25 int x = 0;
26 for (x = 0 ; x < mn; x++)
27 {
28 int y = 0;
29 size_t len_Input_Matrix = wcslen(Input_Matrix[x]);
30 for (y = 0; y < len_Input_Matrix; y++)
31 {
32 /*To traverse every string in the string matrix */
33 if ( (typ == UPPER) || (typ == UPPER_B) )
34 {
35 /*converts the matrix of strings str-matrix into upper case */
36 Output_Matrix[x][y] = (wchar_t) towupper(Input_Matrix[x][y]);
37 }
38 else if ( (typ == LOW) || (typ == LOW_B) )
39 {
40 /*converts the matrix of strings str-matrix into lower case */
41 Output_Matrix[x][y] = (wchar_t) towlower(Input_Matrix[x][y]);
42 }
43 }
44 Output_Matrix[x][y] = 0;
45 }
46}
47/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/string/src/c/convstr.h b/scilab/modules/string/src/c/convstr.h
deleted file mode 100644
index 5fec504..0000000
--- a/scilab/modules/string/src/c/convstr.h
+++ /dev/null
@@ -1,36 +0,0 @@
1
2/*
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) INRIA - Allan CORNET
5 *
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
11 *
12 */
13
14/*--------------------------------------------------------------------------*/
15#ifndef __CONVSTR_H__
16#define __CONVSTR_H__
17
18#include "dynlib_string.h"
19
20#define LOW 'l'
21#define LOW_B 'L'
22#define UPPER 'u'
23#define UPPER_B 'U'
24
25/**
26* convstr case conversion
27* param[in] Input_Matrix Input string matrix
28* param[out] Output_Matrix
29* param[in] typ 'l' or 'u' means low or upper
30* param[in] Number_Input the number of input string matrix
31*/
32STRING_IMPEXP void convstr(wchar_t **Input_Matrix, wchar_t **Output_Matrix, char typ, int Number_Input);
33
34#endif /* __CONVSTR_H__ */
35/*--------------------------------------------------------------------------*/
36
diff --git a/scilab/modules/string/src/c/isalphanum.c b/scilab/modules/string/src/c/isalphanum.c
index 1cee546..fdab941 100644
--- a/scilab/modules/string/src/c/isalphanum.c
+++ b/scilab/modules/string/src/c/isalphanum.c
@@ -16,6 +16,8 @@
16#include <ctype.h> 16#include <ctype.h>
17#include "isalphanum.h" 17#include "isalphanum.h"
18#include "sci_malloc.h" 18#include "sci_malloc.h"
19#include "charEncoding.h"
20
19/*--------------------------------------------------------------------------*/ 21/*--------------------------------------------------------------------------*/
20BOOL *isalphanum(const char* input_string, int *returnedSize) 22BOOL *isalphanum(const char* input_string, int *returnedSize)
21{ 23{
@@ -25,7 +27,8 @@ BOOL *isalphanum(const char* input_string, int *returnedSize)
25 if (input_string) 27 if (input_string)
26 { 28 {
27 int i = 0; 29 int i = 0;
28 int length_input_string = (int)strlen(input_string); 30 wchar_t* in = to_wide_string(input_string);
31 int length_input_string = (int)wcslen(in);
29 *returnedSize = length_input_string; 32 *returnedSize = length_input_string;
30 33
31 if (length_input_string > 0) 34 if (length_input_string > 0)
@@ -35,7 +38,7 @@ BOOL *isalphanum(const char* input_string, int *returnedSize)
35 { 38 {
36 for (i = 0; i < length_input_string; i++) 39 for (i = 0; i < length_input_string; i++)
37 { 40 {
38 if (isalnum(input_string[i])) 41 if (iswalnum(in[i]))
39 { 42 {
40 returnedValues[i] = TRUE; 43 returnedValues[i] = TRUE;
41 } 44 }
@@ -46,6 +49,8 @@ BOOL *isalphanum(const char* input_string, int *returnedSize)
46 } 49 }
47 } 50 }
48 } 51 }
52
53 FREE(in);
49 } 54 }
50 return returnedValues; 55 return returnedValues;
51} 56}
diff --git a/scilab/modules/string/src/c/isascii.c b/scilab/modules/string/src/c/isascii.c
index 3962e73..db80045 100644
--- a/scilab/modules/string/src/c/isascii.c
+++ b/scilab/modules/string/src/c/isascii.c
@@ -15,8 +15,14 @@
15#include <string.h> 15#include <string.h>
16#include "isascii.h" 16#include "isascii.h"
17#include "sci_malloc.h" 17#include "sci_malloc.h"
18#include "charEncoding.h"
19
20#ifdef _MSC_VER
21#include <ctype.h>
22#define isascii __isascii
23#endif
18/*--------------------------------------------------------------------------*/ 24/*--------------------------------------------------------------------------*/
19BOOL* isasciiStringW(wchar_t* input_string, int* returnedSize) 25BOOL* isasciiStringW(const wchar_t* input_string, int* returnedSize)
20{ 26{
21 BOOL *returnedValues = NULL; 27 BOOL *returnedValues = NULL;
22 *returnedSize = 0; 28 *returnedSize = 0;
@@ -34,7 +40,7 @@ BOOL* isasciiStringW(wchar_t* input_string, int* returnedSize)
34 { 40 {
35 for (i = 0; i < length_input_string; i++) 41 for (i = 0; i < length_input_string; i++)
36 { 42 {
37 if ( iswascii(input_string[i]) ) 43 if (iswascii(input_string[i]))
38 { 44 {
39 returnedValues[i] = TRUE; 45 returnedValues[i] = TRUE;
40 } 46 }
@@ -48,6 +54,14 @@ BOOL* isasciiStringW(wchar_t* input_string, int* returnedSize)
48 } 54 }
49 return returnedValues; 55 return returnedValues;
50} 56}
57/*--------------------------------------------------------------------------*/
58BOOL* isasciiString(const char* input_string, int* returnedSize)
59{
60 wchar_t* ws = to_wide_string(input_string);
61 BOOL* ret = isasciiStringW(ws, returnedSize);
62 FREE(ws);
63 return ret;
64}
51 65
52BOOL* isasciiMatrix(double* inputValues, int inputSize) 66BOOL* isasciiMatrix(double* inputValues, int inputSize)
53{ 67{
diff --git a/scilab/modules/string/src/c/isascii.h b/scilab/modules/string/src/c/isascii.h
index a9aa254..35f5ae0 100644
--- a/scilab/modules/string/src/c/isascii.h
+++ b/scilab/modules/string/src/c/isascii.h
@@ -23,7 +23,7 @@
23 23
24#include "dynlib_string.h" 24#include "dynlib_string.h"
25 25
26STRING_IMPEXP BOOL* isasciiStringW(wchar_t* input_string, int* returnedSize); 26STRING_IMPEXP BOOL* isasciiString(const char* input_string, int* returnedSize);
27STRING_IMPEXP BOOL* isasciiMatrix(double* input_string, int matrixSize); 27STRING_IMPEXP BOOL* isasciiMatrix(double* input_string, int matrixSize);
28 28
29#endif /* __ISASCII_H__ */ 29#endif /* __ISASCII_H__ */
diff --git a/scilab/modules/string/src/c/isdigit.c b/scilab/modules/string/src/c/isdigit.c
index 29732f2..a1f0774 100644
--- a/scilab/modules/string/src/c/isdigit.c
+++ b/scilab/modules/string/src/c/isdigit.c
@@ -16,6 +16,8 @@
16#include "isletter.h" 16#include "isletter.h"
17#include "sci_malloc.h" 17#include "sci_malloc.h"
18#include "isdigit.h" 18#include "isdigit.h"
19#include "charEncoding.h"
20
19/*--------------------------------------------------------------------------*/ 21/*--------------------------------------------------------------------------*/
20BOOL *IsDigit(const char* input_string, int *returnedSizeArray) 22BOOL *IsDigit(const char* input_string, int *returnedSizeArray)
21{ 23{
@@ -25,7 +27,9 @@ BOOL *IsDigit(const char* input_string, int *returnedSizeArray)
25 if (input_string) 27 if (input_string)
26 { 28 {
27 int i = 0; 29 int i = 0;
28 int length_input_string = (int)strlen(input_string); 30 wchar_t* in = to_wide_string(input_string);
31 int length_input_string = (int)wcslen(in);
32
29 *returnedSizeArray = length_input_string; 33 *returnedSizeArray = length_input_string;
30 34
31 if (length_input_string > 0) 35 if (length_input_string > 0)
@@ -35,7 +39,7 @@ BOOL *IsDigit(const char* input_string, int *returnedSizeArray)
35 { 39 {
36 for (i = 0; i < length_input_string; i++) 40 for (i = 0; i < length_input_string; i++)
37 { 41 {
38 if (isdigit(input_string[i])) 42 if (iswdigit(in[i]))
39 { 43 {
40 returnedValues[i] = TRUE; 44 returnedValues[i] = TRUE;
41 } 45 }
@@ -46,6 +50,8 @@ BOOL *IsDigit(const char* input_string, int *returnedSizeArray)
46 } 50 }
47 } 51 }
48 } 52 }
53
54 FREE(in);
49 } 55 }
50 return returnedValues; 56 return returnedValues;
51} 57}
diff --git a/scilab/modules/string/src/c/isletter.c b/scilab/modules/string/src/c/isletter.c
index 6b1dba8..44ccd68 100644
--- a/scilab/modules/string/src/c/isletter.c
+++ b/scilab/modules/string/src/c/isletter.c
@@ -17,6 +17,7 @@
17#include <wctype.h> /* iswalpha */ 17#include <wctype.h> /* iswalpha */
18#include "isletter.h" 18#include "isletter.h"
19#include "sci_malloc.h" 19#include "sci_malloc.h"
20#include "charEncoding.h"
20 21
21/*--------------------------------------------------------------------------*/ 22/*--------------------------------------------------------------------------*/
22BOOL *isletter(char *input_string, int *sizeArray) 23BOOL *isletter(char *input_string, int *sizeArray)
@@ -25,49 +26,19 @@ BOOL *isletter(char *input_string, int *sizeArray)
25 if (input_string) 26 if (input_string)
26 { 27 {
27 int i = 0; 28 int i = 0;
28 int length_input_string = (int)strlen(input_string); 29 wchar_t* in = to_wide_string(input_string);
29 *sizeArray = length_input_string; 30 int len = (int)wcslen(in);
30 31
31 if (length_input_string > 0) 32 *sizeArray = len;
32 {
33 returnedValues = (BOOL*)MALLOC(sizeof(BOOL) * length_input_string);
34 if (returnedValues)
35 {
36 for (i = 0; i < length_input_string; i++)
37 {
38 if ( isalpha(input_string[i]) )
39 {
40 returnedValues[i] = TRUE;
41 }
42 else
43 {
44 returnedValues[i] = FALSE;
45 }
46 }
47 }
48 }
49 }
50 return returnedValues;
51}
52/*--------------------------------------------------------------------------*/
53BOOL *isletterW(wchar_t *wcInput_string, int *sizeArray)
54{
55 BOOL *returnedValues = NULL;
56 if (wcInput_string)
57 {
58 int i = 0;
59 int length_input_string = (int)wcslen(wcInput_string);
60
61 *sizeArray = length_input_string;
62 33
63 if (length_input_string > 0) 34 if (len > 0)
64 { 35 {
65 returnedValues = (BOOL*)MALLOC(sizeof(BOOL) * length_input_string); 36 returnedValues = (BOOL*)MALLOC(sizeof(BOOL) * len);
66 if (returnedValues) 37 if (returnedValues)
67 { 38 {
68 for (i = 0; i < length_input_string; i++) 39 for (i = 0; i < len; i++)
69 { 40 {
70 if ( iswalpha(wcInput_string[i]) ) 41 if (iswalpha(in[i]))
71 { 42 {
72 returnedValues[i] = TRUE; 43 returnedValues[i] = TRUE;
73 } 44 }
@@ -78,6 +49,8 @@ BOOL *isletterW(wchar_t *wcInput_string, int *sizeArray)
78 } 49 }
79 } 50 }
80 } 51 }
52
53 FREE(in);
81 } 54 }
82 return returnedValues; 55 return returnedValues;
83} 56}
diff --git a/scilab/modules/string/src/c/isletter.h b/scilab/modules/string/src/c/isletter.h
index 08d44ae..f7a84d8 100644
--- a/scilab/modules/string/src/c/isletter.h
+++ b/scilab/modules/string/src/c/isletter.h
@@ -27,12 +27,5 @@
27*/ 27*/
28STRING_IMPEXP BOOL *isletter(char *input_string, int *sizeArray); 28STRING_IMPEXP BOOL *isletter(char *input_string, int *sizeArray);
29 29
30/**
31* array elements that are alphabetic letters
32* @param[in] a string
33* @return BOOL array
34*/
35STRING_IMPEXP BOOL *isletterW(wchar_t *wcInput_string, int *sizeArray);
36
37#endif /* __ISLETTER_H__ */ 30#endif /* __ISLETTER_H__ */
38/*--------------------------------------------------------------------------*/ 31/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/string/src/c/isnum.c b/scilab/modules/string/src/c/isnum.c
index d04bbdd..a27ac52 100644
--- a/scilab/modules/string/src/c/isnum.c
+++ b/scilab/modules/string/src/c/isnum.c
@@ -42,34 +42,5 @@ BOOL *isNumMatrix(const char **pStrs, int nbRows, int nbCols)
42 return pResults; 42 return pResults;
43} 43}
44// ============================================================================= 44// =============================================================================
45BOOL isNumW(const wchar_t* pStr)
46{
47 if (pStr)
48 {
49 stringToComplexError ierr = STRINGTOCOMPLEX_NO_ERROR;
50 stringToComplexW(pStr, L".", FALSE, &ierr);
51 return (BOOL)(ierr == STRINGTOCOMPLEX_NO_ERROR);
52 }
53 return FALSE;
54}
55// =============================================================================
56BOOL *isNumMatrixW(const wchar_t** pStrs, int nbRows, int nbCols)
57{
58 BOOL *pResults = NULL;
59 if (pStrs)
60 {
61 pResults = (BOOL*)MALLOC(sizeof(BOOL) * (nbCols * nbRows));
62 if (pResults)
63 {
64 int i = 0;
65 for (i = 0; i < nbRows * nbCols; i++)
66 {
67 pResults[i] = isNumW(pStrs[i]);
68 }
69 }
70 }
71 return pResults;
72}
73// =============================================================================
74 45
75 46
diff --git a/scilab/modules/string/src/c/isnum.h b/scilab/modules/string/src/c/isnum.h
index 2831c0c..a69db44 100644
--- a/scilab/modules/string/src/c/isnum.h
+++ b/scilab/modules/string/src/c/isnum.h
@@ -23,11 +23,6 @@ extern "C" {
23 STRING_IMPEXP BOOL isNum(const char *pStr); 23 STRING_IMPEXP BOOL isNum(const char *pStr);
24 24
25 STRING_IMPEXP BOOL *isNumMatrix(const char **pStrs, int nbRows, int nbCols); 25 STRING_IMPEXP BOOL *isNumMatrix(const char **pStrs, int nbRows, int nbCols);
26
27 STRING_IMPEXP BOOL isNumW(const wchar_t *pStr);
28
29 STRING_IMPEXP BOOL *isNumMatrixW(const wchar_t **pStrs, int nbRows, int nbCols);
30
31#ifdef __cplusplus 26#ifdef __cplusplus
32} 27}
33#endif 28#endif
diff --git a/scilab/modules/string/src/c/partfunction.c b/scilab/modules/string/src/c/partfunction.c
index d43320c..d31eddf 100644
--- a/scilab/modules/string/src/c/partfunction.c
+++ b/scilab/modules/string/src/c/partfunction.c
@@ -70,31 +70,3 @@ char **partfunction(const char** stringInput, int m, int n, int *vectInput, int
70 return parts; 70 return parts;
71} 71}
72/*--------------------------------------------------------------------------*/ 72/*--------------------------------------------------------------------------*/
73wchar_t **partfunctionW(wchar_t** _pwstStringInput, int _iRows, int _iCols, int *_piVectInput, int _iVectSize)
74{
75 int i, j;
76 wchar_t **pwstParts = NULL;
77 int iSize = _iRows * _iCols;
78
79 pwstParts = (wchar_t**)MALLOC(sizeof(wchar_t*) * (iSize));
80
81 for (i = 0 ; i < iSize ; i++)
82 {
83 pwstParts[i] = (wchar_t*)MALLOC(sizeof(wchar_t) * (_iVectSize + 1));
84
85 for (j = 0 ; j < _iVectSize ; j++)
86 {
87 if (_piVectInput[j] > wcslen(_pwstStringInput[i]))
88 {
89 pwstParts[i][j] = L' ';
90 }
91 else
92 {
93 pwstParts[i][j] = _pwstStringInput[i][_piVectInput[j] - 1];
94 }
95 }
96 pwstParts[i][j] = '\0';
97 }
98 return pwstParts;
99}
100/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/string/src/c/partfunction.h b/scilab/modules/string/src/c/partfunction.h
index b0143ac..2375b1e 100644
--- a/scilab/modules/string/src/c/partfunction.h
+++ b/scilab/modules/string/src/c/partfunction.h
@@ -25,7 +25,5 @@
25*/ 25*/
26STRING_IMPEXP char **partfunction(const char** stringInput, int m, int n, int *vectInput, int row); 26STRING_IMPEXP char **partfunction(const char** stringInput, int m, int n, int *vectInput, int row);
27 27
28STRING_IMPEXP wchar_t **partfunctionW(wchar_t** _pwstStringInput, int _iRows, int _iCols, int *_piVectInput, int _iVectSize);
29
30#endif /* __PARTFUNCTION_H__ */ 28#endif /* __PARTFUNCTION_H__ */
31/*---------------------------------------------------------------------------*/ 29/*---------------------------------------------------------------------------*/
diff --git a/scilab/modules/string/src/c/pcre_private.c b/scilab/modules/string/src/c/pcre_private.c
index 08ba827..d2f0609 100644
--- a/scilab/modules/string/src/c/pcre_private.c
+++ b/scilab/modules/string/src/c/pcre_private.c
@@ -173,7 +173,7 @@ static int check_match_limit(pcre *re, pcre_extra *extra, char *bptr, int len,
173consist of a regular expression, in delimiters and optionally followed by 173consist of a regular expression, in delimiters and optionally followed by
174options, followed by a set of test data, terminated by an empty line. */ 174options, followed by a set of test data, terminated by an empty line. */
175 175
176pcre_error_code pcre_private(char *INPUT_LINE, char *INPUT_PAT, int *Output_Start, int *Output_End, char*** _pstCapturedString, int* _piCapturedStringCount) 176pcre_error_code pcre_private(const char *INPUT_LINE, const char *INPUT_PAT, int *Output_Start, int *Output_End, char*** _pstCapturedString, int* _piCapturedStringCount)
177{ 177{
178 /* ALL strings are managed as UTF-8 by default */ 178 /* ALL strings are managed as UTF-8 by default */
179 int options = PCRE_UTF8; 179 int options = PCRE_UTF8;
@@ -1148,66 +1148,3 @@ SKIP_DATA:
1148 return PCRE_EXIT; 1148 return PCRE_EXIT;
1149} 1149}
1150/*-------------------------------------------------------------------------------*/ 1150/*-------------------------------------------------------------------------------*/
1151pcre_error_code wide_pcre_private(wchar_t* _pwstInput, wchar_t* _pwstPattern, int* _piStart, int* _piEnd, wchar_t*** _pstCapturedString, int* _piCapturedStringCount)
1152{
1153 pcre_error_code iPcreStatus = PCRE_FINISHED_OK;
1154 int i = 0;
1155 int iStart = 0;
1156 int iEnd = 0;
1157
1158 char* pstInput = wide_string_to_UTF8(_pwstInput);
1159 char* pstPattern = wide_string_to_UTF8(_pwstPattern);
1160 char** pstCaptured = NULL;//(char**)MALLOC(sizeof(char*) * (strlen(pstInput) + 1));
1161
1162 iPcreStatus = pcre_private(pstInput, pstPattern, &iStart, &iEnd, &pstCaptured, _piCapturedStringCount);
1163 if (iPcreStatus == PCRE_FINISHED_OK && iStart != iEnd)
1164 {
1165 char* pstTempStart = NULL;
1166 char* pstTempEnd = NULL;
1167 wchar_t* pwstTempStart = NULL;
1168 wchar_t* pwstTempEnd = NULL;
1169
1170 pstTempStart = os_strdup(pstInput);
1171 pstTempEnd = os_strdup(pstInput);
1172 pstTempEnd[iEnd] = 0;
1173 pstTempStart[iStart] = 0;
1174
1175
1176 pwstTempStart = to_wide_string(pstTempStart);
1177 pwstTempEnd = to_wide_string(pstTempEnd);
1178
1179 *_piStart = (int)wcslen(pwstTempStart);
1180 *_piEnd = (int)wcslen(pwstTempEnd);
1181
1182 if (_piCapturedStringCount && *_piCapturedStringCount > 0)
1183 {
1184 /*convert captured field in wide char*/
1185 *_pstCapturedString = (wchar_t**)MALLOC(sizeof(wchar_t*) * *_piCapturedStringCount);
1186 for (i = 0 ; i < *_piCapturedStringCount ; i++)
1187 {
1188 (*_pstCapturedString)[i] = to_wide_string(pstCaptured[i]);
1189 }
1190 freeArrayOfString(pstCaptured, *_piCapturedStringCount);
1191 }
1192
1193 FREE(pstTempStart);
1194 FREE(pstTempEnd);
1195 FREE(pwstTempStart);
1196 FREE(pwstTempEnd);
1197 }
1198 else
1199 {
1200 *_piStart = iStart;
1201 *_piEnd = iEnd;
1202 if (_piCapturedStringCount && *_piCapturedStringCount > 0)
1203 {
1204 /*free unused captured field*/
1205 freeArrayOfString(pstCaptured, *_piCapturedStringCount);
1206 }
1207 }
1208
1209 FREE(pstInput);
1210 FREE(pstPattern);
1211 return iPcreStatus;
1212}
1213/*-------------------------------------------------------------------------------*/
diff --git a/scilab/modules/string/src/c/string.vcxproj b/scilab/modules/string/src/c/string.vcxproj
index 7b2e30e..47a10c5 100644
--- a/scilab/modules/string/src/c/string.vcxproj
+++ b/scilab/modules/string/src/c/string.vcxproj
@@ -250,7 +250,6 @@
250 <ItemGroup> 250 <ItemGroup>
251 <ClCompile Include="..\cpp\os_wtoi.cpp" /> 251 <ClCompile Include="..\cpp\os_wtoi.cpp" />
252 <ClCompile Include="..\cpp\sort_inter.cpp" /> 252 <ClCompile Include="..\cpp\sort_inter.cpp" />
253 <ClCompile Include="convstr.c" />
254 <ClCompile Include="cvstr.c" /> 253 <ClCompile Include="cvstr.c" />
255 <ClCompile Include="DllMainString.c" /> 254 <ClCompile Include="DllMainString.c" />
256 <ClCompile Include="getfastcode.c" /> 255 <ClCompile Include="getfastcode.c" />
@@ -332,7 +331,6 @@
332 <ClInclude Include="..\..\includes\complex_array.h" /> 331 <ClInclude Include="..\..\includes\complex_array.h" />
333 <ClInclude Include="..\cpp\sort_inter.h" /> 332 <ClInclude Include="..\cpp\sort_inter.h" />
334 <ClInclude Include="config.h" /> 333 <ClInclude Include="config.h" />
335 <ClInclude Include="convstr.h" />
336 <ClInclude Include="CreateEmptystr.h" /> 334 <ClInclude Include="CreateEmptystr.h" />
337 <ClInclude Include="isalphanum.h" /> 335 <ClInclude Include="isalphanum.h" />
338 <ClInclude Include="isascii.h" /> 336 <ClInclude Include="isascii.h" />
diff --git a/scilab/modules/string/src/c/string.vcxproj.filters b/scilab/modules/string/src/c/string.vcxproj.filters
index 7974e8b..e5f9f67 100644
--- a/scilab/modules/string/src/c/string.vcxproj.filters
+++ b/scilab/modules/string/src/c/string.vcxproj.filters
@@ -23,9 +23,6 @@
23 </Filter> 23 </Filter>
24 </ItemGroup> 24 </ItemGroup>
25 <ItemGroup> 25 <ItemGroup>
26 <ClCompile Include="convstr.c">
27 <Filter>Source Files</Filter>
28 </ClCompile>
29 <ClCompile Include="cvstr.c"> 26 <ClCompile Include="cvstr.c">
30 <Filter>Source Files</Filter> 27 <Filter>Source Files</Filter>
31 </ClCompile> 28 </ClCompile>
@@ -173,9 +170,6 @@
173 <ClInclude Include="config.h"> 170 <ClInclude Include="config.h">
174 <Filter>Header Files</Filter> 171 <Filter>Header Files</Filter>
175 </ClInclude> 172 </ClInclude>
176 <ClInclude Include="convstr.h">
177 <Filter>Header Files</Filter>
178 </ClInclude>
179 <ClInclude Include="CreateEmptystr.h"> 173 <ClInclude Include="CreateEmptystr.h">
180 <Filter>Header Files</Filter> 174 <Filter>Header Files</Filter>
181 </ClInclude> 175 </ClInclude>
diff --git a/scilab/modules/string/src/c/stringToComplex.c b/scilab/modules/string/src/c/stringToComplex.c
index 32d3f71..ce8f204 100644
--- a/scilab/modules/string/src/c/stringToComplex.c
+++ b/scilab/modules/string/src/c/stringToComplex.c
@@ -23,17 +23,11 @@
23#include "strsubst.h" 23#include "strsubst.h"
24/* ========================================================================== */ 24/* ========================================================================== */
25#define PlusChar '+' 25#define PlusChar '+'
26#define PlusCharW L'+'
27#define LessChar '-' 26#define LessChar '-'
28#define LessCharW L'-'
29#define ComplexCharI 'i' 27#define ComplexCharI 'i'
30#define ComplexCharIW L'i'
31#define ComplexCharJ 'j' 28#define ComplexCharJ 'j'
32#define ComplexCharJW L'j'
33#define ComplexScilab "%i" 29#define ComplexScilab "%i"
34#define ComplexScilabW L"%i"
35#define ComplexI "i" 30#define ComplexI "i"
36#define ComplexIW L"i"
37/* ========================================================================== */ 31/* ========================================================================== */
38#ifndef _MSC_VER 32#ifndef _MSC_VER
39#ifndef strnicmp 33#ifndef strnicmp
@@ -48,15 +42,10 @@
48#endif 42#endif
49/* ========================================================================== */ 43/* ========================================================================== */
50static int ParseNumber(const char* tx); 44static int ParseNumber(const char* tx);
51static int ParseNumberW(const wchar_t* tx);
52static stringToComplexError ParseComplexValue(const char *tx, BOOL bConvertByNAN, double *real, double *imag); 45static stringToComplexError ParseComplexValue(const char *tx, BOOL bConvertByNAN, double *real, double *imag);
53static stringToComplexError ParseComplexValueW(const wchar_t *tx, BOOL bConvertByNAN, double *real, double *imag);
54static char* midstring(const char *tx, size_t pos, int nb); 46static char* midstring(const char *tx, size_t pos, int nb);
55static wchar_t* midstringW(const wchar_t *tx, size_t pos, int nb);
56static char *leftstring(const char *tx, size_t pos); 47static char *leftstring(const char *tx, size_t pos);
57static wchar_t* leftstringW(const wchar_t* tx, size_t pos);
58static BOOL is_unit_imaginary (const char *src, double *im); 48static BOOL is_unit_imaginary (const char *src, double *im);
59static BOOL is_unit_imaginaryW (const wchar_t* src, double *im);
60static double returnNAN(void); 49static double returnNAN(void);
61/* ========================================================================== */ 50/* ========================================================================== */
62complexArray *stringsToComplexArray(const char **pSTRs, int nbElements, 51complexArray *stringsToComplexArray(const char **pSTRs, int nbElements,
@@ -175,76 +164,6 @@ doublecomplex stringToComplex(const char *pSTR, const char *decimal, BOOL bConve
175 return dComplexValue; 164 return dComplexValue;
176} 165}
177/* ========================================================================== */ 166/* ========================================================================== */
178doublecomplex stringToComplexW(const wchar_t *pSTR, const wchar_t *decimal, BOOL bConvertByNAN, stringToComplexError *ierr)
179{
180 doublecomplex dComplexValue;
181 *ierr = STRINGTOCOMPLEX_ERROR;
182
183 dComplexValue.r = 0.;
184 dComplexValue.i = 0.;
185
186 if (pSTR)
187 {
188 double real = 0.;
189 double imag = 0.;
190 wchar_t *pStrTemp = wcssub(pSTR, L" ", L"");
191
192 if (pStrTemp)
193 {
194 wchar_t *pStrFormatted = wcssub(pStrTemp, decimal, L".");
195 FREE(pStrTemp);
196
197 if (pStrFormatted)
198 {
199 int lenStrFormatted = (int) wcslen(pStrFormatted);
200
201 /* case .4 replaced by 0.4 */
202 if (pStrFormatted[0] == '.')
203 {
204 /* case .4 replaced by 0.4 */
205 wchar_t *pstStrTemp = (wchar_t*)MALLOC(sizeof(wchar_t) * (lenStrFormatted + wcslen(L"0") + 1));
206 wcscpy(pstStrTemp, L"0");
207 wcscat(pstStrTemp, pStrFormatted);
208 FREE(pStrFormatted);
209 pStrFormatted = pstStrTemp;
210 }
211
212 if (lenStrFormatted > 1)
213 {
214 if (((pStrFormatted[0] == '+') || (pStrFormatted[0] == '-')) &&
215 (pStrFormatted[1] == '.'))
216 {
217 /* case +.4 replaced by +0.4 */
218 wchar_t *pstStrTemp = wcssub(pStrFormatted, L"+.", L"+0.");
219 FREE(pStrFormatted);
220
221 /* case -.4 replaced by -0.4 */
222 pStrFormatted = wcssub(pstStrTemp, L"-.", L"-0.");
223 FREE(pstStrTemp);
224 }
225 }
226
227 /* Case: "i", "+i", "-i", and with "j" */
228 if (is_unit_imaginaryW(pStrFormatted, &imag))
229 {
230 *ierr = STRINGTOCOMPLEX_NO_ERROR;
231 dComplexValue.r = 0.;
232 dComplexValue.i = imag;
233 }
234 else
235 {
236 *ierr = ParseComplexValueW(pStrFormatted, bConvertByNAN, &real, &imag);
237 }
238 FREE(pStrFormatted);
239 }
240 }
241 dComplexValue.r = real;
242 dComplexValue.i = imag;
243 }
244 return dComplexValue;
245}
246/* ========================================================================== */
247
248static int ParseNumber(const char* tx) 167static int ParseNumber(const char* tx)
249{ 168{
250 int lookahead = 0; 169 int lookahead = 0;
@@ -323,63 +242,6 @@ static int ParseNumber(const char* tx)
323 return lookahead; 242 return lookahead;
324} 243}
325/* ========================================================================== */ 244/* ========================================================================== */
326static int ParseNumberW(const wchar_t* tx)
327{
328 int lookahead = 0;
329 int len = 0;
330
331 if (tx[len] == NULL)
332 {
333 return lookahead;
334 }
335 if (tx[len] < 0)
336 {
337 return lookahead;
338 }
339
340 if ((tx[len] == L'+') || (tx[len] == L'-'))
341 {
342 len++;
343 }
344
345 while (iswdigit(tx[len]))
346 {
347 len++;
348 }
349 lookahead = len;
350
351 if (tx[lookahead] == L'.')
352 {
353 lookahead++;
354 len = 0;
355 while (iswdigit(tx[len + lookahead]))
356 {
357 len++;
358 }
359 lookahead += len;
360 }
361
362 if ((tx[lookahead] == L'E') || (tx[lookahead] == L'e') ||
363 (tx[lookahead] == L'D') || (tx[lookahead] == L'd'))
364 {
365
366 lookahead++;
367 if ((tx[lookahead] == L'+') || (tx[lookahead] == L'-'))
368 {
369 lookahead++;
370 }
371
372 len = 0;
373 while (iswdigit(tx[len + lookahead]))
374 {
375 len++;
376 }
377
378 lookahead += len;
379 }
380 return lookahead;
381}
382/* ========================================================================== */
383static stringToComplexError ParseComplexValue(const char *tx, BOOL bConvertByNAN, double *real, double *imag) 245static stringToComplexError ParseComplexValue(const char *tx, BOOL bConvertByNAN, double *real, double *imag)
384{ 246{
385 stringToDoubleError ierrDouble = STRINGTODOUBLE_NO_ERROR; 247 stringToDoubleError ierrDouble = STRINGTODOUBLE_NO_ERROR;
@@ -567,239 +429,6 @@ static stringToComplexError ParseComplexValue(const char *tx, BOOL bConvertByNAN
567 return ierr; 429 return ierr;
568} 430}
569/* ========================================================================== */ 431/* ========================================================================== */
570static stringToComplexError ParseComplexValueW(const wchar_t *tx, BOOL bConvertByNAN, double *real, double *imag)
571{
572 stringToDoubleError ierrDouble = STRINGTODOUBLE_NO_ERROR;
573 stringToComplexError ierr = STRINGTOCOMPLEX_NO_ERROR;
574 wchar_t *rnum_string = NULL;
575 wchar_t *inum_string = NULL;
576 size_t lnum = 0;
577 BOOL haveImagI = FALSE;
578 wchar_t *modifiedTxt = NULL;
579
580 *real = stringToDoubleW(tx, FALSE, &ierrDouble);
581 *imag = 0;
582
583 /* test on strlen(tx) > 1 to remove case 'e' */
584 if ((int)wcslen(tx) < 2)
585 {
586 if (ierrDouble == STRINGTODOUBLE_NO_ERROR)
587 {
588 ierr = (stringToComplexError) ierrDouble;
589 }
590 else
591 {
592 if (bConvertByNAN)
593 {
594 ierrDouble = STRINGTODOUBLE_NOT_A_NUMBER;
595 *real = returnNAN();
596 *imag = 0;
597 }
598 else
599 {
600 *real = 0;
601 *imag = 0;
602 ierr = (stringToComplexError) ierrDouble;
603 }
604 }
605 }
606 else if (ierrDouble != STRINGTODOUBLE_NO_ERROR)
607 {
608 modifiedTxt = wcssub(tx, ComplexScilabW, ComplexIW);
609 lnum = ParseNumberW(modifiedTxt);
610 if (lnum <= 1)
611 {
612 /* manages special cases nan + nani, ... */
613 if (wcsnicmp(modifiedTxt, NanStringW, wcslen(NanStringW)) == 0)
614 {
615 lnum = wcslen(NanStringW);
616 }
617 else if (wcsnicmp(modifiedTxt, InfStringW, wcslen(InfStringW)) == 0)
618 {
619 lnum = wcslen(InfStringW);
620 }
621 else if (wcsnicmp(modifiedTxt, NegInfStringW, wcslen(NegInfStringW)) == 0)
622 {
623 lnum = wcslen(NegInfStringW);
624 }
625 else if (wcsnicmp(modifiedTxt, PosInfStringW, wcslen(PosInfStringW)) == 0)
626 {
627 lnum = wcslen(PosInfStringW);
628 }
629 else if (wcsnicmp(modifiedTxt, NegNanStringW, wcslen(NegNanStringW)) == 0)
630 {
631 lnum = wcslen(NegNanStringW);
632 }
633 else if (wcsnicmp(modifiedTxt, PosNanStringW, wcslen(PosNanStringW)) == 0)
634 {
635 lnum = wcslen(PosNanStringW);
636 }
637 else if (wcsnicmp(modifiedTxt, ScilabEpsStringW, wcslen(ScilabEpsStringW)) == 0)
638 {
639 lnum = wcslen(ScilabEpsStringW);
640 }
641 else if (wcsnicmp(modifiedTxt, ScilabPosEpsStringW, wcslen(ScilabPosEpsStringW)) == 0)
642 {
643 lnum = wcslen(ScilabPosEpsStringW);
644 }
645 else if (wcsnicmp(modifiedTxt, ScilabNegEpsStringW, wcslen(ScilabNegEpsStringW)) == 0)
646 {
647 lnum = wcslen(ScilabNegEpsStringW);
648 }
649 else if (wcsnicmp(modifiedTxt, ScilabPiStringW, wcslen(ScilabPiStringW)) == 0)
650 {
651 lnum = wcslen(ScilabPiStringW);
652 }
653 else if (wcsnicmp(modifiedTxt, ScilabNegPiStringW, wcslen(ScilabNegPiStringW)) == 0)
654 {
655 lnum = wcslen(ScilabNegPiStringW);
656 }
657 else if (wcsnicmp(modifiedTxt, ScilabPosPiStringW, wcslen(ScilabPosPiStringW)) == 0)
658 {
659 lnum = wcslen(ScilabPosPiStringW);
660 }
661 else if (wcsnicmp(modifiedTxt, ScilabEStringW, wcslen(ScilabEStringW)) == 0)
662 {
663 lnum = wcslen(ScilabEStringW);
664 }
665 else if (wcsnicmp(modifiedTxt, ScilabPosEStringW, wcslen(ScilabPosEStringW)) == 0)
666 {
667 lnum = wcslen(ScilabPosEStringW);
668 }
669 else if (wcsnicmp(modifiedTxt, ScilabNegEStringW, wcslen(ScilabNegEStringW)) == 0)
670 {
671 lnum = wcslen(ScilabNegEStringW);
672 }
673 }
674 inum_string = midstringW(modifiedTxt, lnum, -1);
675
676 if ((inum_string[wcslen(inum_string) - 1] == L'i') ||
677 (inum_string[wcslen(inum_string) - 1] == L'j'))
678 {
679 inum_string[wcslen(inum_string) - 1] = 0;
680 if (inum_string[wcslen(inum_string) - 1] == L'*')
681 {
682 inum_string[wcslen(inum_string) - 1] = 0;
683 }
684
685 if (wcscmp(inum_string, L"+") == 0)
686 {
687 FREE(inum_string);
688 inum_string = os_wcsdup(L"+1");
689 }
690
691 if (wcscmp(inum_string, L"-") == 0)
692 {
693 FREE(inum_string);
694 inum_string = os_wcsdup(L"-1");
695 }
696 haveImagI = TRUE;
697 }
698 else if ((inum_string[1] == L'i') ||
699 (inum_string[1] == L'j'))
700 {
701 if (inum_string[2] == L'*')
702 {
703 int i = 0;
704 for (i = 1; (i + 2) < wcslen(inum_string); i++)
705 {
706 inum_string[i] = inum_string[i + 2];
707 }
708 inum_string[wcslen(inum_string) - 1] = 0;
709 inum_string[wcslen(inum_string) - 1] = 0;
710 }
711
712 if (wcscmp(inum_string, L"+") == 0)
713 {
714 FREE(inum_string);
715 inum_string = os_wcsdup(L"+1");
716 }
717
718 if (wcscmp(inum_string, L"-") == 0)
719 {
720 FREE(inum_string);
721 inum_string = os_wcsdup(L"-1");
722 }
723 haveImagI = TRUE;
724 }
725 else
726 {
727 haveImagI = FALSE;
728 }
729 rnum_string = leftstringW(modifiedTxt, lnum);
730
731 if (wcscmp(inum_string, L"") == 0)
732 {
733 *imag = stringToDoubleW(rnum_string, bConvertByNAN, &ierrDouble);
734 ierr = (stringToComplexError)(ierrDouble);
735 *real = 0.;
736 }
737 else
738 {
739 double dReal = 0.;
740 double dImag = 0.;
741
742 stringToDoubleError ierrReal = STRINGTODOUBLE_NO_ERROR;
743 stringToDoubleError ierrImag = STRINGTODOUBLE_NO_ERROR;
744 dReal = stringToDoubleW(rnum_string, FALSE, &ierrReal);
745 dImag = stringToDoubleW(inum_string, FALSE, &ierrImag);
746
747 if ((ierrReal == STRINGTODOUBLE_NO_ERROR) && (ierrImag == STRINGTODOUBLE_NO_ERROR))
748 {
749 if (!haveImagI)
750 {
751 if (bConvertByNAN)
752 {
753 ierr = STRINGTOCOMPLEX_NO_ERROR;
754 *real = returnNAN();
755 *imag = 0.;
756 }
757 else
758 {
759 ierr = STRINGTOCOMPLEX_ERROR;
760 }
761 }
762 else
763 {
764 ierr = STRINGTOCOMPLEX_NO_ERROR;
765 *real = dReal;
766 *imag = dImag;
767 }
768 }
769 else
770 {
771 if (bConvertByNAN)
772 {
773 ierr = STRINGTOCOMPLEX_NO_ERROR;
774 *real = returnNAN();
775 *imag = 0.;
776 }
777 else
778 {
779 ierr = STRINGTOCOMPLEX_ERROR;
780 }
781 }
782 }
783
784 if (rnum_string)
785 {
786 FREE(rnum_string);
787 rnum_string = NULL;
788 }
789 if (inum_string)
790 {
791 FREE(inum_string);
792 inum_string = NULL;
793 }
794 if (modifiedTxt)
795 {
796 FREE(modifiedTxt);
797 modifiedTxt = NULL;
798 }
799 }
800 return ierr;
801}
802/* ========================================================================== */
803static char *midstring(const char *tx, size_t pos, int nb) 432static char *midstring(const char *tx, size_t pos, int nb)
804{ 433{
805 char *returnString = NULL; 434 char *returnString = NULL;
@@ -828,34 +457,6 @@ static char *midstring(const char *tx, size_t pos, int nb)
828 return returnString; 457 return returnString;
829} 458}
830/* ========================================================================== */ 459/* ========================================================================== */
831static wchar_t* midstringW(const wchar_t* tx, size_t pos, int nb)
832{
833 wchar_t *returnString = NULL;
834 if (tx)
835 {
836 int lenTx = (int) wcslen(tx);
837 int posEnd = 0;
838 int newLen = 0;
839
840 if (nb < 0)
841 {
842 posEnd = lenTx;
843 }
844 else
845 {
846 posEnd = nb;
847 }
848 newLen = posEnd + 1;
849 if (newLen > 0)
850 {
851 returnString = (wchar_t*)MALLOC(sizeof(wchar_t) * newLen);
852 wcsncpy(returnString, &tx[pos], posEnd);
853 returnString[posEnd] = 0;
854 }
855 }
856 return returnString;
857}
858/* ========================================================================== */
859static char *leftstring(const char *tx, size_t pos) 460static char *leftstring(const char *tx, size_t pos)
860{ 461{
861 char *returnString = NULL; 462 char *returnString = NULL;
@@ -875,25 +476,6 @@ static char *leftstring(const char *tx, size_t pos)
875 return returnString; 476 return returnString;
876} 477}
877/* ========================================================================== */ 478/* ========================================================================== */
878static wchar_t *leftstringW(const wchar_t *tx, size_t pos)
879{
880 wchar_t *returnString = NULL;
881 if (tx)
882 {
883 int lenTx = (int) wcslen(tx);
884 returnString = os_wcsdup(tx);
885 if (pos > lenTx)
886 {
887 return returnString;
888 }
889 else
890 {
891 returnString[pos] = 0;
892 }
893 }
894 return returnString;
895}
896/* ========================================================================== */
897static BOOL is_unit_imaginary (const char *src, double *im) 479static BOOL is_unit_imaginary (const char *src, double *im)
898{ 480{
899 char *modifiedSrc = strsub((char*)src, ComplexScilab, ComplexI); 481 char *modifiedSrc = strsub((char*)src, ComplexScilab, ComplexI);
@@ -939,51 +521,6 @@ static BOOL is_unit_imaginary (const char *src, double *im)
939 return isUnitImag; 521 return isUnitImag;
940} 522}
941/* ========================================================================== */ 523/* ========================================================================== */
942static BOOL is_unit_imaginaryW(const wchar_t *src, double *im)
943{
944 wchar_t *modifiedSrc = wcssub(src, ComplexScilabW, ComplexIW);
945 wchar_t *nextChar = NULL;
946 BOOL isUnitImag = FALSE;
947
948 if (modifiedSrc == NULL)
949 {
950 return isUnitImag;
951 }
952
953 if (modifiedSrc[0] == LessChar)
954 {
955 *im = -1.0;
956 nextChar = modifiedSrc + 1;
957 }
958 else
959 {
960 *im = +1.0;
961 if (modifiedSrc[0] == PlusChar)
962 {
963 nextChar = modifiedSrc + 1;
964 }
965 else
966 {
967 nextChar = modifiedSrc;
968 }
969 }
970
971 if (nextChar)
972 {
973 if ((nextChar[0] == ComplexCharI || nextChar[0] == ComplexCharJ) && nextChar[1] == 0)
974 {
975 isUnitImag = TRUE;
976 }
977 }
978
979 if (modifiedSrc)
980 {
981 FREE(modifiedSrc);
982 modifiedSrc = NULL;
983 }
984 return isUnitImag;
985}
986/* ========================================================================== */
987static double returnNAN(void) 524static double returnNAN(void)
988{ 525{
989 static int first = 1; 526 static int first = 1;
diff --git a/scilab/modules/string/src/c/stringToDouble.c b/scilab/modules/string/src/c/stringToDouble.c
index 43329e4..ebc33ed 100644
--- a/scilab/modules/string/src/c/stringToDouble.c
+++ b/scilab/modules/string/src/c/stringToDouble.c
@@ -65,35 +65,6 @@ static char* replace_D_By_E(const char* _pst)
65 return pstReturn; 65 return pstReturn;
66} 66}
67 67
68static wchar_t* replace_D_By_EW(const wchar_t* _pst)
69{
70 //find and replace d and D by E for compatibility with strtod Linux/Mac
71 wchar_t* pstReturn = os_wcsdup(_pst);
72 wchar_t* pstFind = pstReturn;
73 do
74 {
75 pstFind = wcschr(pstFind, L'D');
76 if (pstFind)
77 {
78 pstFind[0] = L'E';
79 }
80 }
81 while (pstFind);
82
83 pstFind = pstReturn;
84 do
85 {
86 pstFind = wcschr(pstFind, L'd');
87 if (pstFind)
88 {
89 pstFind[0] = L'e';
90 }
91 }
92 while (pstFind);
93
94 return pstReturn;
95}
96
97double stringToDouble(const char *pSTR, BOOL bConvertByNAN, stringToDoubleError *ierr) 68double stringToDouble(const char *pSTR, BOOL bConvertByNAN, stringToDoubleError *ierr)
98{ 69{
99 double dValue = 0.0; 70 double dValue = 0.0;
@@ -189,101 +160,6 @@ double stringToDouble(const char *pSTR, BOOL bConvertByNAN, stringToDoubleError
189 return dValue; 160 return dValue;
190} 161}
191// ============================================================================= 162// =============================================================================
192double stringToDoubleW(const wchar_t *pSTR, BOOL bConvertByNAN, stringToDoubleError *ierr)
193{
194 double dValue = 0.0;
195 *ierr = STRINGTODOUBLE_ERROR;
196 if (pSTR)
197 {
198 if ((wcsicmp(pSTR, NanStringW) == 0) || (wcsicmp(pSTR, NegNanStringW) == 0) ||
199 (wcsicmp(pSTR, PosNanStringW) == 0) || (wcsicmp(pSTR, ScilabPosNanStringW) == 0) ||
200 (wcsicmp(pSTR, ScilabNanStringW) == 0) || (wcsicmp(pSTR, ScilabNegNanStringW) == 0))
201 {
202 dValue = returnNAN();
203 }
204 else if ((wcsicmp(pSTR, InfStringW) == 0) || (wcsicmp(pSTR, PosInfStringW) == 0) ||
205 (wcsicmp(pSTR, ScilabInfStringW) == 0) || (wcsicmp(pSTR, ScilabPosInfStringW) == 0))
206 {
207 dValue = returnINF(TRUE);
208 }
209 else if ((wcsicmp(pSTR, NegInfStringW) == 0) || (wcsicmp(pSTR, ScilabNegInfStringW) == 0))
210 {
211 dValue = returnINF(FALSE);
212 }
213 else if ((wcsicmp(pSTR, ScilabPiStringW) == 0) || (wcsicmp(pSTR, ScilabPosPiStringW) == 0))
214 {
215 dValue = M_PI;
216 }
217 else if (wcsicmp(pSTR, ScilabNegPiStringW) == 0)
218 {
219 dValue = -M_PI;
220 }
221 else if ((wcsicmp(pSTR, ScilabPosEStringW) == 0) || (wcsicmp(pSTR, ScilabEStringW) == 0))
222 {
223 dValue = exp(1);
224 }
225 else if (wcsicmp(pSTR, ScilabNegEStringW) == 0)
226 {
227 dValue = -exp(1);
228 }
229 else if ((wcsicmp(pSTR, ScilabEpsStringW) == 0) || (wcsicmp(pSTR, ScilabPosEpsStringW) == 0))
230 {
231 dValue = EPSILON;
232 }
233 else if (wcsicmp(pSTR, ScilabNegEpsStringW) == 0)
234 {
235 dValue = -EPSILON;
236 }
237 else
238 {
239 wchar_t* pstReplaced = replace_D_By_EW(pSTR);
240 wchar_t *pEnd = NULL;
241 double v = wcstod(pstReplaced, &pEnd);
242 if ((v == 0) && (pEnd == pstReplaced))
243 {
244 if (bConvertByNAN)
245 {
246 dValue = returnNAN();
247 }
248 else
249 {
250 *ierr = STRINGTODOUBLE_NOT_A_NUMBER;
251 FREE(pstReplaced);
252 return (dValue = 0.0);
253 }
254 }
255 else
256 {
257 if (wcscmp(pEnd, L"") == 0)
258 {
259 dValue = v;
260 }
261 else
262 {
263 if (bConvertByNAN)
264 {
265 dValue = returnNAN();
266 }
267 else
268 {
269 *ierr = STRINGTODOUBLE_NOT_A_NUMBER;
270 FREE(pstReplaced);
271 return (dValue = 0.0);
272 }
273 }
274 }
275
276 FREE(pstReplaced);
277 }
278 *ierr = STRINGTODOUBLE_NO_ERROR;
279 }
280 else
281 {
282 *ierr = STRINGTODOUBLE_MEMORY_ALLOCATION;
283 }
284 return dValue;
285}
286// =============================================================================
287static double returnINF(BOOL bPositive) 163static double returnINF(BOOL bPositive)
288{ 164{
289 double dbl1 = 1.0; 165 double dbl1 = 1.0;
diff --git a/scilab/modules/string/src/c/stringsstrrev.c b/scilab/modules/string/src/c/stringsstrrev.c
index 6f938ff..7b0c239 100644
--- a/scilab/modules/string/src/c/stringsstrrev.c
+++ b/scilab/modules/string/src/c/stringsstrrev.c
@@ -18,6 +18,7 @@
18#include "freeArrayOfString.h" 18#include "freeArrayOfString.h"
19#include "sci_malloc.h" 19#include "sci_malloc.h"
20#include "os_string.h" 20#include "os_string.h"
21#include "charEncoding.h"
21/*----------------------------------------------------------------------------*/ 22/*----------------------------------------------------------------------------*/
22char** strings_strrev(char **Input_strings, int Dim_Input_strings) 23char** strings_strrev(char **Input_strings, int Dim_Input_strings)
23{ 24{
@@ -30,31 +31,36 @@ char** strings_strrev(char **Input_strings, int Dim_Input_strings)
30 int i = 0; 31 int i = 0;
31 for (i = 0; i < Dim_Input_strings; i++) 32 for (i = 0; i < Dim_Input_strings; i++)
32 { 33 {
33 Output_strings[i] = scistrrev(Input_strings[i]); 34 wchar_t* w = to_wide_string(Input_strings[i]);
34 if (Output_strings[i] == NULL) 35 wchar_t* o = scistrrev(w);
36 if (o == NULL)
35 { 37 {
36 freeArrayOfString(Output_strings, i); 38 freeArrayOfString(Output_strings, i);
37 return NULL; 39 return NULL;
38 } 40 }
41
42 Output_strings[i] = wide_string_to_UTF8(o);
43 FREE(o);
44 FREE(w);
39 } 45 }
40 } 46 }
41 } 47 }
42 return Output_strings; 48 return Output_strings;
43} 49}
44/*----------------------------------------------------------------------------*/ 50/*----------------------------------------------------------------------------*/
45char* scistrrev(char* str) 51wchar_t* scistrrev(wchar_t* str)
46{ 52{
47 char *revstr = NULL; 53 wchar_t *revstr = NULL;
48 if (str) 54 if (str)
49 { 55 {
50#ifdef _MSC_VER 56#ifdef _MSC_VER
51 revstr = _strrev(str); 57 revstr = _wcsrev(os_wcsdup(str));
52#else 58#else
53 int iLen = 0; 59 int iLen = 0;
54 int j = 0; 60 int j = 0;
55 61
56 iLen = (int)strlen(str); 62 iLen = (int)wcslen(str);
57 revstr = (char*)MALLOC((iLen + 1) * sizeof(char)); 63 revstr = (wchar_t*)MALLOC((iLen + 1) * sizeof(wchar_t));
58 /* copy character by character to reverse string */ 64 /* copy character by character to reverse string */
59 for (j = 0 ; j < iLen ; j++) 65 for (j = 0 ; j < iLen ; j++)
60 { 66 {
diff --git a/scilab/modules/string/src/c/stringsstrrev.h b/scilab/modules/string/src/c/stringsstrrev.h
index 2d17b71..a9afc33 100644
--- a/scilab/modules/string/src/c/stringsstrrev.h
+++ b/scilab/modules/string/src/c/stringsstrrev.h
@@ -19,7 +19,7 @@
19#include "dynlib_string.h" 19#include "dynlib_string.h"
20 20
21STRING_IMPEXP char** strings_strrev(char** Input_strings, int Dim_Input_strings); 21STRING_IMPEXP char** strings_strrev(char** Input_strings, int Dim_Input_strings);
22char* scistrrev(char* str); 22wchar_t* scistrrev(wchar_t* str);
23 23
24#endif /* __STRINGSSTRREV_H__ */ 24#endif /* __STRINGSSTRREV_H__ */
25/*----------------------------------------------------------------------------*/ 25/*----------------------------------------------------------------------------*/
diff --git a/scilab/modules/string/src/c/strsplit.c b/scilab/modules/string/src/c/strsplit.c
index e83f83d..9daf5ca 100644
--- a/scilab/modules/string/src/c/strsplit.c
+++ b/scilab/modules/string/src/c/strsplit.c
@@ -14,24 +14,25 @@
14#include "strsplit.h" 14#include "strsplit.h"
15#include "sci_malloc.h" 15#include "sci_malloc.h"
16#include "freeArrayOfString.h" 16#include "freeArrayOfString.h"
17#include "charEncoding.h"
17/*----------------------------------------------------------------------------*/ 18/*----------------------------------------------------------------------------*/
18char** strsplit(const char* stringToSplit, double *indices, int sizeIndices, strsplit_error *ierr) 19wchar_t **wide_strsplit(wchar_t * wcstringToSplit, double *indices, int sizeIndices, strsplit_error *ierr)
19{ 20{
20 char** splitted = NULL; 21 wchar_t **splitted = NULL;
21 *ierr = STRSPLIT_NO_ERROR; 22 *ierr = STRSPLIT_NO_ERROR;
22 23
23 if (stringToSplit) 24 if (wcstringToSplit)
24 { 25 {
25 int lengthToCopy = 0; 26 int lengthToCopy = 0;
26 int lenString = (int)strlen(stringToSplit); 27 int lenString = (int)wcslen(wcstringToSplit);
27 int i = 0, j = 0; 28 int i = 0, j = 0;
28 char* strDest = NULL; 29 wchar_t* wcStrDest = NULL;
29 const char* strSrc = NULL; 30 wchar_t* wcStrSrc = NULL;
30 31
31 for (i = 0; i < sizeIndices; i++) 32 for (i = 0; i < sizeIndices; i++)
32 { 33 {
33 /* Check 2nd input matrix position */ 34 /* Check 2nd input matrix position */
34 if ( ((int)indices[i] <= 0) || ((int)indices[i] >= lenString) ) 35 if (((int)indices[i] <= 0) || ((int)indices[i] >= lenString))
35 { 36 {
36 *ierr = STRSPLIT_INCORRECT_VALUE_ERROR; 37 *ierr = STRSPLIT_INCORRECT_VALUE_ERROR;
37 return NULL; 38 return NULL;
@@ -40,9 +41,9 @@ char** strsplit(const char* stringToSplit, double *indices, int sizeIndices, str
40 /* check 2nd input order */ 41 /* check 2nd input order */
41 if (sizeIndices > 1) 42 if (sizeIndices > 1)
42 { 43 {
43 if ( i < (sizeIndices - 1) ) 44 if (i < (sizeIndices - 1))
44 { 45 {
45 if ((int)indices[i] > (int)indices[i + 1]) 46 if ((int)indices[i] >(int)indices[i + 1])
46 { 47 {
47 *ierr = STRSPLIT_INCORRECT_ORDER_ERROR; 48 *ierr = STRSPLIT_INCORRECT_ORDER_ERROR;
48 return NULL; 49 return NULL;
@@ -51,7 +52,7 @@ char** strsplit(const char* stringToSplit, double *indices, int sizeIndices, str
51 } 52 }
52 } 53 }
53 54
54 splitted = (char**)MALLOC(sizeof(char*) * (sizeIndices + 1)); 55 splitted = (wchar_t**)MALLOC(sizeof(wchar_t*) * (sizeIndices + 1));
55 if (splitted == NULL) 56 if (splitted == NULL)
56 { 57 {
57 *ierr = STRSPLIT_MEMORY_ALLOCATION_ERROR; 58 *ierr = STRSPLIT_MEMORY_ALLOCATION_ERROR;
@@ -70,38 +71,56 @@ char** strsplit(const char* stringToSplit, double *indices, int sizeIndices, str
70 lengthToCopy = (int)indices[i] - (int)indices[i - 1]; 71 lengthToCopy = (int)indices[i] - (int)indices[i - 1];
71 } 72 }
72 73
73 splitted[i] = (char*)MALLOC(sizeof(char) * (lengthToCopy + 1)); 74 splitted[i] = (wchar_t*)MALLOC(sizeof(wchar_t) * (lengthToCopy + 1));
74 strDest = splitted[i]; 75 wcStrDest = splitted[i];
75 76
76 if (splitted[i] == NULL) 77 if (splitted[i] == NULL)
77 { 78 {
78 freeArrayOfString(splitted, sizeIndices); 79 freeArrayOfWideString(splitted, sizeIndices);
79 *ierr = STRSPLIT_MEMORY_ALLOCATION_ERROR; 80 *ierr = STRSPLIT_MEMORY_ALLOCATION_ERROR;
80 return NULL; 81 return NULL;
81 } 82 }
82 83 wcStrSrc = &wcstringToSplit[j];
83 strSrc = &stringToSplit[j]; 84 memcpy(wcStrDest, wcStrSrc, lengthToCopy * sizeof(wchar_t));
84 memcpy(strDest, strSrc, lengthToCopy * sizeof(char)); 85 wcStrDest[lengthToCopy] = 0;
85 strDest[lengthToCopy] = 0;
86 86
87 j = (int)indices[i]; 87 j = (int)indices[i];
88 } 88 }
89 89
90 lengthToCopy = lenString - (int)indices[sizeIndices - 1]; 90 lengthToCopy = lenString - (int)indices[sizeIndices - 1];
91 splitted[sizeIndices] = (char*)MALLOC(sizeof(char) * (lengthToCopy + 1)); 91 splitted[sizeIndices] = (wchar_t*)MALLOC(sizeof(wchar_t) * (lengthToCopy + 1));
92 strDest = splitted[sizeIndices]; 92 wcStrDest = splitted[sizeIndices];
93 93
94 if (splitted[sizeIndices] == NULL) 94 if (splitted[sizeIndices] == NULL)
95 { 95 {
96 freeArrayOfString(splitted, sizeIndices + 1); 96 freeArrayOfWideString(splitted, sizeIndices + 1);
97 *ierr = STRSPLIT_MEMORY_ALLOCATION_ERROR; 97 *ierr = STRSPLIT_MEMORY_ALLOCATION_ERROR;
98 return NULL; 98 return NULL;
99 } 99 }
100 100
101 strSrc = &stringToSplit[j]; 101 wcStrSrc = &wcstringToSplit[j];
102 memcpy(strDest, strSrc, lengthToCopy * sizeof(char)); 102 memcpy(wcStrDest, wcStrSrc, lengthToCopy * sizeof(wchar_t));
103 strDest[lengthToCopy] = 0; 103 wcStrDest[lengthToCopy] = 0;
104 } 104 }
105 return splitted; 105 return splitted;
106} 106}
107
108char** strsplit(const char* stringToSplit, double *indices, int sizeIndices, strsplit_error *ierr)
109{
110 wchar_t* w = to_wide_string(stringToSplit);
111 wchar_t** o = wide_strsplit(w, indices, sizeIndices, ierr);
112 if (*ierr == STRSPLIT_NO_ERROR)
113 {
114 char** output = (char**)MALLOC(sizeof(char*) * (sizeIndices + 1));
115 for (int i = 0; i < sizeIndices + 1; ++i)
116 {
117 output[i] = wide_string_to_UTF8(o[i]);
118 }
119
120 freeArrayOfWideString(o, sizeIndices + 1);
121 return output;
122 }
123
124 return NULL;
125}
107/*----------------------------------------------------------------------------*/ 126/*----------------------------------------------------------------------------*/
diff --git a/scilab/modules/string/src/c/strsubst.c b/scilab/modules/string/src/c/strsubst.c
index f644677..bfae544 100644
--- a/scilab/modules/string/src/c/strsubst.c
+++ b/scilab/modules/string/src/c/strsubst.c
@@ -26,14 +26,14 @@ char **strsubst(const char **strings_input, int strings_dim, const char *string_
26{ 26{
27 char **replacedStrings = NULL; 27 char **replacedStrings = NULL;
28 28
29 if ( (strings_input) && (string_to_search) && (replacement_string) ) 29 if ((strings_input) && (string_to_search) && (replacement_string))
30 { 30 {
31 int i = 0; 31 int i = 0;
32 replacedStrings = (char**)MALLOC(sizeof(char*) * strings_dim); 32 replacedStrings = (char**)MALLOC(sizeof(char*) * strings_dim);
33 for (i = 0; i < strings_dim; i++) 33 for (i = 0; i < strings_dim; i++)
34 { 34 {
35 const char *str = strings_input[i]; 35 const char *str = strings_input[i];
36 replacedStrings[i] = strsub (str, string_to_search, replacement_string); 36 replacedStrings[i] = strsub(str, string_to_search, replacement_string);
37 } 37 }
38 } 38 }
39 return replacedStrings; 39 return replacedStrings;
@@ -43,7 +43,7 @@ char **strsubst_reg(const char **strings_input, int strings_dim, const char *str
43{ 43{
44 char **replacedStrings = NULL; 44 char **replacedStrings = NULL;
45 45
46 if ( (strings_input) && (string_to_search) && (replacement_string) ) 46 if ((strings_input) && (string_to_search) && (replacement_string))
47 { 47 {
48 int i = 0; 48 int i = 0;
49 replacedStrings = (char**)MALLOC(sizeof(char*) * strings_dim); 49 replacedStrings = (char**)MALLOC(sizeof(char*) * strings_dim);
@@ -73,22 +73,22 @@ char *strsub(const char* input_string, const char* string_to_search, const char*
73 return os_strdup(input_string); 73 return os_strdup(input_string);
74 } 74 }
75 75
76 occurrence_str = strstr (input_string, string_to_search); 76 occurrence_str = strstr(input_string, string_to_search);
77 if (occurrence_str == NULL) 77 if (occurrence_str == NULL)
78 { 78 {
79 return os_strdup(input_string); 79 return os_strdup(input_string);
80 } 80 }
81 81
82 if (strlen (replacement_string) > strlen (string_to_search)) 82 if (strlen(replacement_string) > strlen(string_to_search))
83 { 83 {
84 count = 0; 84 count = 0;
85 len = (int)strlen (string_to_search); 85 len = (int)strlen(string_to_search);
86 if (len) 86 if (len)
87 { 87 {
88 occurrence_str = input_string; 88 occurrence_str = input_string;
89 while (occurrence_str != NULL && *occurrence_str != '\0') 89 while (occurrence_str != NULL && *occurrence_str != '\0')
90 { 90 {
91 occurrence_str = strstr (occurrence_str, string_to_search); 91 occurrence_str = strstr(occurrence_str, string_to_search);
92 if (occurrence_str != NULL) 92 if (occurrence_str != NULL)
93 { 93 {
94 occurrence_str += len; 94 occurrence_str += len;
@@ -103,7 +103,7 @@ char *strsub(const char* input_string, const char* string_to_search, const char*
103 len = (int)strlen(input_string); 103 len = (int)strlen(input_string);
104 } 104 }
105 105
106 replacedString = (char*)MALLOC (sizeof(char) * (len + 1)); 106 replacedString = (char*)MALLOC(sizeof(char) * (len + 1));
107 if (replacedString == NULL) 107 if (replacedString == NULL)
108 { 108 {
109 return NULL; 109 return NULL;
@@ -111,10 +111,10 @@ char *strsub(const char* input_string, const char* string_to_search, const char*
111 111
112 occurrence_str = input_string; 112 occurrence_str = input_string;
113 result_str = replacedString; 113 result_str = replacedString;
114 len = (int)strlen (string_to_search); 114 len = (int)strlen(string_to_search);
115 while (*occurrence_str != '\0') 115 while (*occurrence_str != '\0')
116 { 116 {
117 if (*occurrence_str == string_to_search[0] && strncmp (occurrence_str, string_to_search, len) == 0) 117 if (*occurrence_str == string_to_search[0] && strncmp(occurrence_str, string_to_search, len) == 0)
118 { 118 {
119 const char *N = NULL; 119 const char *N = NULL;
120 N = replacement_string; 120 N = replacement_string;
@@ -179,7 +179,7 @@ char *strsub_reg(const char* input_string, const char* string_to_search, const c
179 179
180 len = (int)wcslen(wcreplacement_string) + (int)wcslen(wcinput_string); 180 len = (int)wcslen(wcreplacement_string) + (int)wcslen(wcinput_string);
181 181
182 wcreplacedString = (wchar_t*)MALLOC (sizeof(wchar_t) * (len + 1)); 182 wcreplacedString = (wchar_t*)MALLOC(sizeof(wchar_t) * (len + 1));
183 if (wcreplacedString == NULL) 183 if (wcreplacedString == NULL)
184 { 184 {
185 FREE(replacement_string); 185 FREE(replacement_string);
@@ -196,7 +196,7 @@ char *strsub_reg(const char* input_string, const char* string_to_search, const c
196 int wcOutput_End = 0; 196 int wcOutput_End = 0;
197 197
198 char * strOutput_Start = os_strdup(input_string); 198 char * strOutput_Start = os_strdup(input_string);
199 char * strOutput_End = os_strdup(input_string); 199 char * strOutput_End = os_strdup(input_string);
200 200
201 wchar_t *wcstrOutput_Start = NULL; 201 wchar_t *wcstrOutput_Start = NULL;
202 wchar_t *wcstrOutput_End = NULL; 202 wchar_t *wcstrOutput_End = NULL;
@@ -247,163 +247,3 @@ char *strsub_reg(const char* input_string, const char* string_to_search, const c
247 return replacedString; 247 return replacedString;
248} 248}
249/*-------------------------------------------------------------------------------------*/ 249/*-------------------------------------------------------------------------------------*/
250wchar_t *wcssub_reg(const wchar_t* _pwstInput, const wchar_t* _pwstSearch, const wchar_t* _pwstReplace, int* _piErr)
251{
252 pcre_error_code iPcreStatus = PCRE_FINISHED_OK;
253 int iStart = 0;
254 int iEnd = 0;
255 int iLen = 0;
256
257 wchar_t* pwstOutput = NULL;
258
259 if (_pwstInput == NULL)
260 {
261 return NULL;
262 }
263
264 if (_pwstSearch == NULL || _pwstReplace == NULL)
265 {
266 return os_wcsdup(_pwstInput);
267 }
268
269 iPcreStatus = wide_pcre_private((wchar_t*)_pwstInput, (wchar_t*)_pwstSearch, &iStart, &iEnd, NULL, NULL);
270 if (iPcreStatus != PCRE_FINISHED_OK)
271 {
272 *_piErr = iPcreStatus;
273 return os_wcsdup(_pwstInput);
274 }
275
276 //compute new size of output string
277 iLen += (int)wcslen(_pwstReplace) - (iEnd - iStart);
278
279 pwstOutput = (wchar_t*)MALLOC(sizeof(wchar_t) * (wcslen(_pwstInput) + iLen + 1));
280 memset(pwstOutput, 0x00, sizeof(wchar_t) * (wcslen(_pwstInput) + iLen + 1));
281
282 //copy start of original string
283 wcsncpy(pwstOutput, _pwstInput, iStart);
284 //copy replace string
285 wcscpy(pwstOutput + wcslen(pwstOutput), _pwstReplace);
286 //copy end of original string
287 wcscpy(pwstOutput + wcslen(pwstOutput), _pwstInput + iEnd);
288
289 *_piErr = iPcreStatus;
290 return pwstOutput;
291}
292/*-------------------------------------------------------------------------------------*/
293wchar_t **wcssubst_reg(const wchar_t** _pwstInput, int _iInputSize, const wchar_t* _pwstSearch, const wchar_t* _pwstReplace, int* _piErr)
294{
295 wchar_t** pwstOutput = NULL;
296
297 if (_pwstInput != NULL && _pwstSearch != NULL && _pwstReplace != NULL)
298 {
299 int i = 0;
300 pwstOutput = (wchar_t**)MALLOC(sizeof(wchar_t*) * _iInputSize);
301 for (i = 0 ; i < _iInputSize ; i++)
302 {
303 const wchar_t* pwst = _pwstInput[i];
304 pwstOutput[i] = wcssub_reg(pwst, _pwstSearch, _pwstReplace, _piErr);
305 }
306 }
307 return pwstOutput;
308}
309/*-------------------------------------------------------------------------------------*/
310wchar_t **wcssubst(const wchar_t** _pwstInput, int _iInputSize, const wchar_t* _pwstSearch, const wchar_t* _pwstReplace)
311{
312 wchar_t** pwstOutput = NULL;
313
314 if (_pwstInput != NULL && _pwstSearch != NULL && _pwstReplace != NULL)
315 {
316 int i = 0;
317 pwstOutput = (wchar_t**)MALLOC(sizeof(wchar_t*) * _iInputSize);
318 for (i = 0 ; i < _iInputSize ; i++)
319 {
320 const wchar_t* pwst = _pwstInput[i];
321 if (wcslen(pwst) == 0)
322 {
323 pwstOutput[i] = os_wcsdup(L"");
324 }
325 else
326 {
327 pwstOutput[i] = wcssub(pwst, _pwstSearch, _pwstReplace);
328 }
329 }
330 }
331 return pwstOutput;
332}
333/*-------------------------------------------------------------------------------------*/
334wchar_t *wcssub(const wchar_t* _pwstInput, const wchar_t* _pwstSearch, const wchar_t* _pwstReplace)
335{
336 int i = 0;
337 int iOccurs = 0;
338 size_t iReplace = 0;
339 size_t iSearch = 0;
340 size_t iOffset = 0;
341
342 size_t* piStart = NULL;
343
344 const wchar_t* pwstPos = NULL;
345 wchar_t* pwstOutput = NULL;
346
347 if (_pwstInput == NULL)
348 {
349 return NULL;
350 }
351
352 if (_pwstInput[0] == L'\0')
353 {
354 return os_wcsdup(L"");
355 }
356
357 if (_pwstSearch == NULL || _pwstReplace == NULL)
358 {
359 return os_wcsdup(_pwstInput);
360 }
361
362 iSearch = wcslen(_pwstSearch);
363 iReplace = wcslen(_pwstReplace);
364 piStart = (size_t*)MALLOC(sizeof(size_t) * wcslen(_pwstInput));
365 pwstPos = _pwstInput;
366
367 while (pwstPos)
368 {
369 pwstPos = wcsstr(pwstPos, _pwstSearch);
370 if (pwstPos)
371 {
372 piStart[iOccurs++] = pwstPos - _pwstInput;
373 iOffset += iReplace - iSearch;
374 pwstPos++;
375 }
376 }
377
378 pwstOutput = (wchar_t*)MALLOC(sizeof(wchar_t) * (wcslen(_pwstInput) + iOffset + 1));
379 memset(pwstOutput, 0x00, sizeof(wchar_t) * (wcslen(_pwstInput) + iOffset + 1));
380
381 if (iOccurs == 0)
382 {
383 wcscpy(pwstOutput, _pwstInput);
384 }
385 else
386 {
387 for (i = 0 ; i < iOccurs ; i++)
388 {
389 if (i == 0)
390 {
391 //copy start of original string
392 wcsncpy(pwstOutput, _pwstInput, piStart[i]);
393 }
394 else
395 {
396 //copy start of original string
397 wcsncpy(pwstOutput + wcslen(pwstOutput), _pwstInput + piStart[i - 1] + iSearch, piStart[i] - (iSearch + piStart[i - 1]));
398 }
399 //copy replace string
400 wcscpy(pwstOutput + wcslen(pwstOutput), _pwstReplace);
401 }
402 //copy end of original string
403 wcscpy(pwstOutput + wcslen(pwstOutput), _pwstInput + piStart[iOccurs - 1] + iSearch);
404 }
405
406 FREE(piStart);
407 return pwstOutput;
408}
409/*-------------------------------------------------------------------------------------*/
diff --git a/scilab/modules/string/src/c/tokens.c b/scilab/modules/string/src/c/tokens.c
index 041eb12..391f53a 100644
--- a/scilab/modules/string/src/c/tokens.c
+++ b/scilab/modules/string/src/c/tokens.c
@@ -22,48 +22,48 @@
22 22
23 23
24/*------------------------------------------------------------------------*/ 24/*------------------------------------------------------------------------*/
25char** stringTokens(const char* str, const char* delim, int* sizeoutputs) 25wchar_t** stringTokens(wchar_t* str, wchar_t* delim, int* sizeOutputs)
26{ 26{
27 char **outputs = NULL; 27 wchar_t **Outputs = NULL;
28 *sizeoutputs = 0; 28 *sizeOutputs = 0;
29 if (str) 29 if (str)
30 { 30 {
31 if (delim) 31 if (delim)
32 { 32 {
33 int i = 0; 33 int i = 0;
34 char *pstToken = NULL; 34 wchar_t *pwstToken = NULL;
35 char *pstWork = os_strdup(str); 35 wchar_t *pwstWork = os_wcsdup(str);
36 char *pstState = NULL; 36 wchar_t *pwstState = NULL;
37 37
38 //compute size of outputs array 38 //compute size of outputs array
39 for (pstToken = os_strtok(pstWork, delim, &pstState); 39 for (pwstToken = os_wcstok(pwstWork, delim, &pwstState);
40 pstToken != NULL; 40 pwstToken != NULL;
41 pstToken = os_strtok(NULL, delim, &pstState), (*sizeoutputs)++) 41 pwstToken = os_wcstok(NULL, delim, &pwstState), (*sizeOutputs)++)
42 { 42 {
43 ; 43 ;
44 } 44 }
45 45
46 if (*sizeoutputs == 0) 46 if (*sizeOutputs == 0)
47 { 47 {
48 FREE(pstWork); 48 FREE(pwstWork);
49 return NULL; 49 return NULL;
50 } 50 }
51 51
52 //alloc output array 52 //alloc output array
53 outputs = (char**)MALLOC(sizeof(char*) * *sizeoutputs); 53 Outputs = (wchar_t**)MALLOC(sizeof(wchar_t*) * *sizeOutputs);
54 54
55 FREE(pstWork); 55 FREE(pwstWork);
56 pstWork = os_strdup(str); 56 pwstWork = os_wcsdup(str);
57 for (pstToken = os_strtok(pstWork, delim, &pstState); 57 for (pwstToken = os_wcstok(pwstWork, delim, &pwstState);
58 pstToken != NULL; 58 pwstToken != NULL;
59 pstToken = os_strtok(NULL, delim, &pstState), i++) 59 pwstToken = os_wcstok(NULL, delim, &pwstState), i++)
60 { 60 {
61 outputs[i] = os_strdup(pstToken); 61 Outputs[i] = os_wcsdup(pwstToken);
62 } 62 }
63 63
64 FREE(pstWork); 64 FREE(pwstWork);
65 } 65 }
66 } 66 }
67 return outputs; 67 return Outputs;
68} 68}
69/*--------------------------------------------------------------------------*/ 69/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/string/src/c/tokens.h b/scilab/modules/string/src/c/tokens.h
index fed6f9a..31e9737 100644
--- a/scilab/modules/string/src/c/tokens.h
+++ b/scilab/modules/string/src/c/tokens.h
@@ -27,7 +27,7 @@
27#include <wchar.h> 27#include <wchar.h>
28#include "dynlib_string.h" 28#include "dynlib_string.h"
29 29
30STRING_IMPEXP char** stringTokens(const char* str, const char* delim, int* sizeOutputs); 30STRING_IMPEXP wchar_t** stringTokens(wchar_t* str, wchar_t* delim, int* sizeOutputs);
31 31
32#endif /* __TOKENS_H__ */ 32#endif /* __TOKENS_H__ */
33/*------------------------------------------------------------------------*/ 33/*------------------------------------------------------------------------*/