Ice 3.8
C++ API Reference
Loading...
Searching...
No Matches
StringUtil.h
1// Copyright (c) ZeroC, Inc.
2
3#ifndef ICE_STRING_UTIL_H
4#define ICE_STRING_UTIL_H
5
6#include "Ice/Config.h"
7
8#include <cstdint>
9#include <string>
10#include <vector>
11
12namespace Ice
13{
14 /// The output mode for xxxToString methods such as identityToString and proxyToString. The actual encoding format
15 /// for the string is the same for all modes: you don't need to specify an encoding format or mode when reading such
16 /// a string.
17 enum class ToStringMode : std::uint8_t
18 {
19 /// Characters with ordinal values greater than 127 are kept as-is in the resulting string. Non-printable ASCII
20 /// characters with ordinal values 127 and below are encoded as \\t, \\n (etc.) or \\unnnn.
22 /// Characters with ordinal values greater than 127 are encoded as universal character names in the resulting
23 /// string: \\unnnn for BMP characters and \\Unnnnnnnn for non-BMP characters. Non-printable ASCII characters
24 /// with ordinal values 127 and below are encoded as \\t, \\n (etc.) or \\unnnn.
26 /// Characters with ordinal values greater than 127 are encoded as a sequence of UTF-8 bytes using octal
27 /// escapes. Characters with ordinal values 127 and below are encoded as \\t, \\n (etc.) or an octal escape. Use
28 /// this mode to generate strings compatible with Ice 3.6 and earlier.
30 };
31}
32
33namespace IceInternal
34{
35 //
36 // Add escape sequences (like "\n", or "\123") to the input string
37 // (first parameter).
38 // The second parameter adds characters to escape, and can be empty.
39 //
40 ICE_API std::string escapeString(std::string_view s, std::string_view special, Ice::ToStringMode toStringMode);
41
42 //
43 // Remove escape sequences added by escapeString. Throws std::invalid_argument
44 // for an invalid input string.
45 //
46 ICE_API std::string unescapeString(
47 std::string_view,
48 std::string_view::size_type,
49 std::string_view::size_type,
50 std::string_view special);
51
52 //
53 // Split a string using the given delimiters. Considers single and double quotes;
54 // returns false for unbalanced quote, true otherwise.
55 //
56 ICE_API bool splitString(std::string_view, std::string_view, std::vector<std::string>&);
57
58 //
59 // Join a list of strings using the given delimiter.
60 //
61 ICE_API std::string joinString(const std::vector<std::string>&, std::string_view delimiter);
62
63 //
64 // Trim white space
65 //
66 ICE_API std::string trim(std::string_view);
67
68 //
69 // If a single or double quotation mark is found at the start
70 // position, then the position of the matching closing quote is
71 // returned. If no quotation mark is found at the start position, then
72 // 0 is returned. If no matching closing quote is found, then
73 // std::string::npos is returned.
74 //
75 ICE_API std::string::size_type checkQuote(const std::string&, std::string::size_type = 0);
76
77 //
78 // Match `s' against the pattern `pat'. A * in the pattern acts
79 // as a wildcard: it matches any non-empty sequence of characters
80 // other than a period (`.'). We match by hand here because
81 // it's portable across platforms (whereas regex() isn't).
82 //
83 ICE_API bool match(const std::string&, const std::string&, bool = false);
84
85 //
86 // Get the error message for the last error code or given error code.
87 //
88 ICE_API std::string lastErrorToString();
89#ifdef _WIN32
90 using ErrorCode = unsigned long; // DWORD
91 ICE_API std::string errorToStringWithSource(ErrorCode error, const void* source);
92 inline std::string errorToString(ErrorCode error) { return errorToStringWithSource(error, nullptr); }
93#else
94 using ErrorCode = int;
95 ICE_API std::string errorToString(int);
96#endif
97
98 //
99 // Functions to convert to lower/upper case. These functions accept
100 // UTF8 string/characters but ignore non ASCII characters. Unlike, the
101 // C methods, these methods are not local dependent.
102 //
103 ICE_API std::string toLower(std::string_view);
104 ICE_API std::string toUpper(std::string_view);
105 ICE_API bool isAlpha(char);
106 ICE_API bool isDigit(char);
107
108 //
109 // Remove all whitespace from a string
110 //
111 ICE_API std::string removeWhitespace(std::string_view);
112}
113
114#endif
ToStringMode
The output mode for xxxToString methods such as identityToString and proxyToString.
Definition StringUtil.h:18
@ Compat
Characters with ordinal values greater than 127 are encoded as a sequence of UTF-8 bytes using octal ...
Definition StringUtil.h:29
@ Unicode
Characters with ordinal values greater than 127 are kept as-is in the resulting string.
Definition StringUtil.h:21
@ ASCII
Characters with ordinal values greater than 127 are encoded as universal character names in the resul...
Definition StringUtil.h:25
The Ice RPC framework.
Definition SampleEvent.h:59