strusBase  0.17
string_conv.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Patrick P. Frey
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
9 #ifndef _STRUS_STRING_CONV_HPP_INCLUDED
10 #define _STRUS_STRING_CONV_HPP_INCLUDED
11 #include <string>
12 #include <stdexcept>
13 
14 namespace strus {
15 
17  StringConvOk = 0x0,
20 };
21 
24 std::runtime_error stringconv_exception( StringConvError errcode);
25 
30 std::string tolower( const char* val, StringConvError& err);
31 
37 std::string tolower( const char* val, std::size_t size, StringConvError& err);
38 
43 std::string tolower( const std::string& val, StringConvError& err);
44 
49 std::string trim( const std::string& val, StringConvError& err);
50 
56 std::string trim( const char* val, std::size_t size, StringConvError& err);
57 
62 bool isEmptyString( const char* val, std::size_t size);
63 
67 bool isEmptyString( const std::string& val);
68 
73 bool caseInsensitiveEquals( const std::string& val1, const std::string& val2);
74 
79 bool caseInsensitiveStartsWith( const std::string& val, const std::string& prefix);
80 
85 bool stringStartsWith( const std::string& val, const std::string& prefix);
86 
91 std::string utf8clean( const std::string& name, StringConvError& err);
92 
97 std::string unescape( const std::string& val, StringConvError& err);
98 
101 {
102  static std::string tolower( const std::string& str)
103  {
104  StringConvError errcode = StringConvOk;
105  std::string rt = strus::tolower( str, errcode);
106  if (errcode != StringConvOk) throw strus::stringconv_exception( errcode);
107  return rt;
108  }
109  static std::string tolower( const char* str, std::size_t strsize)
110  {
111  StringConvError errcode = StringConvOk;
112  std::string rt = strus::tolower( str, strsize, errcode);
113  if (errcode != StringConvOk) throw strus::stringconv_exception( errcode);
114  return rt;
115  }
116  static std::string trim( const std::string& str)
117  {
118  StringConvError errcode = StringConvOk;
119  std::string rt = strus::trim( str, errcode);
120  if (errcode != StringConvOk) throw strus::stringconv_exception( errcode);
121  return rt;
122  }
123  static std::string trim( const char* str, std::size_t strsize)
124  {
125  StringConvError errcode = StringConvOk;
126  std::string rt = strus::trim( str, strsize, errcode);
127  if (errcode != StringConvOk) throw strus::stringconv_exception( errcode);
128  return rt;
129  }
130  static std::string unescape( const std::string& str)
131  {
132  StringConvError errcode = StringConvOk;
133  std::string rt = strus::unescape( str, errcode);
134  if (errcode != StringConvOk) throw strus::stringconv_exception( errcode);
135  return rt;
136  }
137 };
138 
139 }//namespace
140 #endif
bool stringStartsWith(const std::string &val, const std::string &prefix)
Test prefix on equality.
Definition: string_conv.hpp:18
static std::string unescape(const std::string &str)
Definition: string_conv.hpp:130
Inlined version of string conversion functions throwing an exception instead of setting an error code...
Definition: string_conv.hpp:100
std::runtime_error stringconv_exception(StringConvError errcode)
Convert string conversion error code into an exception.
static std::string trim(const char *str, std::size_t strsize)
Definition: string_conv.hpp:123
std::string trim(const std::string &val, StringConvError &err)
Trim trailing and heading whitespace and control characters.
StringConvError
Definition: string_conv.hpp:16
std::string utf8clean(const std::string &name, StringConvError &err)
Convert possibly broken UTF-8 to valid UTF-8.
Definition: string_conv.hpp:19
bool caseInsensitiveStartsWith(const std::string &val, const std::string &prefix)
Test prefix on Ascii letter caseinsensitive equality.
std::string tolower(const char *val, StringConvError &err)
Convert ASCII letters in string to lowercase.
std::string unescape(const std::string &val, StringConvError &err)
Convert excaped control characters to their unescaped form (e.g. \n to )
static std::string tolower(const char *str, std::size_t strsize)
Definition: string_conv.hpp:109
Definition: string_conv.hpp:17
bool caseInsensitiveEquals(const std::string &val1, const std::string &val2)
Compare on Ascii letter caseinsensitive equality.
static std::string trim(const std::string &str)
Definition: string_conv.hpp:116
static std::string tolower(const std::string &str)
Definition: string_conv.hpp:102
bool isEmptyString(const char *val, std::size_t size)
Evaluate if a string is empty or contains only space characters.