| 1 | /*
|
|---|
| 2 | * SPDX-FileCopyrightText: 2019 Jaroslav Jindrak
|
|---|
| 3 | *
|
|---|
| 4 | * SPDX-License-Identifier: BSD-3-Clause
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | #include <cassert>
|
|---|
| 8 | #include <string>
|
|---|
| 9 |
|
|---|
| 10 | namespace std
|
|---|
| 11 | {
|
|---|
| 12 | int stoi(const string& str, size_t* idx, int base)
|
|---|
| 13 | {
|
|---|
| 14 | // TODO: implement using stol once we have numeric limits
|
|---|
| 15 | __unimplemented();
|
|---|
| 16 | return 0;
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | long stol(const string& str, size_t* idx, int base)
|
|---|
| 20 | {
|
|---|
| 21 | char* end;
|
|---|
| 22 | long result = ::strtol(str.c_str(), &end, base);
|
|---|
| 23 |
|
|---|
| 24 | if (end != str.c_str())
|
|---|
| 25 | {
|
|---|
| 26 | if (idx)
|
|---|
| 27 | *idx = static_cast<size_t>(end - str.c_str());
|
|---|
| 28 | return result;
|
|---|
| 29 | }
|
|---|
| 30 | // TODO: no conversion -> invalid_argument
|
|---|
| 31 | // TODO: ERANGE in errno -> out_of_range
|
|---|
| 32 | return 0;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | unsigned long stoul(const string& str, size_t* idx, int base)
|
|---|
| 36 | {
|
|---|
| 37 | char* end;
|
|---|
| 38 | unsigned long result = ::strtoul(str.c_str(), &end, base);
|
|---|
| 39 |
|
|---|
| 40 | if (end != str.c_str())
|
|---|
| 41 | {
|
|---|
| 42 | if (idx)
|
|---|
| 43 | *idx = static_cast<size_t>(end - str.c_str());
|
|---|
| 44 | return result;
|
|---|
| 45 | }
|
|---|
| 46 | // TODO: no conversion -> invalid_argument
|
|---|
| 47 | // TODO: ERANGE in errno -> out_of_range
|
|---|
| 48 | return 0;
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | long long stoll(const string& str, size_t* idx, int base)
|
|---|
| 52 | {
|
|---|
| 53 | // TODO: implement using stol once we have numeric limits
|
|---|
| 54 | __unimplemented();
|
|---|
| 55 | return 0;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | unsigned long long stoull(const string& str, size_t* idx, int base)
|
|---|
| 59 | {
|
|---|
| 60 | // TODO: implement using stoul once we have numeric limits
|
|---|
| 61 | __unimplemented();
|
|---|
| 62 | return 0;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | float stof(const string& str, size_t* idx)
|
|---|
| 66 | {
|
|---|
| 67 | // TODO: implement
|
|---|
| 68 | __unimplemented();
|
|---|
| 69 | return 0.f;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | double stod(const string& str, size_t* idx)
|
|---|
| 73 | {
|
|---|
| 74 | // TODO: implement
|
|---|
| 75 | __unimplemented();
|
|---|
| 76 | return 0.0;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | long double stold(const string& str, size_t* idx)
|
|---|
| 80 | {
|
|---|
| 81 | // TODO: implement
|
|---|
| 82 | __unimplemented();
|
|---|
| 83 | return 0.0l;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | string to_string(int val)
|
|---|
| 87 | {
|
|---|
| 88 | char* tmp;
|
|---|
| 89 | ::asprintf(&tmp, "%d", val);
|
|---|
| 90 |
|
|---|
| 91 | std::string res{tmp};
|
|---|
| 92 | free(tmp);
|
|---|
| 93 |
|
|---|
| 94 | return res;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | string to_string(unsigned val)
|
|---|
| 98 | {
|
|---|
| 99 | char* tmp;
|
|---|
| 100 | ::asprintf(&tmp, "%u", val);
|
|---|
| 101 |
|
|---|
| 102 | std::string res{tmp};
|
|---|
| 103 | free(tmp);
|
|---|
| 104 |
|
|---|
| 105 | return res;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | string to_string(long val)
|
|---|
| 109 | {
|
|---|
| 110 | char* tmp;
|
|---|
| 111 | ::asprintf(&tmp, "%ld", val);
|
|---|
| 112 |
|
|---|
| 113 | std::string res{tmp};
|
|---|
| 114 | free(tmp);
|
|---|
| 115 |
|
|---|
| 116 | return res;
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | string to_string(unsigned long val)
|
|---|
| 120 | {
|
|---|
| 121 | char* tmp;
|
|---|
| 122 | ::asprintf(&tmp, "%lu", val);
|
|---|
| 123 |
|
|---|
| 124 | std::string res{tmp};
|
|---|
| 125 | free(tmp);
|
|---|
| 126 |
|
|---|
| 127 | return res;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | string to_string(long long val)
|
|---|
| 131 | {
|
|---|
| 132 | char* tmp;
|
|---|
| 133 | ::asprintf(&tmp, "%lld", val);
|
|---|
| 134 |
|
|---|
| 135 | std::string res{tmp};
|
|---|
| 136 | free(tmp);
|
|---|
| 137 |
|
|---|
| 138 | return res;
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | string to_string(unsigned long long val)
|
|---|
| 142 | {
|
|---|
| 143 | char* tmp;
|
|---|
| 144 | ::asprintf(&tmp, "%llu", val);
|
|---|
| 145 |
|
|---|
| 146 | std::string res{tmp};
|
|---|
| 147 | free(tmp);
|
|---|
| 148 |
|
|---|
| 149 | return res;
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | string to_string(float val)
|
|---|
| 153 | {
|
|---|
| 154 | char* tmp;
|
|---|
| 155 | ::asprintf(&tmp, "%f", val);
|
|---|
| 156 |
|
|---|
| 157 | std::string res{tmp};
|
|---|
| 158 | free(tmp);
|
|---|
| 159 |
|
|---|
| 160 | return res;
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | string to_string(double val)
|
|---|
| 164 | {
|
|---|
| 165 | char* tmp;
|
|---|
| 166 | ::asprintf(&tmp, "%f", val);
|
|---|
| 167 |
|
|---|
| 168 | std::string res{tmp};
|
|---|
| 169 | free(tmp);
|
|---|
| 170 |
|
|---|
| 171 | return res;
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | string to_string(long double val)
|
|---|
| 175 | {
|
|---|
| 176 | char* tmp;
|
|---|
| 177 | ::asprintf(&tmp, "%Lf", val);
|
|---|
| 178 |
|
|---|
| 179 | std::string res{tmp};
|
|---|
| 180 | free(tmp);
|
|---|
| 181 |
|
|---|
| 182 | return res;
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | int stoi(const wstring& str, size_t* idx, int base)
|
|---|
| 186 | {
|
|---|
| 187 | // TODO: implement
|
|---|
| 188 | __unimplemented();
|
|---|
| 189 | return 0;
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | long stol(const wstring& str, size_t* idx, int base)
|
|---|
| 193 | {
|
|---|
| 194 | // TODO: implement
|
|---|
| 195 | __unimplemented();
|
|---|
| 196 | return 0;
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | unsigned long stoul(const wstring& str, size_t* idx, int base)
|
|---|
| 200 | {
|
|---|
| 201 | // TODO: implement
|
|---|
| 202 | __unimplemented();
|
|---|
| 203 | return 0;
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | long long stoll(const wstring& str, size_t* idx, int base)
|
|---|
| 207 | {
|
|---|
| 208 | // TODO: implement
|
|---|
| 209 | __unimplemented();
|
|---|
| 210 | return 0;
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | unsigned long long stoull(const wstring& str, size_t* idx, int base)
|
|---|
| 214 | {
|
|---|
| 215 | // TODO: implement
|
|---|
| 216 | __unimplemented();
|
|---|
| 217 | return 0;
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | float stof(const wstring& str, size_t* idx)
|
|---|
| 221 | {
|
|---|
| 222 | // TODO: implement
|
|---|
| 223 | __unimplemented();
|
|---|
| 224 | return 0.f;
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | double stod(const wstring& str, size_t* idx)
|
|---|
| 228 | {
|
|---|
| 229 | // TODO: implement
|
|---|
| 230 | __unimplemented();
|
|---|
| 231 | return 0.0;
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | long double stold(const wstring& str, size_t* idx)
|
|---|
| 235 | {
|
|---|
| 236 | // TODO: implement
|
|---|
| 237 | __unimplemented();
|
|---|
| 238 | return 0.0l;
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | wstring to_wstring(int val)
|
|---|
| 242 | {
|
|---|
| 243 | // TODO: implement
|
|---|
| 244 | __unimplemented();
|
|---|
| 245 | return wstring{};
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | wstring to_wstring(unsigned val)
|
|---|
| 249 | {
|
|---|
| 250 | // TODO: implement
|
|---|
| 251 | __unimplemented();
|
|---|
| 252 | return wstring{};
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | wstring to_wstring(long val)
|
|---|
| 256 | {
|
|---|
| 257 | // TODO: implement
|
|---|
| 258 | __unimplemented();
|
|---|
| 259 | return wstring{};
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 | wstring to_wstring(unsigned long val)
|
|---|
| 263 | {
|
|---|
| 264 | // TODO: implement
|
|---|
| 265 | __unimplemented();
|
|---|
| 266 | return wstring{};
|
|---|
| 267 | }
|
|---|
| 268 |
|
|---|
| 269 | wstring to_wstring(long long val)
|
|---|
| 270 | {
|
|---|
| 271 | // TODO: implement
|
|---|
| 272 | __unimplemented();
|
|---|
| 273 | return wstring{};
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | wstring to_wstring(unsigned long long val)
|
|---|
| 277 | {
|
|---|
| 278 | // TODO: implement
|
|---|
| 279 | __unimplemented();
|
|---|
| 280 | return wstring{};
|
|---|
| 281 | }
|
|---|
| 282 |
|
|---|
| 283 | wstring to_wstring(float val)
|
|---|
| 284 | {
|
|---|
| 285 | // TODO: implement
|
|---|
| 286 | __unimplemented();
|
|---|
| 287 | return wstring{};
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | wstring to_wstring(double val)
|
|---|
| 291 | {
|
|---|
| 292 | // TODO: implement
|
|---|
| 293 | __unimplemented();
|
|---|
| 294 | return wstring{};
|
|---|
| 295 | }
|
|---|
| 296 |
|
|---|
| 297 | wstring to_wstring(long double val)
|
|---|
| 298 | {
|
|---|
| 299 | // TODO: implement
|
|---|
| 300 | __unimplemented();
|
|---|
| 301 | return wstring{};
|
|---|
| 302 | }
|
|---|
| 303 |
|
|---|
| 304 | /**
|
|---|
| 305 | * 21.7, suffix for basic_string literals:
|
|---|
| 306 | */
|
|---|
| 307 |
|
|---|
| 308 | /**
|
|---|
| 309 | * Note: According to the standard, literal suffixes that do not
|
|---|
| 310 | * start with an underscore are reserved for future standardization,
|
|---|
| 311 | * but since we are implementing the standard, we're going to ignore it.
|
|---|
| 312 | * This should work (according to their documentation) work for clang,
|
|---|
| 313 | * but that should be tested.
|
|---|
| 314 | */
|
|---|
| 315 | #pragma GCC diagnostic push
|
|---|
| 316 | #pragma GCC diagnostic ignored "-Wliteral-suffix"
|
|---|
| 317 | inline namespace literals {
|
|---|
| 318 | inline namespace string_literals
|
|---|
| 319 | {
|
|---|
| 320 | string operator "" s(const char* str, size_t len)
|
|---|
| 321 | {
|
|---|
| 322 | return string{str, len};
|
|---|
| 323 | }
|
|---|
| 324 |
|
|---|
| 325 | u16string operator "" s(const char16_t* str, size_t len)
|
|---|
| 326 | {
|
|---|
| 327 | return u16string{str, len};
|
|---|
| 328 | }
|
|---|
| 329 |
|
|---|
| 330 | u32string operator "" s(const char32_t* str, size_t len)
|
|---|
| 331 | {
|
|---|
| 332 | return u32string{str, len};
|
|---|
| 333 | }
|
|---|
| 334 |
|
|---|
| 335 | /* Problem: wchar_t == int in HelenOS, but standard forbids it.
|
|---|
| 336 | wstring operator "" s(const wchar_t* str, size_t len)
|
|---|
| 337 | {
|
|---|
| 338 | return wstring{str, len};
|
|---|
| 339 | }
|
|---|
| 340 | */
|
|---|
| 341 | }}
|
|---|
| 342 | #pragma GCC diagnostic pop
|
|---|
| 343 | }
|
|---|