Kigs Framework  Doc version 0.8
Open source multi purpose Rapid Application Development framework
kstlstring.h
1 #ifndef __KSTLSTRING_H__
2 #define __KSTLSTRING_H__
3 
4 #include "Platform/Core/CorePlatformDefines.h"
5 
6 #include <string>
7 #include <algorithm>
8 
9 #ifndef _NO_KSTL_OVERLOADING_
10 
11 #include "CoreSTLAllocator.h"
12 
13 namespace kstl
14 {
15  using string = std::basic_string<char, std::char_traits<char>, CoreSTLAllocator<char>>;
16  using wstring = std::basic_string<wchar_t, std::char_traits<wchar_t>, CoreSTLAllocator<wchar_t>>;
17  using u16string = std::basic_string<char16_t, std::char_traits<char16_t>, CoreSTLAllocator<char16_t>>;
18 
19  inline string to_string(int i)
20  {
21  char buffer[32];
22  snprintf(buffer, 32, "%d", i);
23  return buffer;
24  }
25 }
26 
27 
28 
29 #else // _NO_KSTL_OVERLOADING_
30 
31 
32 namespace kstl = std;
33 #endif // _NO_KSTL_OVERLOADING_
34 
35 #include <locale>
36 
37 static inline kstl::string ToUpperCase(const kstl::string& a_entry)
38 {
39  std::locale loc;
40  kstl::string str = "";
41 
42  for (std::string::size_type i = 0; i<a_entry.size(); ++i)
43  str += std::toupper(a_entry[i], loc);
44 
45  return str;
46 }
47 
48 static inline void str_toupper(std::string& s) {
49  std::transform(s.begin(), s.end(), s.begin(),
50  [](unsigned char c) { return std::toupper(c); }
51  );
52 }
53 
54 static inline kstl::string ToLowerCase(const kstl::string& a_entry)
55 {
56  std::locale loc;
57  kstl::string str = "";
58 
59  for (std::string::size_type i = 0; i<a_entry.size(); ++i)
60  str += std::tolower(a_entry[i], loc);
61 
62  return str;
63 }
64 
65 static inline void str_tolower(std::string& s) {
66  std::transform(s.begin(), s.end(), s.begin(),
67  [](unsigned char c) { return std::tolower(c); }
68  );
69 }
70 
71 #ifdef __ANDROID__
72 #include "kstlsstream.h"
73 // Workaround for Android NDK builds (version r10e) that does not support std::to_string
74 namespace std
75 {
76  template <typename T>
77  kstl::string to_string(T value)
78  {
79  kstl::ostringstream tmp;
80  tmp << value;
81  return tmp.str();
82  }
83 }
84 #endif
85 
86 #endif