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