From f1737e7a92c04459557967d50f80f9f730b4992e Mon Sep 17 00:00:00 2001 From: zsx Date: Sat, 8 Sep 2018 21:33:44 +0800 Subject: [PATCH] fixed bugs in string::begih_with --- lib_acl_cpp/samples/string/string2/main.cpp | 7 +++++++ lib_acl_cpp/src/stdlib/string.cpp | 9 +++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib_acl_cpp/samples/string/string2/main.cpp b/lib_acl_cpp/samples/string/string2/main.cpp index 7ddafd589..b76b71266 100644 --- a/lib_acl_cpp/samples/string/string2/main.cpp +++ b/lib_acl_cpp/samples/string/string2/main.cpp @@ -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) diff --git a/lib_acl_cpp/src/stdlib/string.cpp b/lib_acl_cpp/src/stdlib/string.cpp index 516f60875..25ebe1ffe 100644 --- a/lib_acl_cpp/src/stdlib/string.cpp +++ b/lib_acl_cpp/src/stdlib/string.cpp @@ -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; }