diff --git a/Jupiter/Readable_String.h b/Jupiter/Readable_String.h index e5f31e5..431ca7a 100644 --- a/Jupiter/Readable_String.h +++ b/Jupiter/Readable_String.h @@ -157,6 +157,7 @@ namespace Jupiter */ bool match(const Readable_String &format) const; bool match(const std::basic_string &format) const; + bool match(const T *format, size_t formatSize) const; bool match(const T *format) const; /** @@ -168,6 +169,7 @@ namespace Jupiter */ bool matchi(const Readable_String &format) const; bool matchi(const std::basic_string &format) const; + bool matchi(const T *format, size_t formatSize) const; bool matchi(const T *format) const; /** diff --git a/Jupiter/Readable_String_Imp.h b/Jupiter/Readable_String_Imp.h index 4607b9c..7ede4d3 100644 --- a/Jupiter/Readable_String_Imp.h +++ b/Jupiter/Readable_String_Imp.h @@ -366,138 +366,147 @@ template bool Jupiter::Readable_String::equalsi(const std::nullpt // match() -template<> bool inline Jupiter::Readable_String::match(const Jupiter::Readable_String &format) const -{ - size_t index = 0; - size_t formatIndex = 0; - while (formatIndex != format.size()) - { - if (format.get(formatIndex) == '*') - { - formatIndex++; - while (format.get(formatIndex) == '?') - { - if (this->get(index) == 0) return false; - formatIndex++; - index++; - } - if (format.get(formatIndex) == 0) return true; - if (format.get(formatIndex) == '*') continue; - while (format.get(formatIndex) != this->get(index)) - { - if (this->get(index) == 0) return false; - index++; - } - } - else if (format.get(formatIndex) != '?' && format.get(formatIndex) != this->get(index)) return false; - formatIndex++; - index++; - } - return index == this->size(); -} - -template<> bool inline Jupiter::Readable_String::match(const Jupiter::Readable_String &format) const +template bool Jupiter::Readable_String::match(const Jupiter::Readable_String &format) const { - size_t index = 0; - size_t formatIndex = 0; - while (formatIndex != format.size()) - { - if (format.get(formatIndex) == '*') - { - formatIndex++; - while (format.get(formatIndex) == '?') - { - if (this->get(index) == 0) return false; - formatIndex++; - index++; - } - if (format.get(formatIndex) == 0) return true; - if (format.get(formatIndex) == '*') continue; - while (format.get(formatIndex) != this->get(index)) - { - if (this->get(index) == 0) return false; - index++; - } - } - else if (format.get(formatIndex) != '?' && format.get(formatIndex) != this->get(index)) return false; - formatIndex++; - index++; - } - return index == this->size(); + return this->match(format.ptr(), format.size()); } -template bool Jupiter::Readable_String::match(const Jupiter::Readable_String &format) const +template bool Jupiter::Readable_String::match(const std::basic_string &format) const { - return false; // Wildcard matching not supported for type. + return this->match(format.data(), format.size()); } -template<> bool inline Jupiter::Readable_String::match(const std::basic_string &format) const +template<> bool inline Jupiter::Readable_String::match(const char *format, size_t formatSize) const { + if (this->size() == 0) + { + if (formatSize == 0) + return true; + while (format[--formatSize] == '*') + if (formatSize == 0) + return *format == '*'; + return false; + } size_t index = 0; size_t formatIndex = 0; - while (formatIndex != format.size()) + while (formatIndex != formatSize) { - if (format.at(formatIndex) == '*') + if (format[formatIndex] == '*') { - formatIndex++; - while (format.at(formatIndex) == '?') + if (++formatIndex == formatSize) + return true; + + while (format[formatIndex] == '?') { - if (this->get(index) == 0) return false; - formatIndex++; - index++; + if (++formatIndex == formatSize) + return true; + if (++index == this->size()) + { + while (format[formatIndex++] == '*') + if (formatIndex == formatSize) + return true; + return false; + } } - if (format.at(formatIndex) == 0) return true; - if (format.at(formatIndex) == '*') continue; - while (format.at(formatIndex) != this->get(index)) + if (format[formatIndex] == '*') continue; + + while (format[formatIndex] != this->get(index)) { - if (this->get(index) == 0) return false; - index++; + if (++index == this->size()) + { + while (format[formatIndex] == '*') + if (++formatIndex == formatSize) + return true; + return false; + } } } - else if (format.at(formatIndex) != '?' && format.at(formatIndex) != this->get(index)) return false; + else if (format[formatIndex] != '?' && format[formatIndex] != this->get(index)) return false; formatIndex++; - index++; + if (++index == this->size()) + { + if (formatIndex == formatSize) + return true; + while (format[formatIndex] == '*') + if (++formatIndex == formatSize) + return true; + return false; + } } - return index == this->size(); + return false; } -template<> bool inline Jupiter::Readable_String::match(const std::basic_string &format) const +template<> bool inline Jupiter::Readable_String::match(const wchar_t *format, size_t formatSize) const { + if (this->size() == 0) + { + if (formatSize == 0) + return true; + while (format[--formatSize] == L'*') + if (formatSize == 0) + return *format == L'*'; + return false; + } size_t index = 0; size_t formatIndex = 0; - while (formatIndex != format.size()) + while (formatIndex != formatSize) { - if (format.at(formatIndex) == '*') + if (format[formatIndex] == L'*') { - formatIndex++; - while (format.at(formatIndex) == '?') + if (++formatIndex == formatSize) + return true; + + while (format[formatIndex] == L'?') { - if (this->get(index) == 0) return false; - formatIndex++; - index++; + if (++formatIndex == formatSize) + return index + 1 == this->size(); + if (++index == this->size()) + { + while (format[formatIndex++] == L'*') + if (formatIndex == formatSize) + return true; + return false; + } } - if (format.at(formatIndex) == 0) return true; - if (format.at(formatIndex) == '*') continue; - while (format.at(formatIndex) != this->get(index)) + if (format[formatIndex] == L'*') continue; + + while (format[formatIndex] != this->get(index)) { - if (this->get(index) == 0) return false; - index++; + if (++index == this->size()) + { + while (format[formatIndex] == L'*') + if (++formatIndex == formatSize) + return true; + return false; + } } } - else if (format.at(formatIndex) != '?' && format.at(formatIndex) != this->get(index)) return false; + else if (format[formatIndex] != L'?' && format[formatIndex] != this->get(index)) return false; formatIndex++; - index++; + if (++index == this->size()) + { + while (format[formatIndex] == L'*') + if (++formatIndex == formatSize) + return true; + return false; + } } - return index == this->size(); + return false; } -template bool Jupiter::Readable_String::match(const std::basic_string &format) const +template bool Jupiter::Readable_String::match(const T *, size_t) const { return false; // Wildcard matching not supported for type. } -template<> inline bool Jupiter::Readable_String::match(const char *format) const +template<> bool inline Jupiter::Readable_String::match(const char *format) const { + if (this->size() == 0) + { + while (*format == '*') + format++; + return *format == 0; + } size_t index = 0; while (*format != 0) { @@ -506,27 +515,47 @@ template<> inline bool Jupiter::Readable_String::match(const char *format) format++; while (*format == '?') { - if (this->get(index) == 0) return false; format++; - index++; + if (++index == this->size()) + { + while (*format == '*') + format++; + return *format == 0; + } } if (*format == 0) return true; if (*format == '*') continue; + while (*format != this->get(index)) { - if (this->get(index) == 0) return false; - index++; + if (++index == this->size()) + { + while (*format == '*') + format++; + return *format == 0; + } } } else if (*format != '?' && *format != this->get(index)) return false; format++; - index++; + if (++index == this->size()) + { + while (*format == '*') + format++; + return *format == 0; + } } - return index == this->size(); + return false; } -template<> inline bool Jupiter::Readable_String::match(const wchar_t *format) const +template<> bool inline Jupiter::Readable_String::match(const wchar_t *format) const { + if (this->size() == 0) + { + while (*format == L'*') + format++; + return *format == 0; + } size_t index = 0; while (*format != 0) { @@ -535,23 +564,37 @@ template<> inline bool Jupiter::Readable_String::match(const wchar_t *f format++; while (*format == L'?') { - if (this->get(index) == 0) return false; format++; - index++; + if (this->size() == 0) + { + while (*format == L'*') + format++; + return *format == 0; + } } if (*format == 0) return true; - if (*format == L'*') continue; + if (*format == '*') continue; + while (*format != this->get(index)) { - if (this->get(index) == 0) return false; - index++; + if (this->size() == 0) + { + while (*format == L'*') + format++; + return *format == 0; + } } } else if (*format != L'?' && *format != this->get(index)) return false; format++; - index++; + if (this->size() == 0) + { + while (*format == L'*') + format++; + return *format == 0; + } } - return index == this->size(); + return false; } template bool Jupiter::Readable_String::match(const T *format) const @@ -561,147 +604,147 @@ template bool Jupiter::Readable_String::match(const T *format) co // matchi() -template<> bool inline Jupiter::Readable_String::matchi(const Jupiter::Readable_String &format) const +template bool Jupiter::Readable_String::matchi(const Jupiter::Readable_String &format) const { - int fUpper; - size_t index = 0; - size_t formatIndex = 0; - while (formatIndex != format.size()) - { - if (format.get(formatIndex) == L'*') - { - formatIndex++; - while (format.get(formatIndex) == L'?') - { - if (this->get(index) == 0) return false; - formatIndex++; - index++; - } - if (format.get(formatIndex) == 0) return true; - if (format.get(formatIndex) == '*') continue; - fUpper = toupper(format.get(formatIndex)); - while (fUpper != toupper(this->get(index))) - { - if (this->get(index) == 0) return false; - index++; - } - } - else if (format.get(formatIndex) != L'?' && toupper(format.get(formatIndex)) != toupper(this->get(index))) return false; - formatIndex++; - index++; - } - return index == this->size(); + return this->matchi(format.ptr(), format.size()); } -template<> bool inline Jupiter::Readable_String::matchi(const Jupiter::Readable_String &format) const -{ - wint_t fUpper; - size_t index = 0; - size_t formatIndex = 0; - while (formatIndex != format.size()) - { - if (format.get(formatIndex) == L'*') - { - formatIndex++; - while (format.get(formatIndex) == L'?') - { - if (this->get(index) == 0) return false; - formatIndex++; - index++; - } - if (format.get(formatIndex) == 0) return true; - if (format.get(formatIndex) == '*') continue; - fUpper = towupper(format.get(formatIndex)); - while (fUpper != towupper(this->get(index))) - { - if (this->get(index) == 0) return false; - index++; - } - } - else if (format.get(formatIndex) != L'?' && towupper(format.get(formatIndex)) != towupper(this->get(index))) return false; - formatIndex++; - index++; - } - return index == this->size(); -} - -template bool Jupiter::Readable_String::matchi(const Jupiter::Readable_String &format) const +template bool Jupiter::Readable_String::matchi(const std::basic_string &format) const { - return false; // Wildcard matching not supported for type. Concept of "case" not supported for type. + return this->matchi(format.data(), format.size()); } -template<> bool inline Jupiter::Readable_String::matchi(const std::basic_string &format) const +template<> bool inline Jupiter::Readable_String::matchi(const char *format, size_t formatSize) const { - int fUpper; + if (this->size() == 0) + { + if (formatSize == 0) + return true; + while (format[--formatSize] == '*') + if (formatSize == 0) + return *format == '*'; + return false; + } size_t index = 0; size_t formatIndex = 0; - while (formatIndex != format.size()) + while (formatIndex != formatSize) { - if (format.at(formatIndex) == L'*') + if (format[formatIndex] == '*') { - formatIndex++; - while (format.at(formatIndex) == L'?') + if (++formatIndex == formatSize) + return true; + + while (format[formatIndex] == '?') { - if (this->get(index) == 0) return false; - formatIndex++; - index++; + if (++formatIndex == formatSize) + return true; + if (++index == this->size()) + { + while (format[formatIndex++] == '*') + if (formatIndex == formatSize) + return true; + return false; + } } - if (format.at(formatIndex) == 0) return true; - if (format.at(formatIndex) == '*') continue; - fUpper = toupper(format.at(formatIndex)); - while (fUpper != toupper(this->get(index))) + if (format[formatIndex] == '*') continue; + + while (toupper(format[formatIndex]) != toupper(this->get(index))) { - if (this->get(index) == 0) return false; - index++; + if (++index == this->size()) + { + while (format[formatIndex] == '*') + if (++formatIndex == formatSize) + return true; + return false; + } } } - else if (format.at(formatIndex) != L'?' && toupper(format.at(formatIndex)) != toupper(this->get(index))) return false; + else if (format[formatIndex] != '?' && toupper(format[formatIndex]) != toupper(this->get(index))) return false; formatIndex++; - index++; + if (++index == this->size()) + { + if (formatIndex == formatSize) + return true; + while (format[formatIndex] == '*') + if (++formatIndex == formatSize) + return true; + return false; + } } - return index == this->size(); + return false; } -template<> bool inline Jupiter::Readable_String::matchi(const std::basic_string &format) const +template<> bool inline Jupiter::Readable_String::matchi(const wchar_t *format, size_t formatSize) const { - wint_t fUpper; + if (this->size() == 0) + { + if (formatSize == 0) + return true; + while (format[--formatSize] == L'*') + if (formatSize == 0) + return *format == L'*'; + return false; + } size_t index = 0; size_t formatIndex = 0; - while (formatIndex != format.size()) + while (formatIndex != formatSize) { - if (format.at(formatIndex) == L'*') + if (format[formatIndex] == L'*') { - formatIndex++; - while (format.at(formatIndex) == L'?') + if (++formatIndex == formatSize) + return true; + + while (format[formatIndex] == L'?') { - if (this->get(index) == 0) return false; - formatIndex++; - index++; + if (++formatIndex == formatSize) + return index + 1 == this->size(); + if (++index == this->size()) + { + while (format[formatIndex++] == L'*') + if (formatIndex == formatSize) + return true; + return false; + } } - if (format.at(formatIndex) == 0) return true; - if (format.at(formatIndex) == '*') continue; - fUpper = towupper(format.at(formatIndex)); - while (fUpper != towupper(this->get(index))) + if (format[formatIndex] == L'*') continue; + + while (towupper(format[formatIndex]) != towupper(this->get(index))) { - if (this->get(index) == 0) return false; - index++; + if (++index == this->size()) + { + while (format[formatIndex] == L'*') + if (++formatIndex == formatSize) + return true; + return false; + } } } - else if (format.at(formatIndex) != L'?' && towupper(format.at(formatIndex)) != towupper(this->get(index))) return false; + else if (format[formatIndex] != L'?' && towupper(format[formatIndex]) != towupper(this->get(index))) return false; formatIndex++; - index++; + if (++index == this->size()) + { + while (format[formatIndex] == L'*') + if (++formatIndex == formatSize) + return true; + return false; + } } - return index == this->size(); + return false; } -template bool Jupiter::Readable_String::matchi(const std::basic_string &format) const +template bool Jupiter::Readable_String::matchi(const T *, size_t) const { return false; // Wildcard matching not supported for type. Concept of "case" not supported for type. } template<> bool inline Jupiter::Readable_String::matchi(const char *format) const { - int fUpper; + if (this->size() == 0) + { + while (*format == '*') + format++; + return *format == 0; + } size_t index = 0; while (*format != 0) { @@ -710,29 +753,47 @@ template<> bool inline Jupiter::Readable_String::matchi(const char *format format++; while (*format == '?') { - if (this->get(index) == 0) return false; format++; - index++; + if (++index == this->size()) + { + while (*format == '*') + format++; + return *format == 0; + } } if (*format == 0) return true; if (*format == '*') continue; - fUpper = toupper(*format); - while (fUpper != toupper(this->get(index))) + + while (toupper(*format) != toupper(this->get(index))) { - if (this->get(index) == 0) return false; - index++; + if (++index == this->size()) + { + while (*format == '*') + format++; + return *format == 0; + } } } else if (*format != '?' && toupper(*format) != toupper(this->get(index))) return false; format++; - index++; + if (++index == this->size()) + { + while (*format == '*') + format++; + return *format == 0; + } } - return index == this->size(); + return false; } template<> bool inline Jupiter::Readable_String::matchi(const wchar_t *format) const { - wint_t fUpper; + if (this->size() == 0) + { + while (*format == L'*') + format++; + return *format == 0; + } size_t index = 0; while (*format != 0) { @@ -741,24 +802,37 @@ template<> bool inline Jupiter::Readable_String::matchi(const wchar_t * format++; while (*format == L'?') { - if (this->get(index) == 0) return false; format++; - index++; + if (this->size() == 0) + { + while (*format == L'*') + format++; + return *format == 0; + } } if (*format == 0) return true; if (*format == '*') continue; - fUpper = towupper(*format); - while (fUpper != towupper(this->get(index))) + + while (towupper(*format) != towupper(this->get(index))) { - if (this->get(index) == 0) return false; - index++; + if (this->size() == 0) + { + while (*format == L'*') + format++; + return *format == 0; + } } } else if (*format != L'?' && towupper(*format) != towupper(this->get(index))) return false; format++; - index++; + if (this->size() == 0) + { + while (*format == L'*') + format++; + return *format == 0; + } } - return index == this->size(); + return false; } template bool Jupiter::Readable_String::matchi(const T *format) const diff --git a/Release/Jupiter.lib b/Release/Jupiter.lib index 0a05fbb..28ff3a1 100644 Binary files a/Release/Jupiter.lib and b/Release/Jupiter.lib differ