1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-07 18:30:55 +03:00

0024603: The code in TCollection_AsciiString::Search* methods can be simplified

Small improvement in TCollection_AsciiString::Search.
This commit is contained in:
szv 2013-03-28 12:13:26 +04:00 committed by apn
parent 97f7a9d875
commit feb2743f11

View File

@ -990,14 +990,12 @@ Standard_Integer TCollection_AsciiString::Search
if (size) { if (size) {
int k,j; int k,j;
int i = 0; int i = 0;
Standard_Boolean find = Standard_False; while ( i < mylength-size+1 ) {
while ( i < mylength-size+1 && !find) {
k = i++; k = i++;
j = 0; j = 0;
while (j < size && mystring[k++] == swhat[j++]) while (j < size && mystring[k++] == swhat[j++])
if (j == size) find = Standard_True; if (j == size) return i;
} }
if (find) return i;
} }
return -1; return -1;
} }
@ -1013,14 +1011,12 @@ Standard_Integer TCollection_AsciiString::SearchFromEnd
if (size) { if (size) {
int k,j; int k,j;
int i = mylength-1; int i = mylength-1;
Standard_Boolean find = Standard_False; while ( i >= size-1 ) {
while ( i >= size-1 && !find) {
k = i--; k = i--;
j = size-1; j = size-1;
while (j >= 0 && mystring[k--] == what[j--]) while (j >= 0 && mystring[k--] == what[j--])
if (j == -1) find = Standard_True; if (j == -1) return i-size+3;
} }
if (find) return i-size+3;
} }
return -1; return -1;
} }
@ -1037,14 +1033,12 @@ Standard_Integer TCollection_AsciiString::SearchFromEnd
Standard_CString swhat = what.mystring; Standard_CString swhat = what.mystring;
int k,j; int k,j;
int i = mylength-1; int i = mylength-1;
Standard_Boolean find = Standard_False; while ( i >= size-1 ) {
while ( i >= size-1 && !find) {
k = i--; k = i--;
j = size-1; j = size-1;
while (j >= 0 && mystring[k--] == swhat[j--]) while (j >= 0 && mystring[k--] == swhat[j--])
if (j == -1) find = Standard_True; if (j == -1) return i-size+3;
} }
if (find) return i-size+3;
} }
return -1; return -1;
} }