MongoDB  2.7.0
stringutils.h
1 // stringutils.h
2 
3 /* Copyright 2010 10gen Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #pragma once
19 
20 #include <ctype.h>
21 
22 #include <string>
23 #include <vector>
24 
25 #include <boost/scoped_array.hpp>
26 
27 namespace mongo {
28 
29  // see also mongoutils/str.h - perhaps move these there?
30  // see also text.h
31 
32  void splitStringDelim( const std::string& str , std::vector<std::string>* res , char delim );
33 
34  void joinStringDelim( const std::vector<std::string>& strs , std::string* res , char delim );
35 
36  inline std::string tolowerString( StringData input ) {
37  std::string::size_type sz = input.size();
38 
39  boost::scoped_array<char> line(new char[sz+1]);
40  char * copy = line.get();
41 
42  for ( std::string::size_type i=0; i<sz; i++ ) {
43  char c = input[i];
44  copy[i] = (char)tolower( (int)c );
45  }
46  copy[sz] = 0;
47  return copy;
48  }
49 
51  class LexNumCmp {
52  public:
54  LexNumCmp( bool lexOnly );
61  static int cmp( const StringData& s1, const StringData& s2, bool lexOnly );
62  int cmp( const StringData& s1, const StringData& s2 ) const;
63  bool operator()( const StringData& s1, const StringData& s2 ) const;
64  private:
65  bool _lexOnly;
66  };
67 
68  // TODO: Sane-ify core string functionality
69  // For now, this needs to be near the LexNumCmp or else
70  int versionCmp(const StringData rhs, const StringData lhs);
71 
72 } // namespace mongo
LexNumCmp(bool lexOnly)
Definition: stringutils.cpp:45
static int cmp(const StringData &s1, const StringData &s2, bool lexOnly)
Non numeric characters are compared lexicographically; numeric substrings are compared numerically; d...
Definition: stringutils.cpp:49
Functor for combining lexical and numeric comparisons.
Definition: stringutils.h:51