utils.h
Go to the documentation of this file.
1 // Copyright zooml.com 2008 All rights reserved.
2 #ifndef __TERRALIB_COMMON_INTERNAL_URI_UTILS_H
3 #define __TERRALIB_COMMON_INTERNAL_URI_UTILS_H
4 #include "../Config.h"
5 #include <string>
6 #include <stack>
7 #include <cstddef>
8 namespace te
9 {
10  namespace common
11  {
12  namespace uri
13  {
14  std::string TECOMMONEXPORT convert(bool v); ///< bool to string, true="1", false="0"
15  std::string TECOMMONEXPORT convert(int v); ///< int to string
16  std::string TECOMMONEXPORT convert(unsigned int v); ///< uint to string
17  std::string TECOMMONEXPORT convert(long int v); ///< long int to string
18  std::string TECOMMONEXPORT convert(unsigned long int v); ///< unsigned long int to string
19  std::string TECOMMONEXPORT convert(long long int v); ///< long long int to string
20  std::string TECOMMONEXPORT convert(unsigned long long int v); ///< unsigned long long int to string
21  # ifndef _WIN32
22  // std::string TECOMMONEXPORT convert(std::ptrdiff_t v); ///< ptrdiff_t to string
23  # endif
24  std::string TECOMMONEXPORT convert(double v); ///< double to string
25  std::string TECOMMONEXPORT convert(const std::string& v); ///< string to trimmed string
26  inline std::string convert(const char* v) {return v;} ///< cstring to string
27  /// String to bool, returning true if set, which is when
28  /// the string is not empty or all isspace.
29  /// isspace before and/or after value OK.
30  /// The following, and their uppercase, qualify as true:
31  /// 1, 't', "true", 'y', "yes", "on". Their complements are
32  /// considered false, and all else error.
33  /// @exception std::invalid_argument on conversion error
34  bool TECOMMONEXPORT convert(const std::string& s, bool& v);
35  /// String to int, returning true if set, which is when
36  /// the string is not empty or all isspace.
37  /// isspace before and/or after value OK.
38  /// @exception std::invalid_argument on conversion error
39  bool TECOMMONEXPORT convert(const std::string& s, int& v);
40  /// String to unsigned int, returning true if set, which
41  /// is when the string is not empty or all isspace.
42  /// isspace before and/or after value OK.
43  /// @exception std::invalid_argument on conversion error
44  bool TECOMMONEXPORT convert(const std::string& s, unsigned int& v);
45  /// String to size_t, returning true if set, which
46  /// is when the string is not empty or all isspace.
47  /// isspace before and/or after value OK.
48  /// @exception std::invalid_argument on conversion error
49  bool TECOMMONEXPORT convert(const std::string& s, unsigned long int& v);
50  /// String to long long int, returning true if set, which
51  /// is when the string is not empty or all isspace.
52  /// isspace before and/or after value OK.
53  /// @exception std::invalid_argument on conversion error
54  bool TECOMMONEXPORT convert(const std::string& s, long long int& v);
55  /// String to unsigned long long int, returning true if set,
56  /// which is when the string is not empty or all isspace.
57  /// isspace before and/or after value OK.
58  /// @exception std::invalid_argument on conversion error
59  bool TECOMMONEXPORT convert(const std::string& s, unsigned long long int& v);
60  /// String to double, returning true if set, which is
61  /// when the string is not empty or all isspace.
62  /// isspace before and/or after value OK.
63  /// @exception std::invalid_argument on conversion error
64  bool TECOMMONEXPORT convert(const std::string& s, double& v);
65  /// String to trimmed string, returning true if set, which
66  /// is when the string is not empty or all isspace.
67  bool TECOMMONEXPORT convert(const std::string& s, std::string& v);
68  bool TECOMMONEXPORT isspaces(const char* s); ///< Test if string is empty or all isspace.
69  /// Parse hex chars at pos, returning success, and set the char and advance
70  /// first on success.
71  bool TECOMMONEXPORT parse_hex(const std::string& s, size_t pos, char& chr);
72  /// Convert the char v to hex and add the 2 chars to the end of s.
73  void TECOMMONEXPORT append_hex(char v, std::string& s);
74  }
75  }
76 }
77 #endif
void TECOMMONEXPORT append_hex(char v, std::string &s)
Convert the char v to hex and add the 2 chars to the end of s.
bool TECOMMONEXPORT isspaces(const char *s)
Test if string is empty or all isspace.
URI C++ Library.
#define TECOMMONEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:65
std::string TECOMMONEXPORT convert(const path &v)
URI path to string.
bool TECOMMONEXPORT parse_hex(const std::string &s, size_t pos, char &chr)
Parse hex chars at pos, returning success, and set the char and advance first on success.