librime: strings.h Source File

| librime 1.2 Rime Input Method Engine, the core library

strings.h
Go to the documentation of this file.
1#ifndef RIME_STRINGS_H_
2#define RIME_STRINGS_H_
3
4#include <rime/common.h>
5#include <initializer_list>
6
7namespace rime {
8namespace strings {
9
10 enum class SplitBehavior { KeepToken, SkipToken };
11
12vector<string> split(const string& str,
13 const string& delim,
14 SplitBehavior behavior);
15
16vector<string> split(const string& str, const string& delim);
17
18template <typename Iter, typename T>
19 string join(Iter start, Iter end, T&& delim) {
20 string result;
21 if (start != end) {
22 result += (*start);
23 start++;
24 }
25 for (; start != end; start++) {
26 result += (delim);
27 result += (*start);
28 }
29 return result;
30}
31
32template <typename C, typename T>
33 inline string join(C&& container, T&& delim) {
34 return join(std::begin(container), std::end(container), delim);
35}
36
37template <typename C, typename T>
38 inline string join(std::initializer_list<C>&& container, T&& delim) {
39 return join(std::begin(container), std::end(container), delim);
40}
41
42} // namespace strings
43} // namespace rime
44
45#endif // RIME_STRINGS_H_
common.h
rime
Definition algebra.cc:12
rime::strings
Definition strings.cc:4
rime::strings::SplitBehavior
SplitBehavior
Definition strings.h:10
rime::strings::SplitBehavior::KeepToken
@ KeepToken
Definition strings.h:10
rime::strings::SplitBehavior::SkipToken
@ SkipToken
Definition strings.h:10
rime::strings::join
string join(Iter start, Iter end, T &&delim)
Definition strings.h:19
rime::strings::split
vector< string > split(const string &str, const string &delim, SplitBehavior behavior)
Definition strings.cc:6