Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
text.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Contact: Krzysztof Dynowski (k.dynowski@samsumg.com)
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 
25 #ifndef COMMON_UTILS_TEXT_HPP
26 #define COMMON_UTILS_TEXT_HPP
27 
28 #include <string>
29 #include <vector>
30 #include <sstream>
31 
32 namespace utils {
33 
34 inline bool beginsWith(std::string const &value, std::string const &part)
35 {
36  if (part.size() > value.size()) {
37  return false;
38  }
39  return std::equal(part.begin(), part.end(), value.begin());
40 }
41 
42 inline bool endsWith(std::string const &value, std::string const &part)
43 {
44  if (part.size() > value.size()) {
45  return false;
46  }
47  return std::equal(part.rbegin(), part.rend(), value.rbegin());
48 }
49 
53 std::string toHexString(const void *data, unsigned len);
54 
55 template<typename T>
56 std::string join(const std::vector<T>& vec, const char *delim)
57 {
58  std::stringstream res;
59  for (const auto& s : vec) {
60  if (res.tellp()>0) {
61  res << delim;
62  }
63  res << s;
64  }
65  return res.str();
66 }
67 
68 std::vector<std::string> split(const std::string& str, const std::string& delim);
69 
70 } // namespace utils
71 
72 #endif // COMMON_UTILS_TEXT_HPP
std::vector< std::string > split(const std::string &str, const std::string &delim)
Definition: text.cpp:44
std::string toHexString(const void *data, unsigned len)
Convert binary bytes array to hex string representation.
Definition: text.cpp:33
char data[368]
Definition: initctl.cpp:41
std::string join(const std::vector< T > &vec, const char *delim)
Definition: text.hpp:56
bool endsWith(std::string const &value, std::string const &part)
Definition: text.hpp:42
bool beginsWith(std::string const &value, std::string const &part)
Definition: text.hpp:34