|
1 // Copyright (c) 2010, Google Inc. |
|
2 // All rights reserved. |
|
3 // |
|
4 // Redistribution and use in source and binary forms, with or without |
|
5 // modification, are permitted provided that the following conditions are |
|
6 // met: |
|
7 // |
|
8 // * Redistributions of source code must retain the above copyright |
|
9 // notice, this list of conditions and the following disclaimer. |
|
10 // * Redistributions in binary form must reproduce the above |
|
11 // copyright notice, this list of conditions and the following disclaimer |
|
12 // in the documentation and/or other materials provided with the |
|
13 // distribution. |
|
14 // * Neither the name of Google Inc. nor the names of its |
|
15 // contributors may be used to endorse or promote products derived from |
|
16 // this software without specific prior written permission. |
|
17 // |
|
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 // |
|
30 // Implements a Tokenize function for splitting up strings. |
|
31 |
|
32 #ifndef GOOGLE_BREAKPAD_PROCESSOR_TOKENIZE_H_ |
|
33 #define GOOGLE_BREAKPAD_PROCESSOR_TOKENIZE_H_ |
|
34 |
|
35 #include <string> |
|
36 #include <vector> |
|
37 |
|
38 #include "common/using_std_string.h" |
|
39 |
|
40 namespace google_breakpad { |
|
41 |
|
42 // Splits line into at most max_tokens tokens, separated by any of the |
|
43 // characters in separators and placing them in the tokens vector. |
|
44 // line is a 0-terminated string that optionally ends with a newline |
|
45 // character or combination, which will be removed. |
|
46 // If more tokens than max_tokens are present, the final token is placed |
|
47 // into the vector without splitting it up at all. This modifies line as |
|
48 // a side effect. Returns true if exactly max_tokens tokens are returned, |
|
49 // and false if fewer are returned. This is not considered a failure of |
|
50 // Tokenize, but may be treated as a failure if the caller expects an |
|
51 // exact, as opposed to maximum, number of tokens. |
|
52 |
|
53 bool Tokenize(char *line, |
|
54 const char *separators, |
|
55 int max_tokens, |
|
56 std::vector<char*> *tokens); |
|
57 // For convenience, since you need a char* to pass to Tokenize. |
|
58 // You can call StringToVector on a string, and use &vec[0]. |
|
59 void StringToVector(const string &str, std::vector<char> &vec); |
|
60 |
|
61 } // namespace google_breakpad |
|
62 |
|
63 #endif // GOOGLE_BREAKPAD_PROCESSOR_TOKENIZE_H_ |