diff options
Diffstat (limited to 'base/strings.cpp')
-rw-r--r-- | base/strings.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/base/strings.cpp b/base/strings.cpp index bfdaf1244..a8bb2a986 100644 --- a/base/strings.cpp +++ b/base/strings.cpp | |||
@@ -91,12 +91,20 @@ bool StartsWith(const std::string& s, const char* prefix) { | |||
91 | return strncmp(s.c_str(), prefix, strlen(prefix)) == 0; | 91 | return strncmp(s.c_str(), prefix, strlen(prefix)) == 0; |
92 | } | 92 | } |
93 | 93 | ||
94 | bool StartsWith(const std::string& s, const std::string& prefix) { | ||
95 | return strncmp(s.c_str(), prefix.c_str(), prefix.size()) == 0; | ||
96 | } | ||
97 | |||
94 | bool StartsWithIgnoreCase(const std::string& s, const char* prefix) { | 98 | bool StartsWithIgnoreCase(const std::string& s, const char* prefix) { |
95 | return strncasecmp(s.c_str(), prefix, strlen(prefix)) == 0; | 99 | return strncasecmp(s.c_str(), prefix, strlen(prefix)) == 0; |
96 | } | 100 | } |
97 | 101 | ||
98 | static bool EndsWith(const std::string& s, const char* suffix, bool case_sensitive) { | 102 | bool StartsWithIgnoreCase(const std::string& s, const std::string& prefix) { |
99 | size_t suffix_length = strlen(suffix); | 103 | return strncasecmp(s.c_str(), prefix.c_str(), prefix.size()) == 0; |
104 | } | ||
105 | |||
106 | static bool EndsWith(const std::string& s, const char* suffix, size_t suffix_length, | ||
107 | bool case_sensitive) { | ||
100 | size_t string_length = s.size(); | 108 | size_t string_length = s.size(); |
101 | if (suffix_length > string_length) { | 109 | if (suffix_length > string_length) { |
102 | return false; | 110 | return false; |
@@ -106,11 +114,19 @@ static bool EndsWith(const std::string& s, const char* suffix, bool case_sensiti | |||
106 | } | 114 | } |
107 | 115 | ||
108 | bool EndsWith(const std::string& s, const char* suffix) { | 116 | bool EndsWith(const std::string& s, const char* suffix) { |
109 | return EndsWith(s, suffix, true); | 117 | return EndsWith(s, suffix, strlen(suffix), true); |
118 | } | ||
119 | |||
120 | bool EndsWith(const std::string& s, const std::string& suffix) { | ||
121 | return EndsWith(s, suffix.c_str(), suffix.size(), true); | ||
110 | } | 122 | } |
111 | 123 | ||
112 | bool EndsWithIgnoreCase(const std::string& s, const char* suffix) { | 124 | bool EndsWithIgnoreCase(const std::string& s, const char* suffix) { |
113 | return EndsWith(s, suffix, false); | 125 | return EndsWith(s, suffix, strlen(suffix), false); |
126 | } | ||
127 | |||
128 | bool EndsWithIgnoreCase(const std::string& s, const std::string& suffix) { | ||
129 | return EndsWith(s, suffix.c_str(), suffix.size(), false); | ||
114 | } | 130 | } |
115 | 131 | ||
116 | bool EqualsIgnoreCase(const std::string& lhs, const std::string& rhs) { | 132 | bool EqualsIgnoreCase(const std::string& lhs, const std::string& rhs) { |