All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
StringHelpers.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Space.h"
6 
7 #include <string>
8 #include <algorithm>
9 #include <sstream>
10 #include <vector>
11 
12 namespace Eegeo
13 {
14  namespace Helpers
15  {
16 #pragma clang diagnostic push
17 #pragma clang diagnostic ignored "-Wunused-function"
18  bool CaseInsensitiveStringEquals(const std::string& a, const std::string& b);
19 
20  std::string ToLower(const std::string& str);
21 
22  size_t Split(const std::string& s, char delim, std::vector<std::string>& out_elems);
23 
24  std::string TrimRight(const std::string& str, const std::string& charsToTrim);
25 
26  bool TryParseLatLong(const std::string& latString, const std::string& lonString, Eegeo::Space::LatLong& out_LatLon);
27 
28  bool TryParseDouble(const std::string& string, double& out_double);
29 
30  bool TryParseInt(const std::string& string, int& out_int);
31 
32  void SearchReplace(std::string& in_out_originalString, const std::string& searchTerm, const std::string& replaceTerm);
33 
34  bool Contains(std::string& originalString, const std::string& searchTerm);
35 
36  void PadRight(std::stringstream& stream, const std::string& string, int lineLengthToPadTo);
37 
38  void PadLeftRight(std::stringstream& stream, const std::string& string, int leftPadding, int lineLengthToPadTo);
39 
40  std::string FloatingPointToString(float v, int decimalPlaces);
41 
42  std::string FloatingPointToString(double v, int decimalPlaces);
43 #pragma clang diagnostic pop
44 
45  std::string Join(const std::vector<std::string>& tokens, const std::string separator);
46 
47  template <typename T>
48  std::string Join(const std::vector<T>& values, const std::string& seperator)
49  {
50  std::stringstream ss;
51 
52  for (typename std::vector<T>::const_iterator iter = values.begin(); iter != values.end(); ++iter)
53  {
54  ss << *iter;
55  if (iter != values.end() - 1)
56  {
57  ss << seperator;
58  }
59  }
60 
61  return ss.str();
62  }
63 
64  std::string CamelCaseToSnakeCase(const std::string& camelCase);
65  }
66 }