mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-30 02:47:56 +08:00
Add operator == for acl::string for comparing "ok" == acl::string.
This commit is contained in:
parent
8d175b2f02
commit
cad5d4c8d7
@ -1319,6 +1319,13 @@ private:
|
||||
void init(size_t len);
|
||||
};
|
||||
|
||||
/**
|
||||
* string s = "ok";
|
||||
* printf("first: %s\r\n", "ok" == s ? "true" : "false");
|
||||
*/
|
||||
bool operator==(const string* s,const string& str);
|
||||
bool operator==(const char* s,const string& str);
|
||||
|
||||
/**
|
||||
* 模板函数,可用在以下场景:
|
||||
* string s1, s2;
|
||||
|
@ -271,6 +271,17 @@ static void test7(void)
|
||||
ACL_METER_TIME(">> end ACL_VSTRING: acl_vstring_sprintf");
|
||||
}
|
||||
|
||||
static void test8(void)
|
||||
{
|
||||
acl::string s = "ok";
|
||||
acl::string s1 = "ok", *sp = &s1;
|
||||
|
||||
|
||||
printf("s==\"ok\" : %s, \"ok\"==s : %s\r\n",
|
||||
s == "ok" ? "yes" : "no", "ok" == s ? "yes" : "no");
|
||||
printf("sp=s : %s\r\n", sp == s ? "yes" : "no");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void test_main(void)
|
||||
@ -429,6 +440,9 @@ int main(void)
|
||||
{
|
||||
printf("%s\r\n", (*cit).c_str());
|
||||
}
|
||||
|
||||
test8();
|
||||
|
||||
#ifdef WIN32
|
||||
printf("enter any key to exit\r\n");
|
||||
getchar();
|
||||
|
@ -1952,4 +1952,14 @@ string& string::parse_int64(acl_uint64 n)
|
||||
return s;
|
||||
}
|
||||
|
||||
bool operator==(const string* s,const string& str)
|
||||
{
|
||||
return (str == s);
|
||||
}
|
||||
|
||||
bool operator==(const char* s,const string& str)
|
||||
{
|
||||
return (str == s);
|
||||
}
|
||||
|
||||
} // namespace acl
|
||||
|
Loading…
Reference in New Issue
Block a user