MongoDB C++ Driver legacy-1.1.2
Loading...
Searching...
No Matches
text.h
1// text.h
2
3/*
4 * Copyright 2010 10gen Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * 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
19#pragma once
20
21#include <vector>
22#include <string>
23
24#include "mongo/base/disallow_copying.h"
25
26namespace mongo {
27
29public:
33 StringSplitter(const char* big, const char* splitter) : _big(big), _splitter(splitter) {}
34
36 bool more() const {
37 return _big[0] != 0;
38 }
39
41 std::string next();
42
43 void split(std::vector<std::string>& l);
44
45 std::vector<std::string> split();
46
47 static std::vector<std::string> split(const std::string& big, const std::string& splitter);
48
49 static std::string join(const std::vector<std::string>& l, const std::string& split);
50
51private:
52 const char* _big;
53 const char* _splitter;
54};
55
56/* This doesn't defend against ALL bad UTF8, but it will guarantee that the
57 * string can be converted to sequence of codepoints. However, it doesn't
58 * guarantee that the codepoints are valid.
59 */
60bool isValidUTF8(const char* s);
61bool isValidUTF8(const std::string& s);
62
63// expect that n contains a base ten number and nothing else after it
64// NOTE win version hasn't been tested directly
65long long parseLL(const char* n);
66
67#if defined(_WIN32)
68
69std::string toUtf8String(const std::wstring& wide);
70
71std::wstring toWideString(const char* s);
72
73bool writeUtf8ToWindowsConsole(const char* utf8String, unsigned int utf8StringSize);
74
75/* like toWideString but UNICODE macro sensitive */
76#if !defined(_UNICODE)
77#error temp error
78inline std::string toNativeString(const char* s) {
79 return s;
80}
81#else
82inline std::wstring toNativeString(const char* s) {
83 return toWideString(s);
84}
85#endif
86
87class WindowsCommandLine {
88 MONGO_DISALLOW_COPYING(WindowsCommandLine);
89 char** _argv;
90 char** _envp;
91
92public:
93 WindowsCommandLine(int argc, wchar_t* argvW[], wchar_t* envpW[]);
94 ~WindowsCommandLine();
95 char** argv(void) const {
96 return _argv;
97 };
98 char** envp(void) const {
99 return _envp;
100 };
101};
102
103#endif // #if defined(_WIN32)
104
112std::string constructUtf8WindowsCommandLine(const std::vector<std::string>& argv);
113
114} // namespace mongo
Definition text.h:28
std::string next()
get next split string fragment
StringSplitter(const char *big, const char *splitter)
Definition text.h:33
bool more() const
Definition text.h:36
Utility functions for parsing numbers from strings.
Definition compare_numbers.h:20
std::string constructUtf8WindowsCommandLine(const std::vector< std::string > &argv)
Construct a Windows command line string, UTF-8 encoded, from a vector of UTF-8 arguments,...