microsoft/onnxruntime-extensions
Publicmirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable
base/ustring.cc
69lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | #include "ustring.h" |
| 4 | #include <iostream> |
| 5 | |
| 6 | |
| 7 | ustring::ustring() : std::u32string() { |
| 8 | } |
| 9 | |
| 10 | ustring::ustring(char* str) { |
| 11 | utf8_converter str_cvt; |
| 12 | assign(str_cvt.from_bytes(str)); |
| 13 | } |
| 14 | |
| 15 | ustring::ustring(const char* str) { |
| 16 | utf8_converter str_cvt; |
| 17 | assign(str_cvt.from_bytes(str)); |
| 18 | } |
| 19 | |
| 20 | ustring::ustring(std::string& str) { |
| 21 | utf8_converter str_cvt; |
| 22 | assign(str_cvt.from_bytes(str)); |
| 23 | } |
| 24 | |
| 25 | ustring::ustring(const std::string& str) { |
| 26 | utf8_converter str_cvt; |
| 27 | assign(str_cvt.from_bytes(str)); |
| 28 | } |
| 29 | |
| 30 | ustring::ustring(char32_t* str) : std::u32string(str) {} |
| 31 | |
| 32 | ustring::ustring(const char32_t* str) : std::u32string(str) {} |
| 33 | |
| 34 | ustring::ustring(std::u32string& str) : std::u32string(str) {} |
| 35 | |
| 36 | ustring::ustring(std::u32string&& str) : std::u32string(str) {} |
| 37 | |
| 38 | ustring::ustring(const std::u32string& str) : std::u32string(str) {} |
| 39 | |
| 40 | ustring::ustring(const std::u32string&& str) : std::u32string(str) {} |
| 41 | |
| 42 | ustring::ustring(std::string_view& str) { |
| 43 | utf8_converter str_cvt; |
| 44 | assign(str_cvt.from_bytes(str.data(), str.data() + str.size())); |
| 45 | } |
| 46 | |
| 47 | ustring::ustring(const std::string_view& str) { |
| 48 | utf8_converter str_cvt; |
| 49 | assign(str_cvt.from_bytes(str.data(), str.data() + str.size())); |
| 50 | } |
| 51 | |
| 52 | ustring::ustring(std::u32string_view& str):std::u32string(str) {} |
| 53 | |
| 54 | ustring::ustring(std::u32string_view&& str):std::u32string(str) {} |
| 55 | |
| 56 | ustring::ustring(const std::u32string_view& str):std::u32string(str) {} |
| 57 | |
| 58 | ustring::ustring(const std::u32string_view&& str):std::u32string(str) {} |
| 59 | |
| 60 | ustring::operator std::string() { |
| 61 | utf8_converter str_cvt; |
| 62 | return str_cvt.to_bytes(*this); |
| 63 | } |
| 64 | |
| 65 | ustring::operator std::string() const { |
| 66 | utf8_converter str_cvt; |
| 67 | return str_cvt.to_bytes(*this); |
| 68 | } |
| 69 | |
| 70 | |