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
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>
19string 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>
33inline string join(C&& container, T&& delim) {
34 return join(std::begin(container), std::end(container), delim);
35}
36
37template <typename C, typename T>
38inline 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_
Definition algebra.cc:12
Definition strings.cc:4
SplitBehavior
Definition strings.h:10
@ KeepToken
Definition strings.h:10
@ SkipToken
Definition strings.h:10
string join(Iter start, Iter end, T &&delim)
Definition strings.h:19
vector< string > split(const string &str, const string &delim, SplitBehavior behavior)
Definition strings.cc:6