diff --git a/src/kits/tracker/TrackerString.cpp b/src/kits/tracker/TrackerString.cpp index dfa5e89437..b559139c61 100644 --- a/src/kits/tracker/TrackerString.cpp +++ b/src/kits/tracker/TrackerString.cpp @@ -163,275 +163,6 @@ TrackerString::Contains(const char* string, bool caseSensitivity) const } -// About the ?Find* functions: -// The leading star here has been compliance with BString, -// simplicity and performance. Therefore unncessary copying -// has been avoided, as unncessary function calls. -// The copying has been avoided by implementing the -// ?Find*(const char*) functions rather than -// the ?Find*(TrackerString &) functions. -// The function calls has been avoided by -// inserting a check on the first character -// before calling the str*cmp functions. - - -int32 -TrackerString::FindFirst(const BString &string) const -{ - return FindFirst(string.String(), 0); -} - - -int32 -TrackerString::FindFirst(const char* string) const -{ - return FindFirst(string, 0); -} - - -int32 -TrackerString::FindFirst(const BString &string, int32 fromOffset) const -{ - return FindFirst(string.String(), fromOffset); -} - - -int32 -TrackerString::FindFirst(const char* string, int32 fromOffset) const -{ - if (string == NULL) - return -1; - - int32 length = Length(); - uint32 stringLength = strlen(string); - - // The following two checks are required to be compatible - // with BString: - if (length <= 0) - return -1; - - if (stringLength == 0) - return fromOffset; - - int32 stop = length - static_cast(stringLength); - int32 start = MAX(0, MIN(fromOffset, stop)); - int32 position = -1; - - for (int32 i = start; i <= stop; i++) { - if (string[0] == ByteAt(i)) { - // This check is to avoid mute str*cmp() calls. Performance. - if (strncmp(string, String() + i, stringLength) == 0) { - position = i; - break; - } - } - } - - return position; -} - - -int32 -TrackerString::FindFirst(char ch) const -{ - char string[2] = {ch, '\0'}; - return FindFirst(string, 0); -} - - -int32 -TrackerString::FindFirst(char ch, int32 fromOffset) const -{ - char string[2] = {ch, '\0'}; - return FindFirst(string, fromOffset); -} - - -int32 -TrackerString::FindLast(const BString &string) const -{ - return FindLast(string.String(), Length() - 1); -} - - -int32 -TrackerString::FindLast(const char* string) const -{ - return FindLast(string, Length() - 1); -} - - -int32 -TrackerString::FindLast(const BString &string, int32 beforeOffset) const -{ - return FindLast(string.String(), beforeOffset); -} - - -int32 -TrackerString::FindLast(const char* string, int32 beforeOffset) const -{ - if (string == NULL) - return -1; - - int32 length = Length(); - uint32 stringLength = strlen(string); - - // The following two checks are required to be compatible - // with BString: - if (length <= 0) - return -1; - - if (stringLength == 0) - return beforeOffset; - - int32 start = MIN(beforeOffset, - length - static_cast(stringLength)); - int32 stop = 0; - int32 position = -1; - - for (int32 i = start; i >= stop; i--) { - if (string[0] == ByteAt(i)) { - // This check is to avoid mute str*cmp() calls. Performance. - if (strncmp(string, String() + i, stringLength) == 0) { - position = i; - break; - } - } - } - - return position; -} - - -int32 -TrackerString::FindLast(char ch) const -{ - char string[2] = {ch, '\0'}; - return FindLast(string, Length() - 1); -} - - -int32 -TrackerString::FindLast(char ch, int32 beforeOffset) const -{ - char string[2] = {ch, '\0'}; - return FindLast(string, beforeOffset); -} - - -int32 -TrackerString::IFindFirst(const BString &string) const -{ - return IFindFirst(string.String(), 0); -} - - -int32 -TrackerString::IFindFirst(const char* string) const -{ - return IFindFirst(string, 0); -} - - -int32 -TrackerString::IFindFirst(const BString &string, int32 fromOffset) const -{ - return IFindFirst(string.String(), fromOffset); -} - - -int32 -TrackerString::IFindFirst(const char* string, int32 fromOffset) const -{ - if (string == NULL) - return -1; - - int32 length = Length(); - uint32 stringLength = strlen(string); - - // The following two checks are required to be compatible - // with BString: - if (length <= 0) - return -1; - - if (stringLength == 0) - return fromOffset; - - int32 stop = length - static_cast(stringLength); - int32 start = MAX(0, MIN(fromOffset, stop)); - int32 position = -1; - - for (int32 i = start; i <= stop; i++) { - if (tolower(string[0]) == tolower(ByteAt(i))) { - // This check is to avoid mute str*cmp() calls. Performance. - if (strncasecmp(string, String() + i, stringLength) == 0) { - position = i; - break; - } - } - } - - return position; -} - - -int32 -TrackerString::IFindLast(const BString &string) const -{ - return IFindLast(string.String(), Length() - 1); -} - - -int32 -TrackerString::IFindLast(const char* string) const -{ - return IFindLast(string, Length() - 1); -} - - -int32 -TrackerString::IFindLast(const BString &string, int32 beforeOffset) const -{ - return IFindLast(string.String(), beforeOffset); -} - - -int32 -TrackerString::IFindLast(const char* string, int32 beforeOffset) const -{ - if (string == NULL) - return -1; - - int32 length = Length(); - uint32 stringLength = strlen(string); - - // The following two checks are required to be compatible - // with BString: - if (length <= 0) - return -1; - - if (stringLength == 0) - return beforeOffset; - - int32 start = MIN(beforeOffset, length - static_cast(stringLength)); - int32 stop = 0; - int32 position = -1; - - for (int32 i = start; i >= stop; i--) { - if (tolower(string[0]) == tolower(ByteAt(i))) { - // This check is to avoid mute str*cmp() calls. Performance. - if (strncasecmp(string, String() + i, stringLength) == 0) { - position = i; - break; - } - } - } - - return position; -} - - // MatchesBracketExpression() assumes 'pattern' to point to the // character following the initial '[' in a bracket expression. // The reason is that an encountered '[' will be taken literally. diff --git a/src/kits/tracker/TrackerString.h b/src/kits/tracker/TrackerString.h index d53f8b006b..0706ac9020 100644 --- a/src/kits/tracker/TrackerString.h +++ b/src/kits/tracker/TrackerString.h @@ -76,30 +76,6 @@ public: bool StartsWith(const char*, bool caseSensitivity = false) const; bool Contains(const char*, bool caseSensitivity = false) const; - int32 FindFirst(const BString&) const; - int32 FindFirst(const char*) const; - int32 FindFirst(const BString&, int32 fromOffset) const; - int32 FindFirst(const char*, int32 fromOffset) const; - int32 FindFirst(char) const; - int32 FindFirst(char, int32 fromOffset) const; - - int32 FindLast(const BString&) const; - int32 FindLast(const char*) const; - int32 FindLast(const BString&, int32 beforeOffset) const; - int32 FindLast(const char*, int32 beforeOffset) const; - int32 FindLast(char) const; - int32 FindLast(char, int32 beforeOffset) const; - - int32 IFindFirst(const BString&) const; - int32 IFindFirst(const char*) const; - int32 IFindFirst(const BString&, int32 fromOffset) const; - int32 IFindFirst(const char*, int32 fromOffset) const; - - int32 IFindLast(const BString&) const; - int32 IFindLast(const char*) const; - int32 IFindLast(const BString&, int32 beforeOffset) const; - int32 IFindLast(const char*, int32 beforeOffset) const; - private: bool IsGlyph(char) const; bool IsInsideGlyph(char) const;