1 | /** |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one |
---|
3 | * or more contributor license agreements. See the NOTICE file |
---|
4 | * distributed with this work for additional information |
---|
5 | * regarding copyright ownership. The ASF licenses this file |
---|
6 | * to you under the Apache License, Version 2.0 (the |
---|
7 | * "License"); you may not use this file except in compliance |
---|
8 | * with the License. You may obtain a copy of the License at |
---|
9 | * |
---|
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
11 | * |
---|
12 | * Unless required by applicable law or agreed to in writing, software |
---|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
15 | * See the License for the specific language governing permissions and |
---|
16 | * limitations under the License. |
---|
17 | */ |
---|
18 | #ifndef HADOOP_STRING_UTILS_HH |
---|
19 | #define HADOOP_STRING_UTILS_HH |
---|
20 | |
---|
21 | #include <stdint.h> |
---|
22 | #include <string> |
---|
23 | #include <vector> |
---|
24 | |
---|
25 | namespace HadoopUtils { |
---|
26 | |
---|
27 | /** |
---|
28 | * Convert an integer to a string. |
---|
29 | */ |
---|
30 | std::string toString(int32_t x); |
---|
31 | |
---|
32 | /** |
---|
33 | * Convert a string to an integer. |
---|
34 | * @throws Error if the string is not a valid integer |
---|
35 | */ |
---|
36 | int32_t toInt(const std::string& val); |
---|
37 | |
---|
38 | /** |
---|
39 | * Convert the string to a float. |
---|
40 | * @throws Error if the string is not a valid float |
---|
41 | */ |
---|
42 | float toFloat(const std::string& val); |
---|
43 | |
---|
44 | /** |
---|
45 | * Convert the string to a boolean. |
---|
46 | * @throws Error if the string is not a valid boolean value |
---|
47 | */ |
---|
48 | bool toBool(const std::string& val); |
---|
49 | |
---|
50 | /** |
---|
51 | * Get the current time in the number of milliseconds since 1970. |
---|
52 | */ |
---|
53 | uint64_t getCurrentMillis(); |
---|
54 | |
---|
55 | /** |
---|
56 | * Split a string into "words". Multiple deliminators are treated as a single |
---|
57 | * word break, so no zero-length words are returned. |
---|
58 | * @param str the string to split |
---|
59 | * @param separator a list of characters that divide words |
---|
60 | */ |
---|
61 | std::vector<std::string> splitString(const std::string& str, |
---|
62 | const char* separator); |
---|
63 | |
---|
64 | /** |
---|
65 | * Quote a string to avoid "\", non-printable characters, and the |
---|
66 | * deliminators. |
---|
67 | * @param str the string to quote |
---|
68 | * @param deliminators the set of characters to always quote |
---|
69 | */ |
---|
70 | std::string quoteString(const std::string& str, |
---|
71 | const char* deliminators); |
---|
72 | |
---|
73 | /** |
---|
74 | * Unquote the given string to return the original string. |
---|
75 | * @param str the string to unquote |
---|
76 | */ |
---|
77 | std::string unquoteString(const std::string& str); |
---|
78 | |
---|
79 | } |
---|
80 | |
---|
81 | #endif |
---|