Browse Source

Added memory buffer match() and matchi() functions. Fixed match() and matchi() parsing.

release/0.19
JustinAJ 10 years ago
parent
commit
a41e9737e9
  1. 2
      Jupiter/Readable_String.h
  2. 504
      Jupiter/Readable_String_Imp.h
  3. BIN
      Release/Jupiter.lib

2
Jupiter/Readable_String.h

@ -157,6 +157,7 @@ namespace Jupiter
*/ */
bool match(const Readable_String<T> &format) const; bool match(const Readable_String<T> &format) const;
bool match(const std::basic_string<T> &format) const; bool match(const std::basic_string<T> &format) const;
bool match(const T *format, size_t formatSize) const;
bool match(const T *format) const; bool match(const T *format) const;
/** /**
@ -168,6 +169,7 @@ namespace Jupiter
*/ */
bool matchi(const Readable_String<T> &format) const; bool matchi(const Readable_String<T> &format) const;
bool matchi(const std::basic_string<T> &format) const; bool matchi(const std::basic_string<T> &format) const;
bool matchi(const T *format, size_t formatSize) const;
bool matchi(const T *format) const; bool matchi(const T *format) const;
/** /**

504
Jupiter/Readable_String_Imp.h

@ -366,138 +366,147 @@ template<typename T> bool Jupiter::Readable_String<T>::equalsi(const std::nullpt
// match() // match()
template<> bool inline Jupiter::Readable_String<char>::match(const Jupiter::Readable_String<char> &format) const template<typename T> bool Jupiter::Readable_String<T>::match(const Jupiter::Readable_String<T> &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; return this->match(format.ptr(), format.size());
formatIndex++;
index++;
} }
if (format.get(formatIndex) == 0) return true;
if (format.get(formatIndex) == '*') continue; template<typename T> bool Jupiter::Readable_String<T>::match(const std::basic_string<T> &format) const
while (format.get(formatIndex) != this->get(index))
{ {
if (this->get(index) == 0) return false; return this->match(format.data(), format.size());
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<wchar_t>::match(const Jupiter::Readable_String<wchar_t> &format) const template<> bool inline Jupiter::Readable_String<char>::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 index = 0;
size_t formatIndex = 0; size_t formatIndex = 0;
while (formatIndex != format.size()) while (formatIndex != formatSize)
{ {
if (format.get(formatIndex) == '*') if (format[formatIndex] == '*')
{ {
formatIndex++; if (++formatIndex == formatSize)
while (format.get(formatIndex) == '?') return true;
while (format[formatIndex] == '?')
{ {
if (this->get(index) == 0) return false; if (++formatIndex == formatSize)
formatIndex++; return true;
index++; if (++index == this->size())
{
while (format[formatIndex++] == '*')
if (formatIndex == formatSize)
return true;
return false;
} }
if (format.get(formatIndex) == 0) return true; }
if (format.get(formatIndex) == '*') continue; if (format[formatIndex] == '*') continue;
while (format.get(formatIndex) != this->get(index))
while (format[formatIndex] != this->get(index))
{ {
if (this->get(index) == 0) return false; if (++index == this->size())
index++; {
while (format[formatIndex] == '*')
if (++formatIndex == formatSize)
return true;
return false;
} }
} }
else if (format.get(formatIndex) != '?' && format.get(formatIndex) != this->get(index)) return false; }
else if (format[formatIndex] != '?' && format[formatIndex] != this->get(index)) return false;
formatIndex++; 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<typename T> bool Jupiter::Readable_String<T>::match(const Jupiter::Readable_String<T> &format) const
{
return false; // Wildcard matching not supported for type.
} }
template<> bool inline Jupiter::Readable_String<char>::match(const std::basic_string<char> &format) const template<> bool inline Jupiter::Readable_String<wchar_t>::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 index = 0;
size_t formatIndex = 0; size_t formatIndex = 0;
while (formatIndex != format.size()) while (formatIndex != formatSize)
{ {
if (format.at(formatIndex) == '*') if (format[formatIndex] == L'*')
{ {
formatIndex++; if (++formatIndex == formatSize)
while (format.at(formatIndex) == '?') return true;
while (format[formatIndex] == L'?')
{ {
if (this->get(index) == 0) return false; if (++formatIndex == formatSize)
formatIndex++; return index + 1 == this->size();
index++; if (++index == this->size())
}
if (format.at(formatIndex) == 0) return true;
if (format.at(formatIndex) == '*') continue;
while (format.at(formatIndex) != this->get(index))
{ {
if (this->get(index) == 0) return false; while (format[formatIndex++] == L'*')
index++; if (formatIndex == formatSize)
} return true;
} return false;
else if (format.at(formatIndex) != '?' && format.at(formatIndex) != this->get(index)) return false;
formatIndex++;
index++;
} }
return index == this->size();
} }
if (format[formatIndex] == L'*') continue;
template<> bool inline Jupiter::Readable_String<wchar_t>::match(const std::basic_string<wchar_t> &format) const while (format[formatIndex] != this->get(index))
{
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != format.size())
{
if (format.at(formatIndex) == '*')
{ {
formatIndex++; if (++index == this->size())
while (format.at(formatIndex) == '?')
{ {
if (this->get(index) == 0) return false; while (format[formatIndex] == L'*')
formatIndex++; if (++formatIndex == formatSize)
index++; return true;
return false;
} }
if (format.at(formatIndex) == 0) return true;
if (format.at(formatIndex) == '*') continue;
while (format.at(formatIndex) != this->get(index))
{
if (this->get(index) == 0) return false;
index++;
} }
} }
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++; formatIndex++;
index++; if (++index == this->size())
{
while (format[formatIndex] == L'*')
if (++formatIndex == formatSize)
return true;
return false;
}
} }
return index == this->size(); return false;
} }
template<typename T> bool Jupiter::Readable_String<T>::match(const std::basic_string<T> &format) const template<typename T> bool Jupiter::Readable_String<T>::match(const T *, size_t) const
{ {
return false; // Wildcard matching not supported for type. return false; // Wildcard matching not supported for type.
} }
template<> inline bool Jupiter::Readable_String<char>::match(const char *format) const template<> bool inline Jupiter::Readable_String<char>::match(const char *format) const
{
if (this->size() == 0)
{ {
while (*format == '*')
format++;
return *format == 0;
}
size_t index = 0; size_t index = 0;
while (*format != 0) while (*format != 0)
{ {
@ -506,27 +515,47 @@ template<> inline bool Jupiter::Readable_String<char>::match(const char *format)
format++; format++;
while (*format == '?') while (*format == '?')
{ {
if (this->get(index) == 0) return false;
format++; format++;
index++; if (++index == this->size())
{
while (*format == '*')
format++;
return *format == 0;
}
} }
if (*format == 0) return true; if (*format == 0) return true;
if (*format == '*') continue; if (*format == '*') continue;
while (*format != this->get(index)) while (*format != this->get(index))
{ {
if (this->get(index) == 0) return false; if (++index == this->size())
index++; {
while (*format == '*')
format++;
return *format == 0;
}
} }
} }
else if (*format != '?' && *format != this->get(index)) return false; else if (*format != '?' && *format != this->get(index)) return false;
format++; format++;
index++; if (++index == this->size())
{
while (*format == '*')
format++;
return *format == 0;
}
} }
return index == this->size(); return false;
} }
template<> inline bool Jupiter::Readable_String<wchar_t>::match(const wchar_t *format) const template<> bool inline Jupiter::Readable_String<wchar_t>::match(const wchar_t *format) const
{
if (this->size() == 0)
{ {
while (*format == L'*')
format++;
return *format == 0;
}
size_t index = 0; size_t index = 0;
while (*format != 0) while (*format != 0)
{ {
@ -535,23 +564,37 @@ template<> inline bool Jupiter::Readable_String<wchar_t>::match(const wchar_t *f
format++; format++;
while (*format == L'?') while (*format == L'?')
{ {
if (this->get(index) == 0) return false;
format++; format++;
index++; if (this->size() == 0)
{
while (*format == L'*')
format++;
return *format == 0;
}
} }
if (*format == 0) return true; if (*format == 0) return true;
if (*format == L'*') continue; if (*format == '*') continue;
while (*format != this->get(index)) while (*format != this->get(index))
{ {
if (this->get(index) == 0) return false; if (this->size() == 0)
index++; {
while (*format == L'*')
format++;
return *format == 0;
}
} }
} }
else if (*format != L'?' && *format != this->get(index)) return false; else if (*format != L'?' && *format != this->get(index)) return false;
format++; format++;
index++; if (this->size() == 0)
{
while (*format == L'*')
format++;
return *format == 0;
}
} }
return index == this->size(); return false;
} }
template<typename T> bool Jupiter::Readable_String<T>::match(const T *format) const template<typename T> bool Jupiter::Readable_String<T>::match(const T *format) const
@ -561,147 +604,147 @@ template<typename T> bool Jupiter::Readable_String<T>::match(const T *format) co
// matchi() // matchi()
template<> bool inline Jupiter::Readable_String<char>::matchi(const Jupiter::Readable_String<char> &format) const template<typename T> bool Jupiter::Readable_String<T>::matchi(const Jupiter::Readable_String<T> &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; return this->matchi(format.ptr(), format.size());
formatIndex++;
index++;
} }
if (format.get(formatIndex) == 0) return true;
if (format.get(formatIndex) == '*') continue; template<typename T> bool Jupiter::Readable_String<T>::matchi(const std::basic_string<T> &format) const
fUpper = toupper(format.get(formatIndex));
while (fUpper != toupper(this->get(index)))
{ {
if (this->get(index) == 0) return false; return this->matchi(format.data(), format.size());
index++;
}
}
else if (format.get(formatIndex) != L'?' && toupper(format.get(formatIndex)) != toupper(this->get(index))) return false;
formatIndex++;
index++;
}
return index == this->size();
} }
template<> bool inline Jupiter::Readable_String<wchar_t>::matchi(const Jupiter::Readable_String<wchar_t> &format) const template<> bool inline Jupiter::Readable_String<char>::matchi(const char *format, size_t formatSize) const
{
if (this->size() == 0)
{ {
wint_t fUpper; if (formatSize == 0)
return true;
while (format[--formatSize] == '*')
if (formatSize == 0)
return *format == '*';
return false;
}
size_t index = 0; size_t index = 0;
size_t formatIndex = 0; size_t formatIndex = 0;
while (formatIndex != format.size()) while (formatIndex != formatSize)
{ {
if (format.get(formatIndex) == L'*') if (format[formatIndex] == '*')
{ {
formatIndex++; if (++formatIndex == formatSize)
while (format.get(formatIndex) == L'?') return true;
while (format[formatIndex] == '?')
{ {
if (this->get(index) == 0) return false; if (++formatIndex == formatSize)
formatIndex++; return true;
index++; if (++index == this->size())
{
while (format[formatIndex++] == '*')
if (formatIndex == formatSize)
return true;
return false;
} }
if (format.get(formatIndex) == 0) return true; }
if (format.get(formatIndex) == '*') continue; if (format[formatIndex] == '*') continue;
fUpper = towupper(format.get(formatIndex));
while (fUpper != towupper(this->get(index))) while (toupper(format[formatIndex]) != toupper(this->get(index)))
{ {
if (this->get(index) == 0) return false; if (++index == this->size())
index++; {
while (format[formatIndex] == '*')
if (++formatIndex == formatSize)
return true;
return false;
} }
} }
else if (format.get(formatIndex) != L'?' && towupper(format.get(formatIndex)) != towupper(this->get(index))) return false; }
else if (format[formatIndex] != '?' && toupper(format[formatIndex]) != toupper(this->get(index))) return false;
formatIndex++; 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<typename T> bool Jupiter::Readable_String<T>::matchi(const Jupiter::Readable_String<T> &format) const
{
return false; // Wildcard matching not supported for type. Concept of "case" not supported for type.
} }
template<> bool inline Jupiter::Readable_String<char>::matchi(const std::basic_string<char> &format) const template<> bool inline Jupiter::Readable_String<wchar_t>::matchi(const wchar_t *format, size_t formatSize) const
{
if (this->size() == 0)
{ {
int fUpper; if (formatSize == 0)
return true;
while (format[--formatSize] == L'*')
if (formatSize == 0)
return *format == L'*';
return false;
}
size_t index = 0; size_t index = 0;
size_t formatIndex = 0; size_t formatIndex = 0;
while (formatIndex != format.size()) while (formatIndex != formatSize)
{ {
if (format.at(formatIndex) == L'*') if (format[formatIndex] == L'*')
{ {
formatIndex++; if (++formatIndex == formatSize)
while (format.at(formatIndex) == L'?') return true;
while (format[formatIndex] == L'?')
{ {
if (this->get(index) == 0) return false; if (++formatIndex == formatSize)
formatIndex++; return index + 1 == this->size();
index++; if (++index == this->size())
}
if (format.at(formatIndex) == 0) return true;
if (format.at(formatIndex) == '*') continue;
fUpper = toupper(format.at(formatIndex));
while (fUpper != toupper(this->get(index)))
{ {
if (this->get(index) == 0) return false; while (format[formatIndex++] == L'*')
index++; if (formatIndex == formatSize)
} return true;
} return false;
else if (format.at(formatIndex) != L'?' && toupper(format.at(formatIndex)) != toupper(this->get(index))) return false;
formatIndex++;
index++;
} }
return index == this->size();
} }
if (format[formatIndex] == L'*') continue;
template<> bool inline Jupiter::Readable_String<wchar_t>::matchi(const std::basic_string<wchar_t> &format) const while (towupper(format[formatIndex]) != towupper(this->get(index)))
{
wint_t fUpper;
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != format.size())
{
if (format.at(formatIndex) == L'*')
{ {
formatIndex++; if (++index == this->size())
while (format.at(formatIndex) == L'?')
{ {
if (this->get(index) == 0) return false; while (format[formatIndex] == L'*')
formatIndex++; if (++formatIndex == formatSize)
index++; 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 (this->get(index) == 0) return false;
index++;
} }
} }
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++; formatIndex++;
index++; if (++index == this->size())
{
while (format[formatIndex] == L'*')
if (++formatIndex == formatSize)
return true;
return false;
}
} }
return index == this->size(); return false;
} }
template<typename T> bool Jupiter::Readable_String<T>::matchi(const std::basic_string<T> &format) const template<typename T> bool Jupiter::Readable_String<T>::matchi(const T *, size_t) const
{ {
return false; // Wildcard matching not supported for type. Concept of "case" not supported for type. return false; // Wildcard matching not supported for type. Concept of "case" not supported for type.
} }
template<> bool inline Jupiter::Readable_String<char>::matchi(const char *format) const template<> bool inline Jupiter::Readable_String<char>::matchi(const char *format) const
{ {
int fUpper; if (this->size() == 0)
{
while (*format == '*')
format++;
return *format == 0;
}
size_t index = 0; size_t index = 0;
while (*format != 0) while (*format != 0)
{ {
@ -710,29 +753,47 @@ template<> bool inline Jupiter::Readable_String<char>::matchi(const char *format
format++; format++;
while (*format == '?') while (*format == '?')
{ {
if (this->get(index) == 0) return false;
format++; format++;
index++; if (++index == this->size())
{
while (*format == '*')
format++;
return *format == 0;
}
} }
if (*format == 0) return true; if (*format == 0) return true;
if (*format == '*') continue; 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; if (++index == this->size())
index++; {
while (*format == '*')
format++;
return *format == 0;
}
} }
} }
else if (*format != '?' && toupper(*format) != toupper(this->get(index))) return false; else if (*format != '?' && toupper(*format) != toupper(this->get(index))) return false;
format++; format++;
index++; if (++index == this->size())
{
while (*format == '*')
format++;
return *format == 0;
} }
return index == this->size(); }
return false;
} }
template<> bool inline Jupiter::Readable_String<wchar_t>::matchi(const wchar_t *format) const template<> bool inline Jupiter::Readable_String<wchar_t>::matchi(const wchar_t *format) const
{ {
wint_t fUpper; if (this->size() == 0)
{
while (*format == L'*')
format++;
return *format == 0;
}
size_t index = 0; size_t index = 0;
while (*format != 0) while (*format != 0)
{ {
@ -741,24 +802,37 @@ template<> bool inline Jupiter::Readable_String<wchar_t>::matchi(const wchar_t *
format++; format++;
while (*format == L'?') while (*format == L'?')
{ {
if (this->get(index) == 0) return false;
format++; format++;
index++; if (this->size() == 0)
{
while (*format == L'*')
format++;
return *format == 0;
}
} }
if (*format == 0) return true; if (*format == 0) return true;
if (*format == '*') continue; 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; if (this->size() == 0)
index++; {
while (*format == L'*')
format++;
return *format == 0;
}
} }
} }
else if (*format != L'?' && towupper(*format) != towupper(this->get(index))) return false; else if (*format != L'?' && towupper(*format) != towupper(this->get(index))) return false;
format++; format++;
index++; if (this->size() == 0)
{
while (*format == L'*')
format++;
return *format == 0;
}
} }
return index == this->size(); return false;
} }
template<typename T> bool Jupiter::Readable_String<T>::matchi(const T *format) const template<typename T> bool Jupiter::Readable_String<T>::matchi(const T *format) const

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save