Core: std::[w]string Value and String support

git-svn-id: svn://ultimatepp.org/upp/trunk@15733 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2021-02-03 16:44:48 +00:00
parent d4d79b7ac6
commit ff78c94435
3 changed files with 17 additions and 3 deletions

View file

@ -402,6 +402,7 @@ public:
String(const std::string& s) { String0::Set0(s.c_str(), (int)s.length()); }
std::string ToStd() const { return std::string(Begin(), End()); }
operator std::string() const { return ToStd(); }
};
inline std::string to_string(const String& s) { return std::string(s.Begin(), s.End()); }
@ -846,7 +847,6 @@ public:
operator std::wstring() const;
std::wstring ToStd() const { return std::wstring(Begin(), End()); }
#endif
};
#ifndef _HAVE_NO_STDWSTRING
@ -936,6 +936,8 @@ template<> inline String AsString(const char& a) { return String(a, 1
template<> inline String AsString(const signed char& a) { return String(a, 1); }
template<> inline String AsString(const unsigned char& a) { return String(a, 1); }
template<> inline String AsString(const bool& a) { return a ? "true" : "false"; }
template<> inline String AsString(const std::string& s) { return String(s); }
template<> inline String AsString(const std::wstring& s) { return WString(s).ToString(); }
unsigned ctoi(int c);

View file

@ -223,6 +223,8 @@ public:
operator int() const { return Is(INT_V) ? GetSmallRaw<int>() : GetOtherInt(); }
operator int64() const { return Is(INT64_V) ? GetSmallRaw<int64>() : GetOtherInt64(); }
operator bool() const { return Is(BOOL_V) ? GetSmallRaw<bool>() : GetOtherBool(); }
operator std::string() const { return (String)*this; }
operator std::wstring() const { return (WString)*this; }
Value(const String& s) : data(s) { Magic(); }
Value(const WString& s);
@ -234,6 +236,8 @@ public:
Value(Date d) : data(d, DATE_V, String::SPECIAL) { Magic(); }
Value(Time t) : data(t, TIME_V, String::SPECIAL) { Magic(); }
Value(const Nuller&) : data((int)Null, INT_V, String::SPECIAL) { Magic(); }
Value(const std::string& s) : Value(String(s)) {}
Value(const std::wstring& s) : Value(WString(s)) {}
bool operator==(const Value& v) const;
bool operator!=(const Value& v) const { return !operator==(v); }

View file

@ -1,5 +1,4 @@
topic "Value";
[2 $$0,0#00000000000000000000000000000000:Default]
[i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class]
[l288;2 $$2,2#27521748481378242620020725143825:desc]
[0 $$3,0#96390100711032703541132217272105:end]
@ -9,6 +8,7 @@ topic "Value";
[l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param]
[i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam]
[b42;2 $$9,9#13035079074754324216151401829390:normal]
[2 $$0,0#00000000000000000000000000000000:Default]
[{_}%EN-US
[ {{10000@(113.42.0) [s0; [*@7;4 Value]]}}&]
[s1;@(0.0.255)3%- &]
@ -117,6 +117,10 @@ ValueArray or ValueMap (technical and performance reasons).&]
[s5;:Value`:`:operator int`(`)const:%- [* operator_int]()_[@(0.0.255) const]&]
[s5;:Value`:`:operator int64`(`)const:%- [* operator_int64]()_[@(0.0.255) const]&]
[s5;:Value`:`:operator bool`(`)const:%- [* operator_bool]()_[@(0.0.255) const]&]
[s5;:Upp`:`:Value`:`:operator std`:`:string`(`)const:%- [* operator_std`::string]()_[@(0.0.255) c
onst]&]
[s5;:Upp`:`:Value`:`:operator std`:`:wstring`(`)const:%- [* operator_std`::wstring]()_[@(0.0.255) c
onst]&]
[s5;:Value`:`:Value`(const String`&`):%- [* Value]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&
]_[*@3 s])&]
[s5;:Value`:`:Value`(const WString`&`):%- [* Value]([@(0.0.255) const]_[_^WString^ WString][@(0.0.255) `&
@ -129,6 +133,10 @@ ValueArray or ValueMap (technical and performance reasons).&]
[s5;:Value`:`:Value`(bool`):%- [* Value]([@(0.0.255) bool]_[*@3 b])&]
[s5;:Value`:`:Value`(Date`):%- [* Value]([_^Date^ Date]_[*@3 d])&]
[s5;:Value`:`:Value`(Time`):%- [* Value]([_^Time^ Time]_[*@3 t])&]
[s5;:Upp`:`:Value`:`:Value`(const std`:`:string`&`):%- [* Value]([@(0.0.255) const]_[_^std`:`:string^ s
td`::string][@(0.0.255) `&]_[*@3 s])&]
[s5;:Upp`:`:Value`:`:Value`(const std`:`:wstring`&`):%- [* Value]([@(0.0.255) const]_[_^std`:`:wstring^ s
td`::wstring][@(0.0.255) `&]_[*@3 s])&]
[s2; Support of direct T`->Value and Value`->T conversions of standard
Value types. If conversion is not possible, throws ValueTypeError.&]
[s3;%- &]
@ -137,7 +145,7 @@ Value types. If conversion is not possible, throws ValueTypeError.&]
])&]
[s2; Support for assignment from Null (e.g. Value v `= Null). Creates
Value containing (int)Null.&]
[s3;%- &]
[s3; &]
[s4;%- &]
[s5;:Value`:`:operator`=`=`(const Value`&`)const:%- [@(0.0.255) bool]_[* operator`=`=]([@(0.0.255) c
onst]_[_^Value^ Value][@(0.0.255) `&]_[*@3 v])_[@(0.0.255) const]&]