MCPcopy Create free account
hub / github.com/apache/brpc / StringSplitter

Class StringSplitter

src/butil/string_splitter.h:61–112  ·  view source on GitHub ↗

Split a string with one character

Source from the content-addressed store, hash-verified

59
60// Split a string with one character
61class StringSplitter {
62public:
63 // Split `input' with `separator'. If `action' is SKIP_EMPTY_FIELD, zero-
64 // length() field() will be skipped.
65 inline StringSplitter(const char* input, char separator,
66 EmptyFieldAction action = SKIP_EMPTY_FIELD);
67 // Allows containing embedded '\0' characters and separator can be '\0',
68 // if str_end is not NULL.
69 inline StringSplitter(const char* str_begin, const char* str_end,
70 char separator,
71 EmptyFieldAction action = SKIP_EMPTY_FIELD);
72 // Allows containing embedded '\0' characters and separator can be '\0',
73 inline StringSplitter(const StringPiece& input, char separator,
74 EmptyFieldAction action = SKIP_EMPTY_FIELD);
75
76 // Move splitter forward.
77 inline StringSplitter& operator++();
78 inline StringSplitter operator++(int);
79
80 // True iff field() is valid.
81 inline operator const void*() const;
82
83 // Beginning address and length of the field. *(field() + length()) may
84 // not be '\0' because we don't modify `input'.
85 inline const char* field() const;
86 inline size_t length() const;
87 inline StringPiece field_sp() const;
88
89 // Cast field to specific type, and write the value into `pv'.
90 // Returns 0 on success, -1 otherwise.
91 // NOTE: If separator is a digit, casting functions always return -1.
92 inline int to_int8(int8_t *pv) const;
93 inline int to_uint8(uint8_t *pv) const;
94 inline int to_int(int *pv) const;
95 inline int to_uint(unsigned int *pv) const;
96 inline int to_long(long *pv) const;
97 inline int to_ulong(unsigned long *pv) const;
98 inline int to_longlong(long long *pv) const;
99 inline int to_ulonglong(unsigned long long *pv) const;
100 inline int to_float(float *pv) const;
101 inline int to_double(double *pv) const;
102
103private:
104 inline bool not_end(const char* p) const;
105 inline void init();
106
107 const char* _head;
108 const char* _tail;
109 const char* _str_tail;
110 const char _sep;
111 const EmptyFieldAction _empty_field_action;
112};
113
114// Split a string with one of the separators
115class StringMultiSplitter {

Callers 1

parse_cpusetMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected