strspn.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #pragma once
  2. #include "cstriter.h"
  3. #include <util/generic/bitmap.h>
  4. template <class TSetType>
  5. class TStrSpnImpl {
  6. public:
  7. inline TStrSpnImpl(const char* b, const char* e) {
  8. Init(b, e);
  9. }
  10. inline TStrSpnImpl(const char* s) {
  11. Init(s, TCStringEndIterator());
  12. }
  13. //FirstOf
  14. template <class It>
  15. inline It FindFirstOf(It b, const char* e) const noexcept {
  16. return FindFirst<false>(b, e);
  17. }
  18. template <class It>
  19. inline It FindFirstOf(It s) const noexcept {
  20. return FindFirst<false>(s, TCStringEndIterator());
  21. }
  22. //FirstNotOf
  23. template <class It>
  24. inline It FindFirstNotOf(It b, const char* e) const noexcept {
  25. return FindFirst<true>(b, e);
  26. }
  27. template <class It>
  28. inline It FindFirstNotOf(It s) const noexcept {
  29. return FindFirst<true>(s, TCStringEndIterator());
  30. }
  31. inline void Set(ui8 b) noexcept {
  32. S_.Set(b);
  33. }
  34. private:
  35. template <bool Result, class It1, class It2>
  36. inline It1 FindFirst(It1 b, It2 e) const noexcept {
  37. while (b != e && (S_.Get((ui8)*b) == Result)) {
  38. ++b;
  39. }
  40. return b;
  41. }
  42. template <class It1, class It2>
  43. inline void Init(It1 b, It2 e) {
  44. while (b != e) {
  45. this->Set((ui8)*b++);
  46. }
  47. }
  48. private:
  49. TSetType S_;
  50. };
  51. using TCompactStrSpn = TStrSpnImpl<TBitMap<256>>;