MongoDB C++ Driver  legacy-1.0.5
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 
26 namespace mongo {
27 
29  public:
33  StringSplitter( const char * big , const char * splitter )
34  : _big( big ) , _splitter( splitter ) {
35  }
36 
38  bool more() const { return _big[0] != 0; }
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 
51  private:
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  */
60  bool isValidUTF8(const char *s);
61  bool 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
65  long long parseLL( const char *n );
66 
67 #if defined(_WIN32)
68 
69  std::string toUtf8String(const std::wstring& wide);
70 
71  std::wstring toWideString(const char *s);
72 
73  bool writeUtf8ToWindowsConsole( const char* utf8String, unsigned int utf8StringSize );
74 
75  /* like toWideString but UNICODE macro sensitive */
76 # if !defined(_UNICODE)
77 #error temp error
78  inline std::string toNativeString(const char *s) { return s; }
79 # else
80  inline std::wstring toNativeString(const char *s) { return toWideString(s); }
81 # endif
82 
83  class WindowsCommandLine {
84  MONGO_DISALLOW_COPYING(WindowsCommandLine);
85  char** _argv;
86  char** _envp;
87 
88  public:
89  WindowsCommandLine(int argc, wchar_t* argvW[], wchar_t* envpW[]);
90  ~WindowsCommandLine();
91  char** argv(void) const { return _argv; };
92  char** envp(void) const { return _envp; };
93  };
94 
95 #endif // #if defined(_WIN32)
96 
104  std::string constructUtf8WindowsCommandLine(const std::vector<std::string>& argv);
105 
106 } // namespace mongo
std::string next()
get next split string fragment
the main MongoDB namespace
Definition: bulk_operation_builder.h:24
Definition: text.h:28
StringSplitter(const char *big, const char *splitter)
Definition: text.h:33
bool more() const
Definition: text.h:38
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, "argv".