1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4 
5 #ifndef ICE_UTIL_STRING_UTIL_H
6 #define ICE_UTIL_STRING_UTIL_H
7 
8 #include <IceUtil/Config.h>
9 #include <vector>
10 
11 namespace IceUtilInternal
12 {
13 
14 //
15 // Must be kept in sync with Ice::ToStringMode
16 //
17 #ifdef ICE_CPP11_MAPPING
18 enum class ToStringMode : unsigned char
19 #else
20 enum ToStringMode
21 #endif
22 { Unicode, ASCII, Compat };
23 
24 //
25 // Add escape sequences (like "\n", or "\123") to the input string
26 // (first parameter).
27 // The second parameter adds characters to escape, and can be empty.
28 //
29 ICE_API std::string escapeString(const std::string&, const std::string&, ToStringMode);
30 
31 //
32 // Remove escape sequences added by escapeString. Throws IllegalArgumentException
33 // for an invalid input string.
34 //
35 ICE_API std::string unescapeString(const std::string&, std::string::size_type, std::string::size_type, const std::string&);
36 
37 //
38 // Split a string using the given delimiters. Considers single and double quotes;
39 // returns false for unbalanced quote, true otherwise.
40 //
41 ICE_API bool splitString(const std::string&, const std::string&, std::vector<std::string>&);
42 
43 //
44 // Join a list of strings using the given delimiter.
45 //
46 ICE_API std::string joinString(const std::vector<std::string>&, const std::string&);
47 
48 //
49 // Trim white space
50 //
51 ICE_API std::string trim(const std::string&);
52 
53 //
54 // If a single or double quotation mark is found at the start
55 // position, then the position of the matching closing quote is
56 // returned. If no quotation mark is found at the start position, then
57 // 0 is returned. If no matching closing quote is found, then
58 // std::string::npos is returned.
59 //
60 ICE_API std::string::size_type checkQuote(const std::string&, std::string::size_type = 0);
61 
62 //
63 // Match `s' against the pattern `pat'. A * in the pattern acts
~BasicStringConverter()64 // as a wildcard: it matches any non-empty sequence of characters
65 // other than a period (`.'). We match by hand here because
66 // it's portable across platforms (whereas regex() isn't).
67 //
68 ICE_API bool match(const std::string&, const std::string&, bool = false);
69 
70 //
71 // Get the error message for the last error code or given error code.
72 //
73 ICE_API std::string lastErrorToString();
74 #ifdef _WIN32
75 ICE_API std::string errorToString(int, LPCVOID = ICE_NULLPTR);
76 #else
77 ICE_API std::string errorToString(int);
78 #endif
79 
80 //
81 // Functions to convert to lower/upper case. These functions accept
82 // UTF8 string/characters but ignore non ASCII characters. Unlike, the
83 // C methods, these methods are not local dependent.
84 //
85 ICE_API std::string toLower(const std::string&);
86 ICE_API std::string toUpper(const std::string&);
87 ICE_API bool isAlpha(char);
88 ICE_API bool isDigit(char);
89 
90 //
91 // Remove all whitespace from a string
92 //
93 ICE_API std::string removeWhitespace(const std::string&);
94 
95 }
96 
97 #endif
98