Changeset 101346 in vbox for trunk/src/VBox/Runtime/common/string/ministring.cpp
- Timestamp:
- Oct 4, 2023 11:33:39 PM (17 months ago)
- svn:sync-xref-src-repo-rev:
- 159347
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/ministring.cpp
r101343 r101346 1017 1017 } 1018 1018 1019 bool RTCString::endsWith(const RTCString &that, CaseSensitivity cs /*= CaseSensitive*/) const RT_NOEXCEPT 1020 { 1021 size_t l1 = length(); 1022 if (l1 == 0) 1023 return false; 1024 1025 size_t l2 = that.length(); 1026 if (l1 < l2) 1027 return false; 1028 1029 if (!m_psz) /* Don't crash when running against an empty string. */ 1030 return false; 1031 1032 /** @todo r=bird: See handling of l2 == in startsWith; inconsistent output (if l2 == 0, it matches anything). */ 1033 1034 size_t l = l1 - l2; 1035 if (cs == CaseSensitive) 1036 return ::RTStrCmp(&m_psz[l], that.m_psz) == 0; 1037 return ::RTStrICmp(&m_psz[l], that.m_psz) == 0; 1019 bool RTCString::endsWith(const RTCString &a_rThat) const RT_NOEXCEPT 1020 { 1021 size_t const cchThis = length(); 1022 size_t const cchThat = a_rThat.length(); 1023 if ( cchThat > 0 1024 && cchThat <= cchThis) 1025 return ::memcmp(&m_psz[cchThis - cchThat], a_rThat.m_psz, cchThat) == 0; 1026 return false; 1027 } 1028 1029 bool RTCString::endsWithI(const RTCString &a_rThat) const RT_NOEXCEPT 1030 { 1031 size_t const cchThis = length(); 1032 size_t const cchThat = a_rThat.length(); 1033 if ( cchThat > 0 1034 && cchThat <= cchThis) 1035 return ::RTStrICmp(&m_psz[cchThis - cchThat], a_rThat.m_psz) == 0; 1036 return false; 1038 1037 } 1039 1038 … … 1048 1047 bool RTCString::endsWith(const char *a_pszSuffix) const RT_NOEXCEPT 1049 1048 { 1050 return endsWith(a_pszSuffix, strlen(a_pszSuffix)); 1049 if (a_pszSuffix) 1050 return endsWith(a_pszSuffix, strlen(a_pszSuffix)); 1051 return false; 1051 1052 } 1052 1053 … … 1061 1062 bool RTCString::endsWithI(const char *a_pszSuffix) const RT_NOEXCEPT 1062 1063 { 1063 return endsWithI(a_pszSuffix, strlen(a_pszSuffix)); 1064 } 1065 1066 bool RTCString::startsWith(const RTCString &that, CaseSensitivity cs /*= CaseSensitive*/) const RT_NOEXCEPT 1067 { 1068 size_t l1 = length(); 1069 size_t l2 = that.length(); 1070 if (l1 == 0 || l2 == 0) /** @todo r=bird: this differs from endsWith, and I think other IPRT code. If l2 == 0, it matches anything. */ 1071 return false; 1072 1073 if (l1 < l2) 1074 return false; 1075 1076 if (cs == CaseSensitive) 1077 return ::RTStrNCmp(m_psz, that.m_psz, l2) == 0; 1078 return ::RTStrNICmp(m_psz, that.m_psz, l2) == 0; 1064 if (a_pszSuffix) 1065 return endsWithI(a_pszSuffix, strlen(a_pszSuffix)); 1066 return false; 1067 } 1068 1069 bool RTCString::startsWith(const RTCString &a_rThat) const RT_NOEXCEPT 1070 { 1071 size_t const cchThis = length(); 1072 size_t const cchThat = a_rThat.length(); 1073 if ( cchThat > 0 1074 && cchThat <= cchThis) 1075 return ::memcmp(m_psz, a_rThat.m_psz, cchThat) == 0; 1076 return false; 1077 } 1078 1079 bool RTCString::startsWithI(const RTCString &a_rThat) const RT_NOEXCEPT 1080 { 1081 size_t const cchThis = length(); 1082 size_t const cchThat = a_rThat.length(); 1083 if ( cchThat > 0 1084 && cchThat <= cchThis) 1085 return ::RTStrNICmp(m_psz, a_rThat.m_psz, cchThat) == 0; 1086 return false; 1087 } 1088 1089 bool RTCString::startsWith(const char *a_pszPrefix, size_t a_cchPrefix) const RT_NOEXCEPT 1090 { 1091 Assert(RTStrNLen(a_pszPrefix, a_cchPrefix) == a_cchPrefix); 1092 return a_cchPrefix > 0 1093 && a_cchPrefix <= length() 1094 && ::memcmp(m_psz, a_pszPrefix, a_cchPrefix) == 0; 1095 } 1096 1097 bool RTCString::startsWith(const char *a_pszPrefix) const RT_NOEXCEPT 1098 { 1099 if (a_pszPrefix) 1100 return startsWith(a_pszPrefix, strlen(a_pszPrefix)); 1101 return false; 1102 } 1103 1104 bool RTCString::startsWithI(const char *a_pszPrefix, size_t a_cchPrefix) const RT_NOEXCEPT 1105 { 1106 Assert(RTStrNLen(a_pszPrefix, a_cchPrefix) == a_cchPrefix); 1107 return a_cchPrefix > 0 1108 && a_cchPrefix <= length() 1109 && ::RTStrNICmp(m_psz, a_pszPrefix, a_cchPrefix) == 0; 1110 } 1111 1112 bool RTCString::startsWithI(const char *a_pszPrefix) const RT_NOEXCEPT 1113 { 1114 if (a_pszPrefix) 1115 return startsWithI(a_pszPrefix, strlen(a_pszPrefix)); 1116 return false; 1079 1117 } 1080 1118
Note:
See TracChangeset
for help on using the changeset viewer.