]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2009-2010 Dreamhost | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | ||
15 | #include "include/str_list.h" | |
16 | ||
17 | using std::string; | |
18 | using std::vector; | |
19 | using std::set; | |
20 | using std::list; | |
21 | ||
22 | static bool get_next_token(const string &s, size_t& pos, const char *delims, string& token) | |
23 | { | |
24 | int start = s.find_first_not_of(delims, pos); | |
25 | int end; | |
26 | ||
27 | if (start < 0){ | |
28 | pos = s.size(); | |
29 | return false; | |
30 | } | |
31 | ||
32 | end = s.find_first_of(delims, start); | |
33 | if (end >= 0) | |
34 | pos = end + 1; | |
35 | else { | |
36 | pos = end = s.size(); | |
37 | } | |
38 | ||
39 | token = s.substr(start, end - start); | |
40 | return true; | |
41 | } | |
42 | ||
43 | void get_str_list(const string& str, const char *delims, list<string>& str_list) | |
44 | { | |
45 | size_t pos = 0; | |
46 | string token; | |
47 | ||
48 | str_list.clear(); | |
49 | ||
50 | while (pos < str.size()) { | |
51 | if (get_next_token(str, pos, delims, token)) { | |
52 | if (token.size() > 0) { | |
53 | str_list.push_back(token); | |
54 | } | |
55 | } | |
56 | } | |
57 | } | |
58 | ||
59 | void get_str_list(const string& str, list<string>& str_list) | |
60 | { | |
61 | const char *delims = ";,= \t"; | |
62 | return get_str_list(str, delims, str_list); | |
63 | } | |
64 | ||
65 | void get_str_vec(const string& str, const char *delims, vector<string>& str_vec) | |
66 | { | |
67 | size_t pos = 0; | |
68 | string token; | |
69 | str_vec.clear(); | |
70 | ||
71 | while (pos < str.size()) { | |
72 | if (get_next_token(str, pos, delims, token)) { | |
73 | if (token.size() > 0) { | |
74 | str_vec.push_back(token); | |
75 | } | |
76 | } | |
77 | } | |
78 | } | |
79 | ||
80 | void get_str_vec(const string& str, vector<string>& str_vec) | |
81 | { | |
82 | const char *delims = ";,= \t"; | |
83 | return get_str_vec(str, delims, str_vec); | |
84 | } | |
85 | ||
86 | void get_str_set(const string& str, const char *delims, set<string>& str_set) | |
87 | { | |
88 | size_t pos = 0; | |
89 | string token; | |
90 | ||
91 | str_set.clear(); | |
92 | ||
93 | while (pos < str.size()) { | |
94 | if (get_next_token(str, pos, delims, token)) { | |
95 | if (token.size() > 0) { | |
96 | str_set.insert(token); | |
97 | } | |
98 | } | |
99 | } | |
100 | } | |
101 | ||
102 | void get_str_set(const string& str, set<string>& str_set) | |
103 | { | |
104 | const char *delims = ";,= \t"; | |
105 | return get_str_set(str, delims, str_set); | |
106 | } |