blob: 73697874333ce75b1e4247a66e542172381528b3 (
plain)
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
66
67
68
69
70
71
72
73
74
|
#ifndef STRUTIL_H_
#define STRUTIL_H_
#include <string>
#include <vector>
#include "string_piece.h"
using namespace std;
class WordScanner {
public:
struct Iterator {
Iterator& operator++();
StringPiece operator*() const;
bool operator!=(const Iterator& r) const {
return in != r.in || s != r.s || i != r.i;
}
const StringPiece* in;
int s;
int i;
};
explicit WordScanner(StringPiece in);
Iterator begin() const;
Iterator end() const;
private:
StringPiece in_;
};
class WordWriter {
public:
explicit WordWriter(string* o);
void Write(StringPiece s);
private:
string* out_;
bool needs_space_;
};
void InitSymtab();
void QuitSymtab();
StringPiece Intern(StringPiece s);
template <class String>
inline string JoinStrings(vector<String> v, const char* sep) {
string r;
for (StringPiece s : v) {
if (!r.empty()) {
r += sep;
}
r.append(s.begin(), s.end());
}
return r;
}
void AppendString(StringPiece str, string* out);
bool HasPrefix(StringPiece str, StringPiece prefix);
bool HasSuffix(StringPiece str, StringPiece suffix);
StringPiece TrimSuffix(StringPiece str, StringPiece suffix);
void AppendSubstPattern(StringPiece str, StringPiece pat, StringPiece subst,
string* out);
void AppendSubstRef(StringPiece str, StringPiece pat, StringPiece subst,
string* out);
#endif // STRUTIL_H_
|