Source/Gorgon/String.h

Tue, 06 Jul 2021 10:22:49 +0300

author
cemkalyoncu
date
Tue, 06 Jul 2021 10:22:49 +0300
branch
4.x-dev
changeset 1701
b168349a931d
parent 1687
dc9150a2185d
child 1738
dfb250be177d
permissions
-rw-r--r--

* Image/Bitmap rotate

764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
1 /// @file String.h This file contains string helper functions.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
2 /// They work with std::string
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
3
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
4 #pragma once
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
5
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
6 #include <string>
1022
6b84f8ed6940 * X11 DnD problem is mostly solved
cemkalyoncu
parents: 1021
diff changeset
7 #include <cstring>
6b84f8ed6940 * X11 DnD problem is mostly solved
cemkalyoncu
parents: 1021
diff changeset
8 #include <string>
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
9 #include <sstream>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
10 #include <iostream>
1339
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
11 #include <iomanip>
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
12 #include <stdexcept>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
13 #include <algorithm>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
14 #include "String/Exceptions.h"
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
15 #include "Enum.h"
1059
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
16 #include "Types.h"
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
17
863
c6321c51594e * Fixed fullscreen support for windows
cemkalyoncu
parents: 861
diff changeset
18 #undef decltype
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
19
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
20 namespace Gorgon {
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
21
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
22 /// Contains string related functions and classes. This namespace is not yet utf8 aware.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
23 namespace String {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
24
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
25 struct CaseInsensitiveLess {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
26 bool operator()(const std::string &left, const std::string &right) const {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
27 unsigned len=(unsigned int)std::min(left.length(), right.length());
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
28
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
29 auto l=left.begin();
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
30 auto r=right.begin();
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
31 for(unsigned i=0; i<len; i++) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
32 auto lc=tolower(*l);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
33 auto rc=tolower(*r);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
34 if(lc<rc) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
35 return true;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
36 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
37 else if(lc>rc) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
38 return false;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
39 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
40 ++l;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
41 ++r;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
42 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
43
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
44 return left.length()<right.length();
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
45 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
46 };
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
47
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
48 /// Compares two strings case insensitive. Works similar to strcmp
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
49 inline int CaseInsensitiveCompare(const std::string &left, const std::string &right) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
50 unsigned len=(unsigned int)std::min(left.length(), right.length());
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
51
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
52 auto l=left.begin();
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
53 auto r=right.begin();
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
54 for(unsigned i=0; i<len; i++) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
55 auto lc=tolower(*l);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
56 auto rc=tolower(*r);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
57 if(lc<rc) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
58 return -1;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
59 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
60 else if(lc>rc) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
61 return 1;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
62 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
63 ++l;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
64 ++r;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
65 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
66
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
67 return left.length()<right.length() ? -1 : (left.length()==right.length() ? 0 : 1);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
68 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
69
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
70
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
71 #ifdef DOXYGEN
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
72 /// Converts a string to another type. Works for integral types and
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
73 /// Gorgon classes including Point, Size, etc... There is no error
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
74 /// handling. If conversion does not work, you may end up with
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
75 /// uninitialized object. This system will be fixed at a later point.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
76 template <class T_>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
77 T_ To(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
78 return T_();
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
79 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
80 #endif
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
81
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
82 /// @cond
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
83
1306
9fec2f1bb65a * Compatibility fixes for VS2019
cemkalyoncu
parents: 1304
diff changeset
84
797
5d31c4836303 * Loader for Resource::Data
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
85 # define ISENUMUPGRADED decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum
1306
9fec2f1bb65a * Compatibility fixes for VS2019
cemkalyoncu
parents: 1304
diff changeset
86
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
87 template <class T_>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
88 typename std::enable_if<std::is_constructible<T_, std::string>::value, T_>::type
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
89 To(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
90 return T_(value);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
91 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
92
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
93 template <class T_>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
94 typename std::enable_if<!std::is_constructible<T_, std::string>::value && !ISENUMUPGRADED, T_>::type
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
95 To(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
96 std::stringstream ss(value);
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
97
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
98 T_ ret;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
99 ss>>ret;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
100
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
101 return ret;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
102 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
103
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
104 template <class T_>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
105 typename std::enable_if<std::is_constructible<T_, const char*>::value, T_>::type
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
106 To(const char *value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
107 return T_(value);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
108 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
109
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
110 template <class T_>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
111 typename std::enable_if<!std::is_constructible<T_, const char*>::value && std::is_constructible<T_, std::string>::value, T_>::type
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
112 To(const char *value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
113 return T_(value);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
114 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
115
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
116 template <class T_>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
117 typename std::enable_if<!std::is_constructible<T_, const char*>::value &&
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
118 !std::is_constructible<T_, std::string>::value &&
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
119 !ISENUMUPGRADED,
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
120 T_>::type
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
121 To(const char *value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
122 std::stringstream ss(value);
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
123
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
124 T_ ret;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
125 ss>>ret;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
126
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
127 return ret;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
128 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
129
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
130 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
131 inline char To<char>(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
132 char *n;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
133 return (char)std::strtol(value.c_str(), &n, 10);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
134 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
135
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
136 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
137 inline unsigned char To<unsigned char>(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
138 char *n;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
139 return (unsigned char)std::strtol(value.c_str(), &n, 10);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
140 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
141
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
142 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
143 inline short To<short>(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
144 char *n;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
145 return (short)std::strtol(value.c_str(), &n, 10);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
146 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
147
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
148 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
149 inline unsigned short To<unsigned short>(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
150 char *n;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
151 return (unsigned short)std::strtol(value.c_str(), &n, 10);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
152 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
153
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
154 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
155 inline int To<int>(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
156 char *n;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
157 return (int)std::strtol(value.c_str(), &n, 10);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
158 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
159
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
160 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
161 inline unsigned To<unsigned>(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
162 char *n;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
163 return (unsigned)std::strtol(value.c_str(), &n, 10);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
164 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
165
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
166 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
167 inline long To<long>(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
168 char *n;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
169 return (long)std::strtol(value.c_str(), &n, 10);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
170 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
171
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
172 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
173 inline unsigned long To<unsigned long>(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
174 char *n;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
175 return (unsigned long)std::strtol(value.c_str(), &n, 10);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
176 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
177
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
178 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
179 inline long long To<long long>(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
180 char *n;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
181 return (long long)std::strtol(value.c_str(), &n, 10);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
182 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
183
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
184 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
185 inline unsigned long long To<unsigned long long>(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
186 char *n;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
187 return (unsigned long long)std::strtol(value.c_str(), &n, 10);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
188 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
189
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
190 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
191 inline float To<float>(const std::string &value) {
1339
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
192 if(value=="") return 0;
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
193
1380
8ea1cd4f856e * To<float/double> will no longer cause exceptions
cemkalyoncu
parents: 1339
diff changeset
194 return (float)std::strtof(value.c_str(), nullptr);
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
195 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
196
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
197 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
198 inline double To<double>(const std::string &value) {
1339
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
199 if(value=="") return 0;
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
200
1380
8ea1cd4f856e * To<float/double> will no longer cause exceptions
cemkalyoncu
parents: 1339
diff changeset
201 return std::strtod(value.c_str(), nullptr);
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
202 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
203
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
204 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
205 inline long double To<long double>(const std::string &value) {
1339
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
206 if(value=="") return 0;
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
207
1380
8ea1cd4f856e * To<float/double> will no longer cause exceptions
cemkalyoncu
parents: 1339
diff changeset
208 return std::strtold(value.c_str(), nullptr);
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
209 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
210
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
211 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
212 inline bool To<bool>(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
213 if(value=="false" || value=="no" || value=="" || To<int>(value)==0)
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
214 return false;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
215 else
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
216 return true;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
217 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
218
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
219 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
220 inline char To<char>(const char *value) {
1380
8ea1cd4f856e * To<float/double> will no longer cause exceptions
cemkalyoncu
parents: 1339
diff changeset
221 return (char)std::strtol(value, nullptr, 10);
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
222 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
223
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
224 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
225 inline unsigned char To<unsigned char>(const char *value) {
1380
8ea1cd4f856e * To<float/double> will no longer cause exceptions
cemkalyoncu
parents: 1339
diff changeset
226 return (unsigned char)std::strtol(value, nullptr, 10);
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
227 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
228
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
229 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
230 inline short To<short>(const char *value) {
1380
8ea1cd4f856e * To<float/double> will no longer cause exceptions
cemkalyoncu
parents: 1339
diff changeset
231 return (short)std::strtol(value, nullptr, 10);
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
232 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
233
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
234 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
235 inline unsigned short To<unsigned short>(const char *value) {
1380
8ea1cd4f856e * To<float/double> will no longer cause exceptions
cemkalyoncu
parents: 1339
diff changeset
236 return (unsigned short)std::strtol(value, nullptr, 10);
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
237 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
238
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
239 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
240 inline int To<int>(const char *value) {
1380
8ea1cd4f856e * To<float/double> will no longer cause exceptions
cemkalyoncu
parents: 1339
diff changeset
241 return (int)std::strtol(value, nullptr, 10);
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
242 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
243
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
244 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
245 inline unsigned To<unsigned>(const char *value) {
1380
8ea1cd4f856e * To<float/double> will no longer cause exceptions
cemkalyoncu
parents: 1339
diff changeset
246 return (unsigned)std::strtol(value, nullptr, 10);
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
247 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
248
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
249 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
250 inline long To<long>(const char *value) {
1380
8ea1cd4f856e * To<float/double> will no longer cause exceptions
cemkalyoncu
parents: 1339
diff changeset
251 return (long)std::strtol(value, nullptr, 10);
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
252 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
253
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
254 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
255 inline unsigned long To<unsigned long>(const char *value) {
1380
8ea1cd4f856e * To<float/double> will no longer cause exceptions
cemkalyoncu
parents: 1339
diff changeset
256 return (unsigned long)std::strtol(value, nullptr, 10);
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
257 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
258
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
259 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
260 inline long long To<long long>(const char *value) {
1380
8ea1cd4f856e * To<float/double> will no longer cause exceptions
cemkalyoncu
parents: 1339
diff changeset
261 return (long long)std::strtol(value, nullptr, 10);
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
262 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
263
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
264 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
265 inline unsigned long long To<unsigned long long>(const char *value) {
1380
8ea1cd4f856e * To<float/double> will no longer cause exceptions
cemkalyoncu
parents: 1339
diff changeset
266 return (unsigned long long)std::strtol(value, nullptr, 10);
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
267 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
268
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
269 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
270 inline float To<float>(const char *value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
271 return (float)std::atof(value);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
272 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
273
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
274 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
275 inline double To<double>(const char *value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
276 return std::atof(value);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
277 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
278
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
279 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
280 inline long double To<long double>(const char *value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
281 return std::atof(value);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
282 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
283
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
284 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
285 inline bool To<bool>(const char *value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
286 return To<bool>(std::string(value));
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
287 }
922
02f6eed8821f * Bitmap font ImportFolder, missing trim and toalpha
cemkalyoncu
parents: 912
diff changeset
288
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
289 /// Converts a hexadecimal number stored in the string to a given
1380
8ea1cd4f856e * To<float/double> will no longer cause exceptions
cemkalyoncu
parents: 1339
diff changeset
290 /// integer type. If given string is not a valid number this function
8ea1cd4f856e * To<float/double> will no longer cause exceptions
cemkalyoncu
parents: 1339
diff changeset
291 /// throws
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
292 template <class T_>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
293 T_ HexTo(const std::string &value);
922
02f6eed8821f * Bitmap font ImportFolder, missing trim and toalpha
cemkalyoncu
parents: 912
diff changeset
294
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
295 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
296 inline int HexTo<int>(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
297 return std::stoi(value, nullptr, 16);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
298 }
922
02f6eed8821f * Bitmap font ImportFolder, missing trim and toalpha
cemkalyoncu
parents: 912
diff changeset
299
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
300 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
301 inline long HexTo<long>(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
302 return std::stol(value, nullptr, 16);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
303 }
922
02f6eed8821f * Bitmap font ImportFolder, missing trim and toalpha
cemkalyoncu
parents: 912
diff changeset
304
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
305 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
306 inline long long HexTo<long long>(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
307 return std::stoll(value, nullptr, 16);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
308 }
922
02f6eed8821f * Bitmap font ImportFolder, missing trim and toalpha
cemkalyoncu
parents: 912
diff changeset
309
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
310 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
311 inline unsigned int HexTo<unsigned int>(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
312 return (unsigned int)std::stoul(value, nullptr, 16);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
313 }
922
02f6eed8821f * Bitmap font ImportFolder, missing trim and toalpha
cemkalyoncu
parents: 912
diff changeset
314
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
315 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
316 inline unsigned long HexTo<unsigned long>(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
317 return std::stoul(value, nullptr, 16);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
318 }
922
02f6eed8821f * Bitmap font ImportFolder, missing trim and toalpha
cemkalyoncu
parents: 912
diff changeset
319
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
320 template <>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
321 inline unsigned long long HexTo<unsigned long long>(const std::string &value) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
322 return std::stoull(value, nullptr, 16);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
323 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
324 /// @endcond
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
325
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
326 /// Pads the string to the given number of characters from the start. This function is
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
327 /// not utf aware.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
328 inline std::string PadStart(std::string str, std::size_t len, char pad = ' ') {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
329 if(len > str.size())
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
330 str.insert(0, len - str.size(), pad);
1029
46d49a1ef068 * WindowManager::Set/GetClipboardText now supports multiple formats
cemkalyoncu
parents: 1022
diff changeset
331
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
332 return str;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
333 }
1029
46d49a1ef068 * WindowManager::Set/GetClipboardText now supports multiple formats
cemkalyoncu
parents: 1022
diff changeset
334
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
335 /// Pads the string to the given number of characters from the start. This function is
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
336 /// not utf aware.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
337 inline std::string PadEnd(std::string str, std::size_t len, char pad = ' ') {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
338 if(len > str.size())
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
339 str.insert(str.end(), len - str.size(), pad);
1031
8312876a6b1d * Linux build is fixed
cemkalyoncu
parents: 1029
diff changeset
340
8312876a6b1d * Linux build is fixed
cemkalyoncu
parents: 1029
diff changeset
341 return str;
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
342 }
1029
46d49a1ef068 * WindowManager::Set/GetClipboardText now supports multiple formats
cemkalyoncu
parents: 1022
diff changeset
343
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
344 /// String replace that does not use regex. Works faster than regex variant. This function is
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
345 /// not utf aware.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
346 /// @param str is the string to process
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
347 /// @param find is the substrings to be replaced
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
348 /// @param replace is the string to place instead of find. Can be empty string.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
349 inline std::string Replace(std::string str, const std::string &find, const std::string &replace) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
350 std::string::size_type l=0;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
351
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
352 auto flen=find.length();
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
353 auto rlen=replace.length();
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
354
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
355 if(!find.length()) return str;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
356
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
357 while( (l=str.find(find, l)) != str.npos ) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
358 str.erase(l, flen);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
359 str.insert(l, replace);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
360 l+=rlen;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
361 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
362
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
363 return str;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
364 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
365
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
366 /// Strips whitespace around the given string both from start and end. This function is
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
367 /// not utf aware.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
368 /// @param str is the string to process
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
369 /// @param chars is the characters to be considered as whitespace
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
370 inline std::string Trim(std::string str, const std::string &chars=" \t\n\r") {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
371 if(!str.length()) return "";
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
372
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
373 const char *ptr=str.c_str();
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
374 while(*ptr && chars.find_first_of(*ptr)!=chars.npos) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
375 ptr++;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
376 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
377 str=str.substr(ptr-str.c_str());
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
378
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
379 while(str.length() && chars.find_first_of(str[str.length()-1])!=chars.npos) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
380 str.resize(str.length()-1);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
381 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
382
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
383 return str;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
384 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
385
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
386 /// Strips the whitespace from the start of a string. This function is
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
387 /// not utf aware.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
388 /// @param str is the string to process
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
389 /// @param chars is the characters to be considered as whitespace
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
390 inline std::string TrimStart(std::string str, const std::string &chars=" \t\n\r") {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
391 if(!str.length()) return "";
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
392
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
393 const char *ptr=str.c_str();
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
394 while(*ptr && chars.find_first_of(*ptr)!=chars.npos) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
395 ptr++;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
396 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
397 str=str.substr(ptr-str.c_str());
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
398
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
399 return str;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
400 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
401
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
402 /// Strips the whitespace at the end of a string. This function is
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
403 /// not utf aware.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
404 /// @param str is the string to process
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
405 /// @param chars is the characters to be considered as whitespace
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
406 inline std::string TrimEnd(std::string str, const std::string &chars=" \t\n\r") {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
407 while(str.length() && chars.find_first_of(str[str.length()-1])!=chars.npos) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
408 str.resize(str.length()-1);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
409 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
410
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
411 return str;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
412 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
413
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
414 /// Converts the given string to lowercase. This function is
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
415 /// not utf aware.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
416 inline std::string ToLower(std::string str) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
417 for(auto it=str.begin();it!=str.end();++it) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
418 *it=tolower(*it);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
419 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
420
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
421 return str;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
422 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
423
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
424 /// Converts the given string to uppercase. This function is
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
425 /// not utf aware.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
426 inline std::string ToUpper(std::string str) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
427 for(auto it=str.begin();it!=str.end();++it) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
428 *it=toupper(*it);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
429 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
430
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
431 return str;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
432 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
433
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
434
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
435 /// @cond
1483
4dbbdae925b4 #196: Partial implementation of Dropdown list
cemkalyoncu
parents: 1380
diff changeset
436 inline std::string From(const char &value) {
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
437 return std::to_string(value);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
438 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
439
1483
4dbbdae925b4 #196: Partial implementation of Dropdown list
cemkalyoncu
parents: 1380
diff changeset
440 inline std::string From(const unsigned char &value) {
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
441 return std::to_string(value);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
442 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
443
1483
4dbbdae925b4 #196: Partial implementation of Dropdown list
cemkalyoncu
parents: 1380
diff changeset
444 inline std::string From(const int &value) {
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
445 return std::to_string(value);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
446 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
447
1483
4dbbdae925b4 #196: Partial implementation of Dropdown list
cemkalyoncu
parents: 1380
diff changeset
448 inline std::string From(const unsigned &value) {
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
449 return std::to_string(value);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
450 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
451
1483
4dbbdae925b4 #196: Partial implementation of Dropdown list
cemkalyoncu
parents: 1380
diff changeset
452 inline std::string From(const long &value) {
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
453 return std::to_string(value);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
454 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
455
1483
4dbbdae925b4 #196: Partial implementation of Dropdown list
cemkalyoncu
parents: 1380
diff changeset
456 inline std::string From(const unsigned long &value) {
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
457 return std::to_string(value);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
458 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
459
1483
4dbbdae925b4 #196: Partial implementation of Dropdown list
cemkalyoncu
parents: 1380
diff changeset
460 inline std::string From(const long long &value) {
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
461 return std::to_string(value);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
462 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
463
1483
4dbbdae925b4 #196: Partial implementation of Dropdown list
cemkalyoncu
parents: 1380
diff changeset
464 inline std::string From(const unsigned long long &value) {
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
465 return std::to_string(value);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
466 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
467
1483
4dbbdae925b4 #196: Partial implementation of Dropdown list
cemkalyoncu
parents: 1380
diff changeset
468 inline std::string From(const float &value) {
1339
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
469 std::stringstream ss;
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
470 if(value > 1e7) {
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
471 ss<<std::fixed<<std::setprecision(0)<<value;
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
472 }
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
473 else {
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
474 ss<<std::setprecision(7)<<value;
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
475 }
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
476
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
477 return ss.str();
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
478 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
479
1483
4dbbdae925b4 #196: Partial implementation of Dropdown list
cemkalyoncu
parents: 1380
diff changeset
480 inline std::string From(const double &value) {
1339
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
481 std::stringstream ss;
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
482 if(value > 1e14) {
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
483 ss<<std::fixed<<std::setprecision(0)<<value;
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
484 }
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
485 else {
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
486 ss<<std::setprecision(14)<<value;
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
487 }
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
488 return ss.str();
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
489 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
490
1483
4dbbdae925b4 #196: Partial implementation of Dropdown list
cemkalyoncu
parents: 1380
diff changeset
491 inline std::string From(const long double &value) {
1339
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
492 std::stringstream ss;
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
493 if(value > 1e28l) {
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
494 ss<<std::fixed<<std::setprecision(0)<<value;
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
495 }
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
496 else {
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
497 ss<<std::setprecision(28)<<value;
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
498 }
308d6cabe504 #11: Inputbox variants for easy use
cemkalyoncu
parents: 1334
diff changeset
499 return ss.str();
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
500 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
501
1483
4dbbdae925b4 #196: Partial implementation of Dropdown list
cemkalyoncu
parents: 1380
diff changeset
502 inline std::string From(const std::string &value) {
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
503 return value;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
504 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
505
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
506 template<class T_>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
507 typename std::enable_if<std::is_convertible<T_, std::string>::value, std::string>::type
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
508 From(const T_ &item) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
509 return (std::string)item;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
510 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
511
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
512 template<class T_>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
513 typename std::enable_if<!std::is_convertible<T_, std::string>::value && !decltype(gorgon__enum_tr_loc((*(T_*)nullptr)))::isupgradedenum, std::string>::type
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
514 From(const T_ &item) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
515 std::stringstream ss;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
516 ss<<item;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
517
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
518 return ss.str();
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
519 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
520
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
521 template<typename T>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
522 class IsStreamable
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
523 {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
524 using one = char;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
525 struct two {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
526 char dummy[2];
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
527 };
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
528
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
529 template<class TT>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
530 static one test(decltype(((std::ostream*)nullptr)->operator<<((TT*)nullptr))) { return one(); }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
531
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
532 static two test(...) { return two(); }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
533
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
534 public:
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
535 static const bool Value = sizeof( test(*(std::ostream*)nullptr) )==1;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
536 };
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
537
1483
4dbbdae925b4 #196: Partial implementation of Dropdown list
cemkalyoncu
parents: 1380
diff changeset
538 inline void streamthis(std::stringstream &stream) {
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
539 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
540
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
541 template<class T_, class ...P_>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
542 void streamthis(std::stringstream &stream, const T_ &first, const P_&... rest) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
543 stream<<first;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
544
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
545 streamthis(stream, rest...);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
546 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
547 /// @endcond
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
548
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
549 template<class T_>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
550 struct CanBeStringified {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
551 static const bool Value =
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
552 IsStreamable<T_>::Value ||
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
553 std::is_convertible<T_, std::string>::value ||
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
554 decltype(gorgon__enum_tr_loc(*((typename std::decay<T_>::type*)nullptr)))::isupgradedenum;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
555 };
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
556
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
557 /// Streams the given parameters into a stringstream and returns the result, effectively
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
558 /// concatinating all parameters.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
559 template<class ...P_>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
560 std::string Concat(const P_&... rest) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
561 std::stringstream ss;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
562 streamthis(ss, rest...);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
563
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
564
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
565 return ss.str();
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
566 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
567
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
568 /// Returns the number of bytes used by the next UTF8 codepoint
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
569 inline int UTF8Bytes(char c) {
1059
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
570 if((c & 0b10000000) == 0b00000000) return 1;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
571
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
572 if((c & 0b11100000) == 0b11000000) return 2;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
573
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
574 if((c & 0b11110000) == 0b11100000) return 3;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
575
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
576 if((c & 0b11111000) == 0b11110000) return 4;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
577
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
578 //we are probably at the middle of a code point, just return
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
579 // 1 so that the stream can sync.
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
580 return 1;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
581 }
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
582
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
583 inline int UnicodeUTF8Bytes(Char c) {
1059
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
584 if(c < 0x80) return 1;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
585
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
586 if(c < 0x800) return 2;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
587
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
588 if(c < 0x10000) return 3;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
589
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
590 if(c < 0x0010FFFF) return 4;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
591
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
592 return 3; //replacement: 0xfffd
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
593 }
1304
74c3aab69cb3 * Fixed a bug with justified text
cemkalyoncu
parents: 1249
diff changeset
594
74c3aab69cb3 * Fixed a bug with justified text
cemkalyoncu
parents: 1249
diff changeset
595 inline int UnicodeGlyphCount(const std::string &s) {
1687
dc9150a2185d * Couple of fixes
cemkalyoncu
parents: 1483
diff changeset
596 size_t i = 0;
1304
74c3aab69cb3 * Fixed a bug with justified text
cemkalyoncu
parents: 1249
diff changeset
597 int count = 0;
74c3aab69cb3 * Fixed a bug with justified text
cemkalyoncu
parents: 1249
diff changeset
598 while(i < s.length()) {
74c3aab69cb3 * Fixed a bug with justified text
cemkalyoncu
parents: 1249
diff changeset
599 count++;
74c3aab69cb3 * Fixed a bug with justified text
cemkalyoncu
parents: 1249
diff changeset
600 i += UTF8Bytes(s[i]);
74c3aab69cb3 * Fixed a bug with justified text
cemkalyoncu
parents: 1249
diff changeset
601 }
74c3aab69cb3 * Fixed a bug with justified text
cemkalyoncu
parents: 1249
diff changeset
602
74c3aab69cb3 * Fixed a bug with justified text
cemkalyoncu
parents: 1249
diff changeset
603 return count;
74c3aab69cb3 * Fixed a bug with justified text
cemkalyoncu
parents: 1249
diff changeset
604 }
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
605
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
606 /// Appends a unicode code point to the string. If the given char
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
607 /// is valid, this function will return true. Otherwise, it will place
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
608 /// a three byte long replacement character and returns false.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
609 inline bool AppendUnicode(std::string &s, Char c) {
1059
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
610 if(c > 0x10FFFF) {
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
611 s += "\xEF\xBF\xBD";
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
612 return false;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
613 }
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
614
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
615 int bytes = UnicodeUTF8Bytes(c);
1333
a13287f2e3d9 #11 Inputbox caret movement and selection
cemkalyoncu
parents: 1308
diff changeset
616 s.resize(s.size() + bytes);
1059
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
617
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
618 auto it = s.rbegin();
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
619 int cur = 0;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
620
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
621 while(cur < bytes-1) {
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
622 *it = (c & 0b00111111) | 0b10000000;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
623 it++;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
624 cur++;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
625 c = c >> 6;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
626 }
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
627
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
628 if(bytes == 1) {
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
629 *it = c;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
630 }
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
631 else if(bytes == 2) {
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
632 *it = c | 0b11000000;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
633 }
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
634 else if(bytes == 3) {
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
635 *it = c | 0b11100000;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
636 }
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
637 else if(bytes == 4) {
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
638 *it = c | 0b11110000;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
639 }
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
640 else
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
641 return false; // future proofing
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
642
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
643 return true;
51217a097c53 * Full UTF8 support for X11 and DWM
cemkalyoncu
parents: 1031
diff changeset
644 }
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
645
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
646 /// Appends a unicode code point to the string. If the given char
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
647 /// is valid, this function will return true. Otherwise, it will place
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
648 /// a three byte long replacement character and returns false. pos is
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
649 /// the byte offset to insert the character.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
650 inline bool InsertUnicode(std::string &s, std::size_t pos, Char c) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
651 if(c > 0x10FFFF) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
652 s += "\xEF\xBF\xBD";
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
653 return false;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
654 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
655
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
656 char data[4] = {};
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
657
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
658 int bytes = UnicodeUTF8Bytes(c);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
659
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
660 auto it = data + 3;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
661 int cur = 0;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
662
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
663 while(cur < bytes-1) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
664 *it = (c & 0b00111111) | 0b10000000;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
665 it--;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
666 cur++;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
667 c = c >> 6;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
668 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
669
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
670 if(bytes == 1) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
671 *it = c;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
672 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
673 else if(bytes == 2) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
674 *it = c | 0b11000000;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
675 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
676 else if(bytes == 3) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
677 *it = c | 0b11100000;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
678 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
679 else if(bytes == 4) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
680 *it = c | 0b11110000;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
681 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
682 else
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
683 return false; // future proofing
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
684
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
685 s.insert(pos, it, bytes);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
686
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
687 return true;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
688 }
846
c9cf0fba3bd6 * Complete rewrite for URI encoding module with
cemkalyoncu
parents: 830
diff changeset
689
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
690 /// Line ending types
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
691 enum class LineEnding {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
692 /// None, no line endings
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
693 None = 0,
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
694
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
695 /// line feed \\x0a
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
696 LF = 1,
846
c9cf0fba3bd6 * Complete rewrite for URI encoding module with
cemkalyoncu
parents: 830
diff changeset
697
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
698 /// line feed \\x0a
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
699 Unix = 1,
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
700
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
701 /// carriage return \\x0d
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
702 CR = 2,
846
c9cf0fba3bd6 * Complete rewrite for URI encoding module with
cemkalyoncu
parents: 830
diff changeset
703
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
704 /// carriage return \\x0d
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
705 Mac = 2,
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
706
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
707 /// \\x0d\\x0a
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
708 CRLF = 3,
846
c9cf0fba3bd6 * Complete rewrite for URI encoding module with
cemkalyoncu
parents: 830
diff changeset
709
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
710 /// \\x0d\\x0a
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
711 Standard = 3,
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
712
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
713 /// \\x0d\\x0a
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
714 Windows = 3,
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
715
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
716 /// When there are multiple types of line endings present
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
717 Mixed = 4,
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
718 };
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
719
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
720 /// Fixes/changes line endings. If none is supplied, all line endings will be removed. If mixed
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
721 /// is set, nothing will be done.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
722 std::string FixLineEndings(const std::string &in, LineEnding type = LineEnding::Standard);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
723
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
724 //for pretty documentation
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
725 #ifdef DOXYGEN
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
726 /// Creates a string from the given data. Similar to to_string but allows
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
727 /// conversion of a type if it can be casted or streamed to output. Also uses
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
728 /// std::to_string where possible.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
729 template<class T_>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
730 std::string From(const T_ &item) { return ""; }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
731 #endif
1021
6994e5afd7d3 * Win32 dragging is complete
cemkalyoncu
parents: 922
diff changeset
732
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
733 /// Joins a list of strings to a single string using the given glue text.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
734 template<class T_>
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
735 std::string Join(const T_ &vec, const std::string &glue = ", ") {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
736 int totalsize = 0;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
737 int gluesize = (int)glue.size();
1021
6994e5afd7d3 * Win32 dragging is complete
cemkalyoncu
parents: 922
diff changeset
738
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
739 for(const std::string &s : vec) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
740 if(totalsize)
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
741 totalsize += gluesize;
1021
6994e5afd7d3 * Win32 dragging is complete
cemkalyoncu
parents: 922
diff changeset
742
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
743 totalsize += (int)s.size();
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
744 }
1021
6994e5afd7d3 * Win32 dragging is complete
cemkalyoncu
parents: 922
diff changeset
745
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
746 std::string ret;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
747 ret.resize(totalsize);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
748 bool first = true;
1021
6994e5afd7d3 * Win32 dragging is complete
cemkalyoncu
parents: 922
diff changeset
749
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
750 char *data = &ret[0];
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
751 const char *gluedata = glue.data();
1021
6994e5afd7d3 * Win32 dragging is complete
cemkalyoncu
parents: 922
diff changeset
752
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
753 for(const std::string &s : vec) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
754 if(!first) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
755 std::memcpy(data, gluedata, gluesize);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
756 data += gluesize;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
757 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
758
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
759 std::memcpy(data, s.data(), s.size());
1021
6994e5afd7d3 * Win32 dragging is complete
cemkalyoncu
parents: 922
diff changeset
760
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
761 data += s.size();
1021
6994e5afd7d3 * Win32 dragging is complete
cemkalyoncu
parents: 922
diff changeset
762
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
763 first = false;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
764 }
1021
6994e5afd7d3 * Win32 dragging is complete
cemkalyoncu
parents: 922
diff changeset
765
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
766 return ret;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
767 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
768
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
769 /// Extracts the part of the string up to the given marker. Extracted string and
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
770 /// the marker is removed from the original string. If the given string does not
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
771 /// contain marker, entire string will be extracted. It is possible to tokenize
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
772 /// the given string using repeated calls to this function. However, its more
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
773 /// convenient to use Tokenizer.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
774 /// @param original string that will be processed. This string will be modified
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
775 /// by the program
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
776 /// @param marker string that will be searched.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
777 /// @param trim if set, both extracted and the remaining part of the string
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
778 /// @return Extracted string. Does not contain the marker.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
779 inline std::string Extract(std::string &original, const std::string &marker, bool trim = false) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
780 auto pos=original.find(marker);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
781
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
782 if(pos==original.npos) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
783 std::string ret;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
784 std::swap(ret, original);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
785
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
786 return ret;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
787 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
788
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
789 std::string ret=original.substr(0, pos);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
790 original=original.substr(pos+marker.length());
912
e903f3428705 * Additional functions for URI helper classes
cemkalyoncu
parents: 881
diff changeset
791
e903f3428705 * Additional functions for URI helper classes
cemkalyoncu
parents: 881
diff changeset
792 if(trim) {
e903f3428705 * Additional functions for URI helper classes
cemkalyoncu
parents: 881
diff changeset
793 ret = TrimEnd(ret);
e903f3428705 * Additional functions for URI helper classes
cemkalyoncu
parents: 881
diff changeset
794 original = TrimStart(original);
e903f3428705 * Additional functions for URI helper classes
cemkalyoncu
parents: 881
diff changeset
795 }
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
796
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
797 return ret;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
798 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
799
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
800
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
801 /// Extracts the part of the string up to the given marker. Extracted string and
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
802 /// the marker is removed from the original string. If the given string does not
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
803 /// contain marker, entire string will be extracted. It is possible to tokenize
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
804 /// the given string using repeated calls to this function. However, its more
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
805 /// convenient to use Tokenizer.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
806 /// @param original string that will be processed. This string will be modified
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
807 /// by the program
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
808 /// @param marker character that will be searched.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
809 /// @param trim if set, both extracted and the remaining part of the string
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
810 /// @return Extracted string. Does not contain the marker.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
811 inline std::string Extract(std::string &original, char marker, bool trim = false) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
812 auto pos=original.find_first_of(marker);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
813
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
814 if(pos==original.npos) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
815 std::string ret;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
816 std::swap(ret, original);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
817
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
818 return ret;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
819 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
820
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
821 std::string ret=original.substr(0, pos);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
822 original=original.substr(pos+1);
912
e903f3428705 * Additional functions for URI helper classes
cemkalyoncu
parents: 881
diff changeset
823
e903f3428705 * Additional functions for URI helper classes
cemkalyoncu
parents: 881
diff changeset
824 if(trim) {
e903f3428705 * Additional functions for URI helper classes
cemkalyoncu
parents: 881
diff changeset
825 ret = TrimEnd(ret);
e903f3428705 * Additional functions for URI helper classes
cemkalyoncu
parents: 881
diff changeset
826 original = TrimStart(original);
e903f3428705 * Additional functions for URI helper classes
cemkalyoncu
parents: 881
diff changeset
827 }
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
828
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
829 return ret;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
830 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
831
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
832 enum class QuoteType {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
833 None,
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
834 Single,
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
835 Double,
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
836 Both
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
837 };
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
838
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
839 /// Extracts the part of the string up to the given marker. This function will
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
840 /// skipped quoted sections of the string. Both single and double quotes can be
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
841 /// considered, however, double quotes should match with double quotes and single
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
842 /// quotes should match with single quotes. A different quote type inside quote
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
843 /// region is ignored. Extracted string and the marker is removed from the original
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
844 /// string. If the given string does not contain marker outside the quotes,
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
845 /// entire string will be extracted. It is possible to tokenize
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
846 /// the given string using repeated calls to this function. Unbalanced quotes will
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
847 /// be treated ending at the end of the string.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
848 /// @param original string that will be processed. This string will be modified
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
849 /// by the program
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
850 /// @param marker string that will be searched. It is possible to specify quote as
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
851 /// a marker.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
852 /// @param quotetype controls which type of quotes will be considered.
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
853 /// @return Extracted string. Does not contain the marker. Quotes will not be removed
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
854 inline std::string Extract_UseQuotes(std::string &original, char marker, QuoteType quotetype=QuoteType::Both) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
855 int inquotes=0;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
856 std::size_t pos=0;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
857
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
858 for(auto &c : original) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
859 if(inquotes==1) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
860 if(c=='\'') {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
861 inquotes=0;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
862 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
863 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
864 else if(inquotes==2) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
865 if(c=='"') {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
866 inquotes=0;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
867 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
868 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
869 else if(c==marker) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
870 std::string temp=original.substr(0, pos);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
871 original=original.substr(pos+1);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
872
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
873 return temp;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
874 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
875 else if(c=='\'' && (quotetype==QuoteType::Single || quotetype==QuoteType::Both)) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
876 inquotes=1;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
877 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
878 else if(c=='"' && (quotetype==QuoteType::Double || quotetype==QuoteType::Both)) {
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
879 inquotes=2;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
880 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
881
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
882 pos++;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
883 }
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
884
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
885 std::string temp;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
886 std::swap(temp, original);
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
887
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
888 return temp;
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
889 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
890
1334
e32bc803c3fe #11: Inserting text to the middle
cemkalyoncu
parents: 1333
diff changeset
891 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
892 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
893
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
894 # undef ISENUMUPGRADED

mercurial