Skip to content

Commit

Permalink
Deprecate SbStringCompareNoCase (#1981)
Browse files Browse the repository at this point in the history
b/305768669
  • Loading branch information
madhurajayaraman authored Nov 17, 2023
2 parents eebae19 + ef93e17 commit 5c77d54
Show file tree
Hide file tree
Showing 32 changed files with 68 additions and 63 deletions.
8 changes: 0 additions & 8 deletions base/strings/string_util_starboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@

namespace base {

inline int strcasecmp(const char* string1, const char* string2) {
return SbStringCompareNoCase(string1, string2);
}

inline int strncasecmp(const char* string1, const char* string2, size_t count) {
return SbStringCompareNoCaseN(string1, string2, count);
}

#if defined(vsnprintf)
#undef vsnprintf
#endif
Expand Down
2 changes: 1 addition & 1 deletion cobalt/browser/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const int64_t kWatchdogTimeInterval = 10000000;
const int64_t kWatchdogTimeWait = 2000000;

bool IsStringNone(const std::string& str) {
return !base::strcasecmp(str.c_str(), "none");
return !strcasecmp(str.c_str(), "none");
}

#if defined(ENABLE_WEBDRIVER) || defined(ENABLE_DEBUGGER)
Expand Down
7 changes: 3 additions & 4 deletions cobalt/csp/source_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool IsSourceListNone(const char* begin, const char* end) {
const char* position = begin;
SkipWhile<IsSourceCharacter>(&position, end);
size_t len = static_cast<size_t>(position - begin);
if (base::strncasecmp("'none'", begin, len) != 0) {
if (strncasecmp("'none'", begin, len) != 0) {
return false;
}

Expand Down Expand Up @@ -400,7 +400,7 @@ bool SourceList::ParseNonce(const char* begin, const char* end,
const char* prefix = "'nonce-";

if (nonce_length <= strlen(prefix) ||
base::strncasecmp(prefix, begin, strlen(prefix)) != 0) {
strncasecmp(prefix, begin, strlen(prefix)) != 0) {
return true;
}

Expand Down Expand Up @@ -433,8 +433,7 @@ bool SourceList::ParseHash(const char* begin, const char* end,
for (size_t i = 0; i < arraysize(kSupportedPrefixes); ++i) {
const HashPrefix& algorithm = kSupportedPrefixes[i];
if (hash_length > strlen(algorithm.prefix) &&
base::strncasecmp(algorithm.prefix, begin, strlen(algorithm.prefix)) ==
0) {
strncasecmp(algorithm.prefix, begin, strlen(algorithm.prefix)) == 0) {
prefix = algorithm.prefix;
*hash_algorithm = algorithm.type;
break;
Expand Down
6 changes: 3 additions & 3 deletions cobalt/debug/console/command_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ ConsoleCommandManager::CommandHandler::~CommandHandler() {
// static
bool ConsoleCommandManager::CommandHandler::IsOnEnableOrTrue(
const std::string& message) {
return (SbStringCompareNoCase("on", message.c_str()) == 0) ||
(SbStringCompareNoCase("enable", message.c_str()) == 0) ||
(SbStringCompareNoCase("true", message.c_str()) == 0);
return (strcasecmp("on", message.c_str()) == 0) ||
(strcasecmp("enable", message.c_str()) == 0) ||
(strcasecmp("true", message.c_str()) == 0);
}


Expand Down
24 changes: 12 additions & 12 deletions cobalt/dom/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,26 +235,26 @@ scoped_refptr<web::Event> Document::CreateEvent(
script::ExceptionState* exception_state) {
// https://www.w3.org/TR/dom/#dom-document-createevent
// The match of interface name is case-insensitive.
if (base::strcasecmp(interface_name.c_str(), "event") == 0 ||
base::strcasecmp(interface_name.c_str(), "events") == 0 ||
base::strcasecmp(interface_name.c_str(), "htmlevents") == 0) {
if (strcasecmp(interface_name.c_str(), "event") == 0 ||
strcasecmp(interface_name.c_str(), "events") == 0 ||
strcasecmp(interface_name.c_str(), "htmlevents") == 0) {
return new web::Event(web::Event::Uninitialized);
} else if (base::strcasecmp(interface_name.c_str(), "keyboardevent") == 0 ||
base::strcasecmp(interface_name.c_str(), "keyevents") == 0) {
} else if (strcasecmp(interface_name.c_str(), "keyboardevent") == 0 ||
strcasecmp(interface_name.c_str(), "keyevents") == 0) {
return new KeyboardEvent(web::Event::Uninitialized);
} else if (base::strcasecmp(interface_name.c_str(), "messageevent") == 0) {
} else if (strcasecmp(interface_name.c_str(), "messageevent") == 0) {
return new web::MessageEvent(web::Event::Uninitialized);
} else if (base::strcasecmp(interface_name.c_str(), "mouseevent") == 0 ||
base::strcasecmp(interface_name.c_str(), "mouseevents") == 0) {
} else if (strcasecmp(interface_name.c_str(), "mouseevent") == 0 ||
strcasecmp(interface_name.c_str(), "mouseevents") == 0) {
return new MouseEvent(web::Event::Uninitialized);
} else if (base::strcasecmp(interface_name.c_str(), "uievent") == 0 ||
base::strcasecmp(interface_name.c_str(), "uievents") == 0) {
} else if (strcasecmp(interface_name.c_str(), "uievent") == 0 ||
strcasecmp(interface_name.c_str(), "uievents") == 0) {
return new UIEvent(web::Event::Uninitialized);
} else if (base::strcasecmp(interface_name.c_str(), "wheelevent") == 0) {
} else if (strcasecmp(interface_name.c_str(), "wheelevent") == 0) {
// This not in the spec, but commonly implemented to create a WheelEvent.
// https://www.w3.org/TR/2016/WD-uievents-20160804/#interface-wheelevent
return new WheelEvent(web::Event::Uninitialized);
} else if (base::strcasecmp(interface_name.c_str(), "customevent") == 0) {
} else if (strcasecmp(interface_name.c_str(), "customevent") == 0) {
return new web::CustomEvent(web::Event::Uninitialized);
}

Expand Down
3 changes: 1 addition & 2 deletions cobalt/dom/on_screen_keyboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ bool ParseColor(const char* color_str, int& r, int& g, int& b) {
}

// Handle rgb color notation rgb(R, G, B)
if (!is_hex && len >= 10 &&
SbStringCompareNoCaseN("rgb(", color_str, 4) == 0) {
if (!is_hex && len >= 10 && strncasecmp("rgb(", color_str, 4) == 0) {
int rgb_tmp[3] = {-1, -1, -1};
const char* ptr = color_str + 4;
int i = 0;
Expand Down
13 changes: 6 additions & 7 deletions cobalt/loader/cors_preflight.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ bool IsInArray(const char* input_str, const char* array[], size_t size) {
return false;
}
for (size_t i = 0; i < size; ++i) {
if (SbStringCompareNoCase(input_str, array[i]) == 0) {
if (strcasecmp(input_str, array[i]) == 0) {
return true;
}
}
Expand All @@ -132,8 +132,7 @@ bool HasFieldValue(const std::vector<std::string>& field_values,
if (field_values[i].empty()) {
continue;
}
if (SbStringCompareNoCase(field_values[i].c_str(),
find_value_name.c_str()) == 0) {
if (strcasecmp(field_values[i].c_str(), find_value_name.c_str()) == 0) {
return true;
}
}
Expand Down Expand Up @@ -171,7 +170,7 @@ bool CORSPreflight::IsSafeRequestHeader(const std::string& name,

// Safe if header name is 'Content-Type' and value is a match of
// kAllowedMIMEType.
if (SbStringCompareNoCase(name.c_str(), kContentType) == 0) {
if (strcasecmp(name.c_str(), kContentType) == 0) {
std::vector<std::string> content_type_split = base::SplitString(
value, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
auto begin_iter = content_type_split[0].cbegin();
Expand Down Expand Up @@ -220,8 +219,8 @@ bool CORSPreflight::IsSafeResponseHeader(
}

for (size_t i = 0; i < CORS_exposed_header_name_list.size(); i++) {
if (SbStringCompareNoCase(CORS_exposed_header_name_list.at(i).c_str(),
name.c_str()) == 0) {
if (strcasecmp(CORS_exposed_header_name_list.at(i).c_str(), name.c_str()) ==
0) {
return true;
}
}
Expand Down Expand Up @@ -381,7 +380,7 @@ void CORSPreflight::OnURLFetchComplete(const net::URLFetcher* source) {
if (HasFieldValue(headernames_vec, it.name())) {
continue;
}
if (SbStringCompareNoCase(it.name().c_str(), kAuthorization) == 0 ||
if (strcasecmp(it.name().c_str(), kAuthorization) == 0 ||
(!HasFieldValue(headernames_vec, "*") &&
!IsSafeRequestHeader(it.name(), it.value()))) {
error_callback_.Run();
Expand Down
2 changes: 1 addition & 1 deletion cobalt/loader/cors_preflight_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ bool CORSPreflightCache::HaveEntry(
if (entry_ptr->allow_all_headers_except_non_wildcard) {
bool has_auth_header = false;
for (const auto& header : unsafe_headernames) {
if (SbStringCompareNoCase(header.c_str(), kAuthorization)) {
if (strcasecmp(header.c_str(), kAuthorization)) {
has_auth_header = true;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion cobalt/loader/cors_preflight_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CORSPreflightCache : public base::RefCounted<CORSPreflightCache> {
// Case-insensitive comparator.
struct CaseInsensitiveCompare {
bool operator()(const std::string& lhs, const std::string& rhs) const {
return SbStringCompareNoCase(lhs.c_str(), rhs.c_str()) < 0;
return strcasecmp(lhs.c_str(), rhs.c_str()) < 0;
}
};

Expand Down
2 changes: 1 addition & 1 deletion cobalt/media/sandbox/format_guesstimator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ std::string ExtractCodecs(const std::string& content_type) {
std::vector<std::string> tokens = ::base::SplitString(
content_type, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
for (size_t i = 1; i < tokens.size(); ++i) {
if (base::strncasecmp(tokens[i].c_str(), kCodecs, strlen(kCodecs))) {
if (strncasecmp(tokens[i].c_str(), kCodecs, strlen(kCodecs))) {
continue;
}
auto codec = tokens[i].substr(strlen("codecs="));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ void SkFontMgr_Cobalt::LoadLocaleDefault() {
std::string script =
icu::Locale::createCanonical(base::GetSystemLanguageScript().c_str())
.getScript();
if (SbStringCompareNoCase(script.c_str(), ROBOTO_SCRIPT) == 0) {
if (strcasecmp(script.c_str(), ROBOTO_SCRIPT) == 0) {
return;
}

Expand Down Expand Up @@ -515,7 +515,7 @@ bool SkFontMgr_Cobalt::CheckIfFamilyMatchesLocaleScript(
}
std::string family_script =
icu::Locale::createCanonical(family_tag.c_str()).getScript();
if (SbStringCompareNoCase(script, family_script.c_str()) != 0) {
if (strcasecmp(script, family_script.c_str()) != 0) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,12 @@ SkFontStyleSet_Cobalt::SkFontStyleSet_Cobalt(

// Only add font formats that match the format setting.
if (font_format_setting == kTtf) {
if (SbStringCompareNoCase("ttf", extension) != 0 &&
SbStringCompareNoCase(extension, "ttc") != 0) {
if (strcasecmp("ttf", extension) != 0 &&
strcasecmp(extension, "ttc") != 0) {
continue;
}
} else if (font_format_setting == kWoff2 &&
SbStringCompareNoCase("woff2", extension) != 0) {
strcasecmp("woff2", extension) != 0) {
continue;
}

Expand Down Expand Up @@ -273,10 +273,10 @@ SkFontStyleSet_Cobalt::SkFontStyleSet_Cobalt(
if (index != nullptr) {
// If style with name already exists in family, replace it.
if (font_format_setting == kTtfPreferred &&
SbStringCompareNoCase("ttf", extension) == 0) {
strcasecmp("ttf", extension) == 0) {
styles_[*index].reset(font);
} else if (font_format_setting == kWoff2Preferred &&
SbStringCompareNoCase("woff2", extension) == 0) {
strcasecmp("woff2", extension) == 0) {
styles_[*index].reset(font);
}
} else {
Expand Down
5 changes: 0 additions & 5 deletions starboard/client_porting/poem/strings_poem.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@

#include "starboard/string.h"

#undef strcasecmp
#define strcasecmp(s1, s2) SbStringCompareNoCase(s1, s2)
#undef strncasecmp
#define strncasecmp(s1, s2) SbStringCompareNoCaseN(s1, s2)

#endif // POEM_NO_EMULATION

#endif // STARBOARD
Expand Down
6 changes: 2 additions & 4 deletions starboard/elf_loader/exported_symbols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,11 @@ ExportedSymbols::ExportedSymbols() {
REGISTER_SYMBOL(SbStorageOpenRecord);
REGISTER_SYMBOL(SbStorageReadRecord);
REGISTER_SYMBOL(SbStorageWriteRecord);
#if SB_API_VERSION < 16
REGISTER_SYMBOL(SbStringCompareNoCase);
REGISTER_SYMBOL(SbStringCompareNoCaseN);

#if SB_API_VERSION < 16
REGISTER_SYMBOL(SbStringDuplicate);
#endif // #if SB_API_VERSION < 16

#endif // SB_API_VERSION < 16
REGISTER_SYMBOL(SbStringFormat);
REGISTER_SYMBOL(SbStringFormatWide);
REGISTER_SYMBOL(SbStringScan);
Expand Down
2 changes: 2 additions & 0 deletions starboard/nplb/string_compare_no_case_n_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace starboard {
namespace nplb {
namespace {

#if SB_API_VERSION < 16
TEST(SbStringCompareNoCaseNTest, SunnyDaySelf) {
const char kString[] = "0123456789";
EXPECT_EQ(0, SbStringCompareNoCaseN(kString, kString, strlen(kString)));
Expand Down Expand Up @@ -55,6 +56,7 @@ TEST(SbStringCompareNoCaseNTest, SunnyDayCase) {
EXPECT_EQ(0,
SbStringCompareNoCaseN(kString4, kString3, strlen(kString4) / 2));
}
#endif // SB_API_VERSION < 16

} // namespace
} // namespace nplb
Expand Down
3 changes: 2 additions & 1 deletion starboard/nplb/string_compare_no_case_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace starboard {
namespace nplb {
namespace {

#if SB_API_VERSION < 16
TEST(SbStringCompareNoCaseTest, SunnyDaySelf) {
const char kString[] = "0123456789";
EXPECT_EQ(0, SbStringCompareNoCase(kString, kString));
Expand All @@ -36,7 +37,7 @@ TEST(SbStringCompareNoCaseTest, SunnyDayCase) {
EXPECT_EQ(0, SbStringCompareNoCase(kString1, kString2));
EXPECT_EQ(0, SbStringCompareNoCase(kString2, kString1));
}

#endif // SB_API_VERSION < 16
} // namespace
} // namespace nplb
} // namespace starboard
2 changes: 2 additions & 0 deletions starboard/shared/posix/string_compare_no_case.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <string.h> // Non-standard, required for some platforms.
#include <strings.h>

#if SB_API_VERSION < 16
int SbStringCompareNoCase(const char* string1, const char* string2) {
return strcasecmp(string1, string2);
}
#endif
2 changes: 2 additions & 0 deletions starboard/shared/posix/string_compare_no_case_n.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
#include <string.h> // Non-standard, required for some platforms.
#include <strings.h>

#if SB_API_VERSION < 16
int SbStringCompareNoCaseN(const char* string1,
const char* string2,
size_t count) {
return ::strncasecmp(string1, string2, count);
}
#endif
2 changes: 1 addition & 1 deletion starboard/shared/starboard/media/mime_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ const std::string& MimeType::GetParamName(int index) const {

int MimeType::GetParamIndexByName(const char* name) const {
for (size_t i = 0; i < params_.size(); ++i) {
if (SbStringCompareNoCase(params_[i].name.c_str(), name) == 0) {
if (strcasecmp(params_[i].name.c_str(), name) == 0) {
return static_cast<int>(i);
}
}
Expand Down
2 changes: 2 additions & 0 deletions starboard/shared/stub/string_compare_no_case.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "starboard/common/string.h"

#if SB_API_VERSION < 16
int SbStringCompareNoCase(const char* string1, const char* string2) {
return 0;
}
#endif
2 changes: 2 additions & 0 deletions starboard/shared/stub/string_compare_no_case_n.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

#include "starboard/common/string.h"

#if SB_API_VERSION < 16
int SbStringCompareNoCaseN(const char* string1,
const char* string2,
size_t count) {
return 0;
}
#endif
2 changes: 2 additions & 0 deletions starboard/shared/win32/posix_emu/include/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

// MSVC deprecated strdup() in favor of _strdup()
#define strdup _strdup
#define strcasecmp _stricmp
#define strncasecmp _strnicmp

#if defined(STARBOARD)
#define free sb_free
Expand Down
2 changes: 2 additions & 0 deletions starboard/shared/win32/string_compare_no_case.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include <string.h>

#if SB_API_VERSION < 16
int SbStringCompareNoCase(const char* string1, const char* string2) {
return _stricmp(string1, string2);
}
#endif
2 changes: 2 additions & 0 deletions starboard/shared/win32/string_compare_no_case_n.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

#include <string.h>

#if SB_API_VERSION < 16
int SbStringCompareNoCaseN(const char* string1,
const char* string2,
size_t count) {
return _strnicmp(string1, string2, count);
}
#endif
2 changes: 1 addition & 1 deletion starboard/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ extern "C" {
//
// |source|: The string to be copied.
SB_EXPORT char* SbStringDuplicate(const char* source);
#endif // SB_API_VERSION < 16

// Compares two strings, ignoring differences in case. The return value is:
// - |< 0| if |string1| is ASCII-betically lower than |string2|.
Expand All @@ -63,6 +62,7 @@ SB_EXPORT int SbStringCompareNoCase(const char* string1, const char* string2);
SB_EXPORT int SbStringCompareNoCaseN(const char* string1,
const char* string2,
size_t count);
#endif // SB_API_VERSION < 16

// Produces a string formatted with |format| and |arguments|, placing as much
// of the result that will fit into |out_buffer|. The return value specifies
Expand Down
2 changes: 2 additions & 0 deletions starboard/tools/api_leak_detector/api_leak_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
'malloc',
'posix_memalign',
'realloc',
'strcasecmp',
'strncasecmp',
]


Expand Down
Loading

0 comments on commit 5c77d54

Please sign in to comment.