fix bug 3511: strindex did not return all occurrences in regexp mode. 13/12413/6
Antoine ELIAS [Tue, 3 Sep 2013 09:14:03 +0000 (11:14 +0200)]
Change-Id: I2686977a871b72ab5cc14a8d2c345a5f1484e97d

scilab/CHANGES_5.5.X
scilab/modules/string/Makefile.am
scilab/modules/string/Makefile.in
scilab/modules/string/sci_gateway/c/sci_strindex.c
scilab/modules/string/src/c/string.vcxproj
scilab/modules/string/src/c/string.vcxproj.filters
scilab/modules/string/src/cpp/sort_inter.cpp [new file with mode: 0644]
scilab/modules/string/src/cpp/sort_inter.h [new file with mode: 0644]
scilab/modules/string/tests/nonreg_tests/bug_3511.dia.ref [new file with mode: 0644]
scilab/modules/string/tests/nonreg_tests/bug_3511.tst [new file with mode: 0644]

index 63af1a7..3b243ad 100644 (file)
@@ -199,6 +199,8 @@ Bug fixes
 
 * Bug #2416 fixed - Particular case (string([]) returns []) has been added in the string help page.
 
+* Bug #3511 fixed - strindex did not return all occurrences in regexp mode.
+
 * Bug #3928 fixed - An error was returned when a matrix was flipped along the third dimension.
 
 * Bug #4042 fixed - squeeze returned an hypermatrix instead of a matrix when at least one
index bf4d4c2..a7edc3d 100644 (file)
@@ -31,6 +31,9 @@ src/c/isnum.c \
 src/c/stringToComplex.c \
 src/c/complex_array.c
 
+STRING_CPP_SOURCES = \
+    src/cpp/sort_inter.cpp
+    
 STRING_FORTRAN_SOURCES =
 
 GATEWAY_C_SOURCES = sci_gateway/c/gw_string.c \
@@ -72,6 +75,7 @@ sci_gateway/fortran/strops.f
 
 libscistring_la_CPPFLAGS = -I$(srcdir)/src/c \
        -I$(srcdir)/includes/ \
+       -I$(srcdir)/src/cpp/ \
        -I$(top_srcdir)/modules/functions/includes/ \
        -I$(top_srcdir)/modules/api_scilab/includes/ \
        -I$(top_srcdir)/modules/localization/includes/ \
@@ -90,7 +94,7 @@ endif
 
 libscistring_la_LDFLAGS = $(PCRE_LIBS) $(AM_LDFLAGS)
 
-libscistring_algo_la_SOURCES = $(STRING_C_SOURCES) $(STRING_FORTRAN_SOURCES)
+libscistring_algo_la_SOURCES = $(STRING_C_SOURCES) $(STRING_CPP_SOURCES) $(STRING_FORTRAN_SOURCES)
 libscistring_la_SOURCES = $(GATEWAY_C_SOURCES) $(GATEWAY_FORTRAN_SOURCES)
 libscistring_algo_la_CPPFLAGS = $(libscistring_la_CPPFLAGS)
 
index 70e89d8..e76ee4c 100644 (file)
@@ -189,8 +189,10 @@ am__objects_1 = libscistring_algo_la-code2str.lo \
        libscistring_algo_la-isnum.lo \
        libscistring_algo_la-stringToComplex.lo \
        libscistring_algo_la-complex_array.lo
-am__objects_2 =
-am_libscistring_algo_la_OBJECTS = $(am__objects_1) $(am__objects_2)
+am__objects_2 = libscistring_algo_la-sort_inter.lo
+am__objects_3 =
+am_libscistring_algo_la_OBJECTS = $(am__objects_1) $(am__objects_2) \
+       $(am__objects_3)
 libscistring_algo_la_OBJECTS = $(am_libscistring_algo_la_OBJECTS)
 AM_V_lt = $(am__v_lt_@AM_V@)
 am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
@@ -199,7 +201,7 @@ am__v_lt_1 =
 @MAINTAINER_MODE_FALSE@am_libscistring_algo_la_rpath =
 @MAINTAINER_MODE_TRUE@am_libscistring_algo_la_rpath =
 libscistring_la_DEPENDENCIES = libscistring-algo.la
-am__objects_3 = libscistring_la-gw_string.lo \
+am__objects_4 = libscistring_la-gw_string.lo \
        libscistring_la-sci_ascii.lo libscistring_la-sci_code2str.lo \
        libscistring_la-sci_convstr.lo libscistring_la-sci_emptystr.lo \
        libscistring_la-sci_grep.lo libscistring_la-sci_length.lo \
@@ -218,8 +220,8 @@ am__objects_3 = libscistring_la-gw_string.lo \
        libscistring_la-sci_strstr.lo libscistring_la-sci_strtod.lo \
        libscistring_la-sci_strtok.lo libscistring_la-sci_regexp.lo \
        libscistring_la-sci_isnum.lo
-am__objects_4 = sci_f_string.lo strops.lo
-am_libscistring_la_OBJECTS = $(am__objects_3) $(am__objects_4)
+am__objects_5 = sci_f_string.lo strops.lo
+am_libscistring_la_OBJECTS = $(am__objects_4) $(am__objects_5)
 libscistring_la_OBJECTS = $(am_libscistring_la_OBJECTS)
 libscistring_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=F77 \
        $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(F77LD) \
@@ -261,6 +263,24 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@)
 am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
 am__v_CCLD_0 = @echo "  CCLD    " $@;
 am__v_CCLD_1 = 
+CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+       $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) \
+       $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+       $(AM_CXXFLAGS) $(CXXFLAGS)
+AM_V_CXX = $(am__v_CXX_@AM_V@)
+am__v_CXX_ = $(am__v_CXX_@AM_DEFAULT_V@)
+am__v_CXX_0 = @echo "  CXX     " $@;
+am__v_CXX_1 = 
+CXXLD = $(CXX)
+CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
+       $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CXXLD = $(am__v_CXXLD_@AM_V@)
+am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@)
+am__v_CXXLD_0 = @echo "  CXXLD   " $@;
+am__v_CXXLD_1 = 
 F77COMPILE = $(F77) $(AM_FFLAGS) $(FFLAGS)
 LTF77COMPILE = $(LIBTOOL) $(AM_V_lt) --tag=F77 $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=compile $(F77) $(AM_FFLAGS) $(FFLAGS)
@@ -594,6 +614,9 @@ src/c/isnum.c \
 src/c/stringToComplex.c \
 src/c/complex_array.c
 
+STRING_CPP_SOURCES = \
+    src/cpp/sort_inter.cpp
+
 STRING_FORTRAN_SOURCES = 
 GATEWAY_C_SOURCES = sci_gateway/c/gw_string.c \
 sci_gateway/c/sci_ascii.c \
@@ -632,6 +655,7 @@ sci_gateway/fortran/strops.f
 
 libscistring_la_CPPFLAGS = -I$(srcdir)/src/c \
        -I$(srcdir)/includes/ \
+       -I$(srcdir)/src/cpp/ \
        -I$(top_srcdir)/modules/functions/includes/ \
        -I$(top_srcdir)/modules/api_scilab/includes/ \
        -I$(top_srcdir)/modules/localization/includes/ \
@@ -644,7 +668,7 @@ libscistring_la_CPPFLAGS = -I$(srcdir)/src/c \
 @MAINTAINER_MODE_FALSE@noinst_LTLIBRARIES = libscistring-algo.la libscistring.la
 @MAINTAINER_MODE_TRUE@noinst_LTLIBRARIES = libscistring-algo.la
 libscistring_la_LDFLAGS = $(PCRE_LIBS) $(AM_LDFLAGS)
-libscistring_algo_la_SOURCES = $(STRING_C_SOURCES) $(STRING_FORTRAN_SOURCES)
+libscistring_algo_la_SOURCES = $(STRING_C_SOURCES) $(STRING_CPP_SOURCES) $(STRING_FORTRAN_SOURCES)
 libscistring_la_SOURCES = $(GATEWAY_C_SOURCES) $(GATEWAY_FORTRAN_SOURCES)
 libscistring_algo_la_CPPFLAGS = $(libscistring_la_CPPFLAGS)
 
@@ -745,7 +769,7 @@ HELP_CHAPTERLANG = en_US fr_FR pt_BR
 all: all-am
 
 .SUFFIXES:
-.SUFFIXES: .sci .bin .c .f .lo .o .obj
+.SUFFIXES: .sci .bin .c .cpp .f .lo .o .obj
 $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir)/Makefile.incl.am $(am__configure_deps)
        @for dep in $?; do \
          case '$(am__configure_deps)' in \
@@ -825,7 +849,7 @@ clean-pkglibLTLIBRARIES:
        }
 
 libscistring-algo.la: $(libscistring_algo_la_OBJECTS) $(libscistring_algo_la_DEPENDENCIES) $(EXTRA_libscistring_algo_la_DEPENDENCIES) 
-       $(AM_V_CCLD)$(LINK) $(am_libscistring_algo_la_rpath) $(libscistring_algo_la_OBJECTS) $(libscistring_algo_la_LIBADD) $(LIBS)
+       $(AM_V_CXXLD)$(CXXLINK) $(am_libscistring_algo_la_rpath) $(libscistring_algo_la_OBJECTS) $(libscistring_algo_la_LIBADD) $(LIBS)
 
 libscistring.la: $(libscistring_la_OBJECTS) $(libscistring_la_DEPENDENCIES) $(EXTRA_libscistring_la_DEPENDENCIES) 
        $(AM_V_F77LD)$(libscistring_la_LINK) $(am_libscistring_la_rpath) $(libscistring_la_OBJECTS) $(libscistring_la_LIBADD) $(LIBS)
@@ -853,6 +877,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscistring_algo_la-pcre_private.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscistring_algo_la-scistrtostr.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscistring_algo_la-setScilabCharactersCodes.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscistring_algo_la-sort_inter.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscistring_algo_la-stringToComplex.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscistring_algo_la-stringToDouble.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscistring_algo_la-stringsCompare.Plo@am__quote@
@@ -1322,6 +1347,34 @@ libscistring_la-sci_isnum.lo: sci_gateway/c/sci_isnum.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscistring_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libscistring_la-sci_isnum.lo `test -f 'sci_gateway/c/sci_isnum.c' || echo '$(srcdir)/'`sci_gateway/c/sci_isnum.c
 
+.cpp.o:
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ $<
+
+.cpp.obj:
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+.cpp.lo:
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LTCXXCOMPILE) -c -o $@ $<
+
+libscistring_algo_la-sort_inter.lo: src/cpp/sort_inter.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscistring_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscistring_algo_la-sort_inter.lo -MD -MP -MF $(DEPDIR)/libscistring_algo_la-sort_inter.Tpo -c -o libscistring_algo_la-sort_inter.lo `test -f 'src/cpp/sort_inter.cpp' || echo '$(srcdir)/'`src/cpp/sort_inter.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) $(DEPDIR)/libscistring_algo_la-sort_inter.Tpo $(DEPDIR)/libscistring_algo_la-sort_inter.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='src/cpp/sort_inter.cpp' object='libscistring_algo_la-sort_inter.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscistring_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscistring_algo_la-sort_inter.lo `test -f 'src/cpp/sort_inter.cpp' || echo '$(srcdir)/'`src/cpp/sort_inter.cpp
+
 .f.o:
        $(AM_V_F77)$(F77COMPILE) -c -o $@ $<
 
index 83ae265..0cfcdbd 100644 (file)
@@ -27,7 +27,9 @@
 #include "BOOL.h"
 #include "pcre_error.h"
 #include "Scierror.h"
+#include "sciprint.h"
 #include "charEncoding.h"
+#include "sort_inter.h"
 #ifdef _MSC_VER
 #include "strdup_windows.h"
 #endif
 #define CHAR_S "s"
 #define CHAR_R "r"
 /*------------------------------------------------------------------------*/
-struct In
-{
-    int data;
-    int position;
-} ;
 /*------------------------------------------------------------------------*/
-int cmp( const void *a , const void *b)
+int cmp(In left, In right)
 {
-    return (*(struct In *)a).data > (*(struct In *)b).data ? 1 : -1;
+    return left.data < right.data;
 }
 /*------------------------------------------------------------------------*/
 int sci_strindex(char *fname, unsigned long fname_len)
@@ -131,7 +128,7 @@ int sci_strindex(char *fname, unsigned long fname_len)
         wchar_t **wStrings_Input2 = NULL;
         int m2n2 = 0; /* m2 * n2 */
 
-        struct In *values = NULL;
+        In *values = NULL;
 
         int nbValues = 0;
         int nbposition = 0;
@@ -177,60 +174,136 @@ int sci_strindex(char *fname, unsigned long fname_len)
 
         if ( (int)wcslen(wStrings_Input1) == 0 )
         {
-            values = (struct In*)MALLOC(sizeof(struct In));
+            values = (In*)MALLOC(sizeof(In));
         }
         else
         {
-            values = (struct In *)MALLOC( sizeof(struct In) * ( wcslen(wStrings_Input1) ) * m2n2);
+            values = (In *)MALLOC( sizeof(In) * ( wcslen(wStrings_Input1) ) * m2n2);
         }
 
         if (bStrindex_with_pattern)
         {
             int x = 0;
-            pcre_error_code w = PCRE_FINISHED_OK;
+            pcre_error_code answer = PCRE_FINISHED_OK;
 
             int Output_Start = 0;
             int Output_End = 0;
 
-            /* We use pcre library */
+            int wcOutput_Start = 0;
+            int wcstart_point = 0;
+            int wcOutput_End = 0;
+
             for (x = 0; x < m2n2; ++x)
             {
-                w = pcre_private(Strings_Input1[0], Strings_Input2[x], &Output_Start, &Output_End, NULL, NULL);
-                if ( w == PCRE_FINISHED_OK)
+                char *save = strdup(Strings_Input2[x]);
+                if (save)
                 {
-                    char *partStr = strdup(Strings_Input1[0]);
-                    wchar_t *wcpartStr = NULL;
-                    partStr[Output_Start] = '\0';
-                    wcpartStr = to_wide_string(partStr);
-                    values[nbValues++].data = (int)wcslen(wcpartStr) + 1; /* adding the answer into the outputmatrix */
-                    values[nbposition++].position = x + 1;      /* The number according to the str2 matrix */
-
-                    if (partStr)
+                    char *pointer = Strings_Input1[0];
+                    wcstart_point = 0;
+
+                    do
                     {
-                        FREE(partStr);
-                        partStr = NULL;
+                        strcpy(save, Strings_Input2[x]);
+                        Output_Start = 0;
+                        Output_End = 0;
+
+                        answer = pcre_private(pointer, save, &Output_Start, &Output_End, NULL, NULL);
+                        if ( answer == PCRE_FINISHED_OK )
+                        {
+                            /* Start = End means that we matched a position and 0 characters.
+                            * Matching 0 characters, for us, means no match.
+                            */
+                            if (Output_Start != Output_End)
+                            {
+                                char * strOutput_Start = strdup(pointer);
+                                char *  strOutput_End =  strdup(pointer);
+
+                                wchar_t *wcstrOutput_Start = NULL;
+                                wchar_t *wcstrOutput_End = NULL;
+
+                                /* calculates positions with wide characters */
+                                strOutput_Start[Output_Start] = '\0';
+                                strOutput_End[Output_End] = '\0';
+
+                                wcstrOutput_Start = to_wide_string(strOutput_Start);
+                                wcstrOutput_End = to_wide_string(strOutput_End);
+
+                                if (wcstrOutput_Start)
+                                {
+                                    wcOutput_Start = (int)wcslen(wcstrOutput_Start);
+                                    FREE(wcstrOutput_Start);
+                                    wcstrOutput_Start = NULL;
+                                }
+                                else
+                                {
+                                    wcOutput_Start = 0;
+                                }
+
+                                if (wcstrOutput_End)
+                                {
+                                    wcOutput_End = (int)wcslen(wcstrOutput_End);
+                                    FREE(wcstrOutput_End);
+                                    wcstrOutput_End = NULL;
+                                }
+                                else
+                                {
+                                    wcOutput_End = 0;
+                                }
+
+                                if (strOutput_Start)
+                                {
+                                    FREE(strOutput_Start);
+                                    strOutput_Start = NULL;
+                                }
+                                if (strOutput_End)
+                                {
+                                    FREE(strOutput_End);
+                                    strOutput_End = NULL;
+                                }
+
+                                /*adding the answer into the outputmatrix*/
+                                values[nbValues].data = wcOutput_Start + wcstart_point + 1;
+                                values[nbValues].position = x + 1;
+                                nbValues++;
+                            }
+                            else if (Output_End == 0 && *pointer != '\0')
+                            {
+                                /* Avoid an infinite loop */
+                                pointer++;
+                            }
+
+                            pointer = &pointer[Output_End];
+                            wcstart_point = wcstart_point + wcOutput_End;
+                        }
+                        else
+                        {
+                            if (answer != NO_MATCH)
+                            {
+                                pcre_error(fname, answer);
+                                freeArrayOfString(Strings_Input1, m1n1);
+                                freeArrayOfString(Strings_Input2, m2n2);
+                                return 0;
+                            }
+                        }
                     }
-                    if (wcpartStr)
+                    while ( (answer == PCRE_FINISHED_OK) && (*pointer != '\0'));
+
+                    if (save)
                     {
-                        FREE(wcpartStr);
-                        wcpartStr = NULL;
+                        FREE(save);
+                        save = NULL;
                     }
                 }
                 else
                 {
-                    if (w != NO_MATCH)
-                    {
-                        freeArrayOfString(Strings_Input1, m1n1);
-                        freeArrayOfString(Strings_Input2, m2n2);
-                        pcre_error(fname, w);
-                        return 0;
-                    }
-                    break;
+                    freeArrayOfString(Strings_Input1, m1n1);
+                    freeArrayOfString(Strings_Input2, m2n2);
+                    Scierror(999, _("%s: No more memory.\n"), fname);
+                    return 0;
                 }
             }
 
-            qsort(values, nbValues, sizeof(values[0]), cmp);
-
+            sort_inert(values, values + nbValues, cmp);
         }
         else
         {
@@ -273,7 +346,7 @@ int sci_strindex(char *fname, unsigned long fname_len)
                     while (pCur != NULL && *pCur != 0); //Plus tard
 
                     /* values are sorted */
-                    qsort(values, nbValues, sizeof(values[0]), cmp);
+                    sort_inert(values, values + nbValues, cmp);
                 }
             }
         }
@@ -296,8 +369,8 @@ int sci_strindex(char *fname, unsigned long fname_len)
         {
             numRow   = 1;
             outIndex = 0;
-            CreateVar(Rhs + 2, MATRIX_OF_DOUBLE_DATATYPE, &numRow, &nbposition, &outIndex);
-            for ( i = 0 ; i < nbposition ; i++ )
+            CreateVar(Rhs + 2, MATRIX_OF_DOUBLE_DATATYPE, &numRow, &nbValues, &outIndex);
+            for ( i = 0 ; i < nbValues ; i++ )
             {
                 stk(outIndex)[i] = (double)values[i].position ;
             }
index 7997211..12428c0 100644 (file)
@@ -80,7 +80,7 @@
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>.;../../includes;../../../../libs/pcre;../../../core/includes;../../../api_scilab/includes;../../../windows_tools/includes;../../../localization/includes;../../../output_stream/includes;../../../functions/includes;../../../../libs/intl;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>.;../../includes;../cpp;../../../../libs/pcre;../../../core/includes;../../../api_scilab/includes;../../../windows_tools/includes;../../../localization/includes;../../../output_stream/includes;../../../functions/includes;../../../../libs/intl;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;FORDLL;_DEBUG;_WINDOWS;_USRDLL;STRING_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
       <WarningLevel>Level3</WarningLevel>
@@ -112,7 +112,7 @@ lib /DEF:"$(ProjectDir)functions_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platf
     </Midl>
     <ClCompile>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>.;../../includes;../../../../libs/pcre;../../../core/includes;../../../api_scilab/includes;../../../windows_tools/includes;../../../localization/includes;../../../output_stream/includes;../../../functions/includes;../../../../libs/intl;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>.;../../includes;../cpp;../../../../libs/pcre;../../../core/includes;../../../api_scilab/includes;../../../windows_tools/includes;../../../localization/includes;../../../output_stream/includes;../../../functions/includes;../../../../libs/intl;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;FORDLL;_DEBUG;_WINDOWS;_USRDLL;STRING_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
       <WarningLevel>Level3</WarningLevel>
@@ -142,7 +142,7 @@ lib /DEF:"$(ProjectDir)functions_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platf
     <ClCompile>
       <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
       <WholeProgramOptimization>false</WholeProgramOptimization>
-      <AdditionalIncludeDirectories>.;../../includes;../../../../libs/pcre;../../../core/includes;../../../api_scilab/includes;../../../windows_tools/includes;../../../localization/includes;../../../output_stream/includes;../../../functions/includes;../../../../libs/intl;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>.;../../includes;../cpp;../../../../libs/pcre;../../../core/includes;../../../api_scilab/includes;../../../windows_tools/includes;../../../localization/includes;../../../output_stream/includes;../../../functions/includes;../../../../libs/intl;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;FORDLL;NDEBUG;_WINDOWS;_USRDLL;STRING_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <StringPooling>true</StringPooling>
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
@@ -180,7 +180,7 @@ lib /DEF:"$(ProjectDir)functions_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platf
     <ClCompile>
       <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
       <WholeProgramOptimization>false</WholeProgramOptimization>
-      <AdditionalIncludeDirectories>.;../../includes;../../../../libs/pcre;../../../core/includes;../../../api_scilab/includes;../../../windows_tools/includes;../../../localization/includes;../../../output_stream/includes;../../../functions/includes;../../../../libs/intl;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>.;../../includes;../cpp;../../../../libs/pcre;../../../core/includes;../../../api_scilab/includes;../../../windows_tools/includes;../../../localization/includes;../../../output_stream/includes;../../../functions/includes;../../../../libs/intl;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;FORDLL;NDEBUG;_WINDOWS;_USRDLL;STRING_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <StringPooling>true</StringPooling>
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
@@ -212,6 +212,7 @@ lib /DEF:"$(ProjectDir)functions_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platf
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClCompile Include="..\cpp\sort_inter.cpp" />
     <ClCompile Include="code2str.c" />
     <ClCompile Include="convstr.c" />
     <ClCompile Include="cvstr.c" />
@@ -326,6 +327,7 @@ lib /DEF:"$(ProjectDir)functions_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platf
     <ClInclude Include="..\..\includes\strsubst.h" />
     <ClInclude Include="..\..\includes\stringToComplex.h" />
     <ClInclude Include="..\..\includes\complex_array.h" />
+    <ClInclude Include="..\cpp\sort_inter.h" />
     <ClInclude Include="config.h" />
     <ClInclude Include="convstr.h" />
     <ClInclude Include="CreateEmptystr.h" />
index cc204d7..fc09780 100644 (file)
     <ClCompile Include="..\..\sci_gateway\c\sci_strcspn.c">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="..\..\sci_gateway\c\sci_strindex.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="..\..\sci_gateway\c\sci_string.c">
       <Filter>Source Files</Filter>
     </ClCompile>
     <ClCompile Include="complex_array.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\sci_gateway\c\sci_strindex.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\cpp\sort_inter.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <None Include="core_import.def">
     <ClInclude Include="isnum.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\cpp\sort_inter.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>
\ No newline at end of file
diff --git a/scilab/modules/string/src/cpp/sort_inter.cpp b/scilab/modules/string/src/cpp/sort_inter.cpp
new file mode 100644 (file)
index 0000000..76fc9fd
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2013 - Scilab Enterprises - Antoine ELIAS
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+
+extern "C"
+{
+#include "sort_inter.h"
+}
+
+#include <algorithm>
+
+void sort_inert(In* pBegin, In* pEnd, cmp_func func)
+{
+    std::sort(pBegin, pEnd, func);
+}
\ No newline at end of file
diff --git a/scilab/modules/string/src/cpp/sort_inter.h b/scilab/modules/string/src/cpp/sort_inter.h
new file mode 100644 (file)
index 0000000..ea7c7df
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2013 - Scilab Enterprises - Antoine ELIAS
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+
+typedef struct __In__
+{
+    int data;
+    int position;
+} In;
+
+
+typedef int (* cmp_func)(In left, In right);
+
+void sort_inert(In* pBegin, In* pEnd, cmp_func func);
diff --git a/scilab/modules/string/tests/nonreg_tests/bug_3511.dia.ref b/scilab/modules/string/tests/nonreg_tests/bug_3511.dia.ref
new file mode 100644 (file)
index 0000000..ffd29f9
--- /dev/null
@@ -0,0 +1,20 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2008-2008 - DIGITEO - Simon LIPP <simon.lipp@scilab.org>
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
+// <-- Non-regression test for bug 3500 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=3500
+//
+// Short description:
+// strindex cannot return all occurrences in regexp mode
+[k,w]=strindex('a aa aab aaa','/aa*/','r');
+assert_checkequal(k, [1 3 6 10]);
+assert_checkequal(w, [1 1 1 1]);
+[k,w]=strindex('a aa aab aaa',['/aa*/' '/aa/'],'r');
+assert_checkequal(k, [1 3 3 6 6 10 10]);
+assert_checkequal(w, [1 1 2 1 2 1 2]);
diff --git a/scilab/modules/string/tests/nonreg_tests/bug_3511.tst b/scilab/modules/string/tests/nonreg_tests/bug_3511.tst
new file mode 100644 (file)
index 0000000..f6f96fd
--- /dev/null
@@ -0,0 +1,24 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2008-2008 - DIGITEO - Simon LIPP <simon.lipp@scilab.org>
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- CLI SHELL MODE -->
+
+// <-- Non-regression test for bug 3500 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=3500
+//
+// Short description:
+// strindex cannot return all occurrences in regexp mode
+
+[k,w]=strindex('a aa aab aaa','/aa*/','r');
+assert_checkequal(k, [1 3 6 10]);
+assert_checkequal(w, [1 1 1 1]);
+
+[k,w]=strindex('a aa aab aaa',['/aa*/' '/aa/'],'r');
+assert_checkequal(k, [1 3 3 6 6 10 10]);
+assert_checkequal(w, [1 1 2 1 2 1 2]);