| 1 | /*
|
|---|
| 2 | * Copyright (c) 2018 Jaroslav Jindrak
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | #include <string>
|
|---|
| 30 |
|
|---|
| 31 | namespace std
|
|---|
| 32 | {
|
|---|
| 33 | int stoi(const string& str, size_t* idx, int base)
|
|---|
| 34 | {
|
|---|
| 35 | // TODO: implement using stol once we have numeric limits
|
|---|
| 36 | return 0;
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | long stol(const string& str, size_t* idx, int base)
|
|---|
| 40 | {
|
|---|
| 41 | char* end;
|
|---|
| 42 | long result = hel::strtol(str.c_str(), &end, base);
|
|---|
| 43 |
|
|---|
| 44 | if (end != str.c_str())
|
|---|
| 45 | {
|
|---|
| 46 | if (idx)
|
|---|
| 47 | *idx = static_cast<size_t>(end - str.c_str());
|
|---|
| 48 | return result;
|
|---|
| 49 | }
|
|---|
| 50 | // TODO: no conversion -> invalid_argument
|
|---|
| 51 | // TODO: ERANGE in errno -> out_of_range
|
|---|
| 52 | return 0;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | unsigned long stoul(const string& str, size_t* idx, int base)
|
|---|
| 56 | {
|
|---|
| 57 | char* end;
|
|---|
| 58 | unsigned long result = hel::strtoul(str.c_str(), &end, base);
|
|---|
| 59 |
|
|---|
| 60 | if (end != str.c_str())
|
|---|
| 61 | {
|
|---|
| 62 | if (idx)
|
|---|
| 63 | *idx = static_cast<size_t>(end - str.c_str());
|
|---|
| 64 | return result;
|
|---|
| 65 | }
|
|---|
| 66 | // TODO: no conversion -> invalid_argument
|
|---|
| 67 | // TODO: ERANGE in errno -> out_of_range
|
|---|
| 68 | return 0;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | long long stoll(const string& str, size_t* idx, int base)
|
|---|
| 72 | {
|
|---|
| 73 | // TODO: implement using stol once we have numeric limits
|
|---|
| 74 | return 0;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | unsigned long long stoull(const string& str, size_t* idx, int base)
|
|---|
| 78 | {
|
|---|
| 79 | // TODO: implement using stoul once we have numeric limits
|
|---|
| 80 | return 0;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | float stof(const string& str, size_t* idx)
|
|---|
| 84 | {
|
|---|
| 85 | // TODO: implement
|
|---|
| 86 | return 0.f;
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | double stod(const string& str, size_t* idx)
|
|---|
| 90 | {
|
|---|
| 91 | // TODO: implement
|
|---|
| 92 | return 0.0;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | long double stold(const string& str, size_t* idx)
|
|---|
| 96 | {
|
|---|
| 97 | // TODO: implement
|
|---|
| 98 | return 0.0l;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | namespace hel
|
|---|
| 102 | {
|
|---|
| 103 | extern "C" int asprintf(char**, const char*, ...);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | string to_string(int val)
|
|---|
| 107 | {
|
|---|
| 108 | char* tmp;
|
|---|
| 109 | hel::asprintf(&tmp, "%d", val);
|
|---|
| 110 |
|
|---|
| 111 | std::string res{tmp};
|
|---|
| 112 | free(tmp);
|
|---|
| 113 |
|
|---|
| 114 | return res;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | string to_string(unsigned val)
|
|---|
| 118 | {
|
|---|
| 119 | char* tmp;
|
|---|
| 120 | hel::asprintf(&tmp, "%u", val);
|
|---|
| 121 |
|
|---|
| 122 | std::string res{tmp};
|
|---|
| 123 | free(tmp);
|
|---|
| 124 |
|
|---|
| 125 | return res;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | string to_string(long val)
|
|---|
| 129 | {
|
|---|
| 130 | char* tmp;
|
|---|
| 131 | hel::asprintf(&tmp, "%ld", val);
|
|---|
| 132 |
|
|---|
| 133 | std::string res{tmp};
|
|---|
| 134 | free(tmp);
|
|---|
| 135 |
|
|---|
| 136 | return res;
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | string to_string(unsigned long val)
|
|---|
| 140 | {
|
|---|
| 141 | char* tmp;
|
|---|
| 142 | hel::asprintf(&tmp, "%lu", val);
|
|---|
| 143 |
|
|---|
| 144 | std::string res{tmp};
|
|---|
| 145 | free(tmp);
|
|---|
| 146 |
|
|---|
| 147 | return res;
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | string to_string(long long val)
|
|---|
| 151 | {
|
|---|
| 152 | char* tmp;
|
|---|
| 153 | hel::asprintf(&tmp, "%lld", val);
|
|---|
| 154 |
|
|---|
| 155 | std::string res{tmp};
|
|---|
| 156 | free(tmp);
|
|---|
| 157 |
|
|---|
| 158 | return res;
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | string to_string(unsigned long long val)
|
|---|
| 162 | {
|
|---|
| 163 | char* tmp;
|
|---|
| 164 | hel::asprintf(&tmp, "%llu", val);
|
|---|
| 165 |
|
|---|
| 166 | std::string res{tmp};
|
|---|
| 167 | free(tmp);
|
|---|
| 168 |
|
|---|
| 169 | return res;
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | string to_string(float val)
|
|---|
| 173 | {
|
|---|
| 174 | char* tmp;
|
|---|
| 175 | hel::asprintf(&tmp, "%f", val);
|
|---|
| 176 |
|
|---|
| 177 | std::string res{tmp};
|
|---|
| 178 | free(tmp);
|
|---|
| 179 |
|
|---|
| 180 | return res;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | string to_string(double val)
|
|---|
| 184 | {
|
|---|
| 185 | char* tmp;
|
|---|
| 186 | hel::asprintf(&tmp, "%f", val);
|
|---|
| 187 |
|
|---|
| 188 | std::string res{tmp};
|
|---|
| 189 | free(tmp);
|
|---|
| 190 |
|
|---|
| 191 | return res;
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | string to_string(long double val)
|
|---|
| 195 | {
|
|---|
| 196 | char* tmp;
|
|---|
| 197 | hel::asprintf(&tmp, "%Lf", val);
|
|---|
| 198 |
|
|---|
| 199 | std::string res{tmp};
|
|---|
| 200 | free(tmp);
|
|---|
| 201 |
|
|---|
| 202 | return res;
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | int stoi(const wstring& str, size_t* idx, int base)
|
|---|
| 206 | {
|
|---|
| 207 | // TODO: implement
|
|---|
| 208 | return 0;
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | long stol(const wstring& str, size_t* idx, int base)
|
|---|
| 212 | {
|
|---|
| 213 | // TODO: implement
|
|---|
| 214 | return 0;
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | unsigned long stoul(const wstring& str, size_t* idx, int base)
|
|---|
| 218 | {
|
|---|
| 219 | // TODO: implement
|
|---|
| 220 | return 0;
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | long long stoll(const wstring& str, size_t* idx, int base)
|
|---|
| 224 | {
|
|---|
| 225 | // TODO: implement
|
|---|
| 226 | return 0;
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | unsigned long long stoull(const wstring& str, size_t* idx, int base)
|
|---|
| 230 | {
|
|---|
| 231 | // TODO: implement
|
|---|
| 232 | return 0;
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | float stof(const wstring& str, size_t* idx)
|
|---|
| 236 | {
|
|---|
| 237 | // TODO: implement
|
|---|
| 238 | return 0.f;
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | double stod(const wstring& str, size_t* idx)
|
|---|
| 242 | {
|
|---|
| 243 | // TODO: implement
|
|---|
| 244 | return 0.0;
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | long double stold(const wstring& str, size_t* idx)
|
|---|
| 248 | {
|
|---|
| 249 | // TODO: implement
|
|---|
| 250 | return 0.0l;
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | wstring to_wstring(int val)
|
|---|
| 254 | {
|
|---|
| 255 | // TODO: implement
|
|---|
| 256 | return wstring{};
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| 259 | wstring to_wstring(unsigned val)
|
|---|
| 260 | {
|
|---|
| 261 | // TODO: implement
|
|---|
| 262 | return wstring{};
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 | wstring to_wstring(long val)
|
|---|
| 266 | {
|
|---|
| 267 | // TODO: implement
|
|---|
| 268 | return wstring{};
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| 271 | wstring to_wstring(unsigned long val)
|
|---|
| 272 | {
|
|---|
| 273 | // TODO: implement
|
|---|
| 274 | return wstring{};
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | wstring to_wstring(long long val)
|
|---|
| 278 | {
|
|---|
| 279 | // TODO: implement
|
|---|
| 280 | return wstring{};
|
|---|
| 281 | }
|
|---|
| 282 |
|
|---|
| 283 | wstring to_wstring(unsigned long long val)
|
|---|
| 284 | {
|
|---|
| 285 | // TODO: implement
|
|---|
| 286 | return wstring{};
|
|---|
| 287 | }
|
|---|
| 288 |
|
|---|
| 289 | wstring to_wstring(float val)
|
|---|
| 290 | {
|
|---|
| 291 | // TODO: implement
|
|---|
| 292 | return wstring{};
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | wstring to_wstring(double val)
|
|---|
| 296 | {
|
|---|
| 297 | // TODO: implement
|
|---|
| 298 | return wstring{};
|
|---|
| 299 | }
|
|---|
| 300 |
|
|---|
| 301 | wstring to_wstring(long double val)
|
|---|
| 302 | {
|
|---|
| 303 | // TODO: implement
|
|---|
| 304 | return wstring{};
|
|---|
| 305 | }
|
|---|
| 306 |
|
|---|
| 307 | /**
|
|---|
| 308 | * 21.7, suffix for basic_string literals:
|
|---|
| 309 | */
|
|---|
| 310 |
|
|---|
| 311 | /**
|
|---|
| 312 | * Note: According to the standard, literal suffixes that do not
|
|---|
| 313 | * start with an underscore are reserved for future standardization,
|
|---|
| 314 | * but since we are implementing the standard, we're going to ignore it.
|
|---|
| 315 | * This should work (according to their documentation) work for clang,
|
|---|
| 316 | * but that should be tested.
|
|---|
| 317 | */
|
|---|
| 318 | #pragma GCC diagnostic push
|
|---|
| 319 | #pragma GCC diagnostic ignored "-Wliteral-suffix"
|
|---|
| 320 | inline namespace literals {
|
|---|
| 321 | inline namespace string_literals
|
|---|
| 322 | {
|
|---|
| 323 | string operator "" s(const char* str, size_t len)
|
|---|
| 324 | {
|
|---|
| 325 | return string{str, len};
|
|---|
| 326 | }
|
|---|
| 327 |
|
|---|
| 328 | u16string operator "" s(const char16_t* str, size_t len)
|
|---|
| 329 | {
|
|---|
| 330 | return u16string{str, len};
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 | u32string operator "" s(const char32_t* str, size_t len)
|
|---|
| 334 | {
|
|---|
| 335 | return u32string{str, len};
|
|---|
| 336 | }
|
|---|
| 337 |
|
|---|
| 338 | /* Problem: wchar_t == int in HelenOS, but standard forbids it.
|
|---|
| 339 | wstring operator "" s(const wchar_t* str, size_t len)
|
|---|
| 340 | {
|
|---|
| 341 | return wstring{str, len};
|
|---|
| 342 | }
|
|---|
| 343 | */
|
|---|
| 344 | }}
|
|---|
| 345 | #pragma GCC diagnostic pop
|
|---|
| 346 | }
|
|---|