fixed bugs in string::begih_with

This commit is contained in:
zsx 2018-09-08 21:33:44 +08:00
parent ac3bcf1f98
commit f1737e7a92
2 changed files with 10 additions and 6 deletions

View File

@ -58,6 +58,13 @@ static void test(void)
} else {
printf("error\r\n");
}
disk = "/data2/www";
if (path.begin_with(disk)) {
printf("error\r\n");
} else {
printf("ok\r\n");
}
}
static void usage(const char* procname)

View File

@ -893,18 +893,15 @@ bool string::equal(const string& s, bool case_sensitive /* = true */) const
bool string::begin_with(const char* s, bool case_sensitive /* = true */) const
{
return ncompare(s, case_sensitive) == 0 ? true : false;
return ncompare(s, strlen(s), case_sensitive) == 0 ? true : false;
}
bool string::begin_with(const void* v, size_t n) const
{
if (LEN(vbf_) == 0) {
if (n == 0)
return true;
if (n == 0)
return false;
}
if (n > LEN(vbf_))
n = LEN(vbf_);
return false;
return memcmp(STR(vbf_), v, n) == 0 ? true : false;
}