ci_string.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "ci_string.h"
  2. int TCiString::compare(const TCiString& s1, const TCiString& s2, const CodePage& cp) {
  3. return cp.stricmp(s1.data(), s2.data());
  4. }
  5. int TCiString::compare(const char* p, const TCiString& s2, const CodePage& cp) {
  6. return cp.stricmp(p, s2.data());
  7. }
  8. int TCiString::compare(const TCiString& s1, const char* p, const CodePage& cp) {
  9. return cp.stricmp(s1.data(), p);
  10. }
  11. int TCiString::compare(const TStringBuf& p1, const TStringBuf& p2, const CodePage& cp) {
  12. int rv = cp.strnicmp(p1.data(), p2.data(), Min(p1.size(), p2.size()));
  13. return rv ? rv : p1.size() < p2.size() ? -1 : p1.size() == p2.size() ? 0 : 1;
  14. }
  15. bool TCiString::is_prefix(const TStringBuf& what, const TStringBuf& of, const CodePage& cp) {
  16. size_t len = what.size();
  17. return len <= of.size() && cp.strnicmp(what.data(), of.data(), len) == 0;
  18. }
  19. bool TCiString::is_suffix(const TStringBuf& what, const TStringBuf& of, const CodePage& cp) {
  20. size_t len = what.size();
  21. size_t slen = of.size();
  22. return (len <= slen) && (0 == cp.strnicmp(what.data(), of.data() + slen - len, len));
  23. }
  24. size_t TCiString::hashVal(const char* s, size_t len, const CodePage& cp) {
  25. size_t h = len;
  26. for (; /* (*s) && */ len--; ++s)
  27. h = 5 * h + cp.ToLower(*s);
  28. return h;
  29. }
  30. template <>
  31. void Out<TCiString>(IOutputStream& o, const TCiString& p) {
  32. o.Write(p.data(), p.size());
  33. }