compare.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #pragma once
  2. namespace nall {
  3. template<bool Insensitive>
  4. auto string::_compare(const char* target, uint capacity, const char* source, uint size) -> int {
  5. if(Insensitive) return memory::icompare(target, capacity, source, size);
  6. return memory::compare(target, capacity, source, size);
  7. }
  8. //size() + 1 includes null-terminator; required to properly compare strings of differing lengths
  9. auto string::compare(string_view x, string_view y) -> int {
  10. return memory::compare(x.data(), x.size() + 1, y.data(), y.size() + 1);
  11. }
  12. auto string::icompare(string_view x, string_view y) -> int {
  13. return memory::icompare(x.data(), x.size() + 1, y.data(), y.size() + 1);
  14. }
  15. auto string::compare(string_view source) const -> int {
  16. return memory::compare(data(), size() + 1, source.data(), source.size() + 1);
  17. }
  18. auto string::icompare(string_view source) const -> int {
  19. return memory::icompare(data(), size() + 1, source.data(), source.size() + 1);
  20. }
  21. auto string::equals(string_view source) const -> bool {
  22. if(size() != source.size()) return false;
  23. return memory::compare(data(), source.data(), source.size()) == 0;
  24. }
  25. auto string::iequals(string_view source) const -> bool {
  26. if(size() != source.size()) return false;
  27. return memory::icompare(data(), source.data(), source.size()) == 0;
  28. }
  29. auto string::beginsWith(string_view source) const -> bool {
  30. if(source.size() > size()) return false;
  31. return memory::compare(data(), source.data(), source.size()) == 0;
  32. }
  33. auto string::ibeginsWith(string_view source) const -> bool {
  34. if(source.size() > size()) return false;
  35. return memory::icompare(data(), source.data(), source.size()) == 0;
  36. }
  37. auto string::endsWith(string_view source) const -> bool {
  38. if(source.size() > size()) return false;
  39. return memory::compare(data() + size() - source.size(), source.data(), source.size()) == 0;
  40. }
  41. auto string::iendsWith(string_view source) const -> bool {
  42. if(source.size() > size()) return false;
  43. return memory::icompare(data() + size() - source.size(), source.data(), source.size()) == 0;
  44. }
  45. }