--- a/String.st Thu Oct 13 11:39:45 2016 +0200
+++ b/String.st Thu Oct 13 11:43:15 2016 +0200
@@ -4381,7 +4381,7 @@
slowIndexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue caseSensitive:caseSensitive
"naive search fallback (non-BM).
Use this for short searchStrings (<= 2)
- or for caseSensitive searches"
+ or for caseInSensitive searches"
|notFound|
@@ -4392,103 +4392,103 @@
&& (__isSmallInteger(startIndex))
&& (__intVal(startIndex) > 0)
) {
- unsigned char *c_pSelf = __stringVal(self);
- unsigned char *c_substring = __stringVal(aSubString);
- unsigned char *c_pSelfI, *c_pSelfMax;
- int c_lenSelf = __stringSize(self);
- int c_lenSubstring = __stringSize(aSubString);
- int c_idx0Max = c_lenSelf - c_lenSubstring;
- unsigned char c_first;
- unsigned char c_ucFirst;
- unsigned char c_lcFirst;
- unsigned char c_oppositeCaseFirst;
- int i;
-
- if (c_lenSubstring == 0) {
+ unsigned char *c_pSelf = __stringVal(self);
+ unsigned char *c_substring = __stringVal(aSubString);
+ unsigned char *c_pSelfI, *c_pSelfMax;
+ int c_lenSelf = __stringSize(self);
+ int c_lenSubstring = __stringSize(aSubString);
+ int c_idx0Max = c_lenSelf - c_lenSubstring;
+ unsigned char c_first;
+ unsigned char c_ucFirst;
+ unsigned char c_lcFirst;
+ unsigned char c_oppositeCaseFirst;
+ int i;
+
+ if (c_lenSubstring == 0) {
#if 1
- /* empty string does not match */
- notFound = true;
- goto getOutOfHere;
+ /* empty string does not match */
+ notFound = true;
+ goto getOutOfHere;
#else
- /* empty string matches */
- RETURN(startIndex);
+ /* empty string matches */
+ RETURN(startIndex);
#endif
- }
-
- // searched string's length > string
- if (c_idx0Max < 0) {
- notFound = true;
- goto getOutOfHere;
- }
-
- c_first = c_lcFirst = c_substring[0];
- if (((c_first >= 'A') && (c_first <= 'Z'))
- || ((c_first >= 0xC0) && (c_first <= 0xDE))) {
- c_ucFirst = c_first;
- c_lcFirst = c_oppositeCaseFirst = c_first - 'A' + 'a';
- } else {
- if (((c_first >= 'a') && (c_first <= 'z'))
- || ((c_first >= 0xE0) && (c_first <= 0xFE))) {
- c_lcFirst = c_first;
- c_ucFirst = c_oppositeCaseFirst = c_first - 'a' + 'A';
- }
- }
-
- // idx:
- // 0123456789
-
- // 1234567890 - lenSelf = 10
- // abc - lenSubstring = 3
- // - idx0Max = 7 (last legal startIndex)
-
- i = __intVal(startIndex) - 1;
- c_pSelfI = c_pSelf + i;
- c_pSelfMax = c_pSelf + c_idx0Max;
-
- for (; c_pSelfI <= c_pSelfMax; c_pSelfI++) {
- int j;
- unsigned char c_selfChar;
-
- // find the first char
- c_selfChar = c_pSelfI[0];
- if (c_selfChar != c_first) {
- if (caseSensitive == true) continue;
- if (c_selfChar != c_oppositeCaseFirst) {
+ }
+
+ // searched string's length > string
+ if (c_idx0Max < 0) {
+ notFound = true;
+ goto getOutOfHere;
+ }
+
+ c_first = c_lcFirst = c_substring[0];
+ if (((c_first >= 'A') && (c_first <= 'Z'))
+ || ((c_first >= 0xC0) && (c_first <= 0xDE))) {
+ c_ucFirst = c_first;
+ c_lcFirst = c_oppositeCaseFirst = c_first - 'A' + 'a';
+ } else {
+ if (((c_first >= 'a') && (c_first <= 'z'))
+ || ((c_first >= 0xE0) && (c_first <= 0xFE))) {
+ c_lcFirst = c_first;
+ c_ucFirst = c_oppositeCaseFirst = c_first - 'a' + 'A';
+ }
+ }
+
+ // idx:
+ // 0123456789
+
+ // 1234567890 - lenSelf = 10
+ // abc - lenSubstring = 3
+ // - idx0Max = 7 (last legal startIndex)
+
+ i = __intVal(startIndex) - 1;
+ c_pSelfI = c_pSelf + i;
+ c_pSelfMax = c_pSelf + c_idx0Max;
+
+ for (; c_pSelfI <= c_pSelfMax; c_pSelfI++) {
+ int j;
+ unsigned char c_selfChar;
+
+ // find the first char
+ c_selfChar = c_pSelfI[0];
+ if (c_selfChar != c_first) {
+ if (caseSensitive == true) continue;
+ if (c_selfChar != c_oppositeCaseFirst) {
searchNext: ;
- continue;
- }
- }
-
- // first char matches
- // compare rest
- for (j=1; j<c_lenSubstring; j++) {
- unsigned char c_selfChar, c_subChar, c_lcSubChar, c_ucSubChar;
-
- c_subChar = c_substring[j];
- c_selfChar = c_pSelfI[j];
-
- if (c_selfChar == c_subChar) continue;
- if (caseSensitive == true) goto searchNext;
-
- c_lcSubChar = c_subChar;
- if (((c_lcSubChar >= 'A') && (c_lcSubChar <= 'Z'))
- || ((c_lcSubChar >= 0xC0) && (c_lcSubChar <= 0xDE))) {
- c_lcSubChar = c_subChar - 'A' + 'a';
- if (c_selfChar != c_lcSubChar) goto searchNext;
- } else {
- if (((c_lcSubChar >= 'a') && (c_lcSubChar <= 'z'))
- || ((c_lcSubChar >= 0xE0) && (c_lcSubChar <= 0xFE))) {
- c_ucSubChar = c_subChar - 'a' + 'A';
- if (c_selfChar != c_ucSubChar) goto searchNext;
- } else {
- goto searchNext;
- }
- }
- }
- // if we arrive here, we have a match at i
- RETURN( __mkSmallInteger( c_pSelfI - c_pSelf + 1 ) );
- }
- notFound = true;
+ continue;
+ }
+ }
+
+ // first char matches
+ // compare rest
+ for (j=1; j<c_lenSubstring; j++) {
+ unsigned char c_selfChar, c_subChar, c_lcSubChar, c_ucSubChar;
+
+ c_subChar = c_substring[j];
+ c_selfChar = c_pSelfI[j];
+
+ if (c_selfChar == c_subChar) continue;
+ if (caseSensitive == true) goto searchNext;
+
+ c_lcSubChar = c_subChar;
+ if (((c_lcSubChar >= 'A') && (c_lcSubChar <= 'Z'))
+ || ((c_lcSubChar >= 0xC0) && (c_lcSubChar <= 0xDE))) {
+ c_lcSubChar = c_subChar - 'A' + 'a';
+ if (c_selfChar != c_lcSubChar) goto searchNext;
+ } else {
+ if (((c_lcSubChar >= 'a') && (c_lcSubChar <= 'z'))
+ || ((c_lcSubChar >= 0xE0) && (c_lcSubChar <= 0xFE))) {
+ c_ucSubChar = c_subChar - 'a' + 'A';
+ if (c_selfChar != c_ucSubChar) goto searchNext;
+ } else {
+ goto searchNext;
+ }
+ }
+ }
+ // if we arrive here, we have a match at i
+ RETURN( __mkSmallInteger( c_pSelfI - c_pSelf + 1 ) );
+ }
+ notFound = true;
}
getOutOfHere: ;
@@ -4496,7 +4496,7 @@
%}.
"/ arrive here if either not found, or invalid arguments
notFound == true ifTrue:[
- ^ exceptionValue value.
+ ^ exceptionValue value.
].
^ super indexOfSubCollection:aSubString startingAt:startIndex ifAbsent:exceptionValue caseSensitive:caseSensitive