Skip to content

Commit

Permalink
Deprecate SbStringCompareNoCase
Browse files Browse the repository at this point in the history
b/305768669
  • Loading branch information
madhurajayaraman committed Nov 14, 2023
1 parent e4ede3d commit 5318a32
Show file tree
Hide file tree
Showing 17 changed files with 112 additions and 6 deletions.
6 changes: 6 additions & 0 deletions cobalt/debug/console/command_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ ConsoleCommandManager::CommandHandler::~CommandHandler() {
// static
bool ConsoleCommandManager::CommandHandler::IsOnEnableOrTrue(
const std::string& message) {
#if SB_API_VERSION < 16
return (SbStringCompareNoCase("on", message.c_str()) == 0) ||
(SbStringCompareNoCase("enable", message.c_str()) == 0) ||
(SbStringCompareNoCase("true", message.c_str()) == 0);
#else
return (strcasecmp("on", message.c_str()) == 0) ||
(strcasecmp("enable", message.c_str()) == 0) ||
(strcasecmp("true", message.c_str()) == 0);
#endif // SB_API_VERSION < 16
}


Expand Down
8 changes: 6 additions & 2 deletions cobalt/dom/on_screen_keyboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ 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 SB_API_VERSION < 16
bool strcmp = SbStringCompareNoCaseN("rgb(", color_str, 4) == 0;
#else
bool strcmp = strncasecmp("rgb(", color_str, 4) == 0;
#endif //SB_API_VERSION < 16
if (!is_hex && len >= 10 && strcmp) {
int rgb_tmp[3] = {-1, -1, -1};
const char* ptr = color_str + 4;
int i = 0;
Expand Down
31 changes: 31 additions & 0 deletions cobalt/loader/cors_preflight.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,15 @@ bool IsInArray(const char* input_str, const char* array[], size_t size) {
return false;
}
for (size_t i = 0; i < size; ++i) {
#if SB_API_VERSION < 16
if (SbStringCompareNoCase(input_str, array[i]) == 0) {
return true;
}
#else
if (strcasecmp(input_str, array[i]) == 0) {
return true;
}
#endif // SB_API_VERSION < 16
}
return false;
}
Expand All @@ -132,10 +138,18 @@ bool HasFieldValue(const std::vector<std::string>& field_values,
if (field_values[i].empty()) {
continue;
}
#if SB_API_VERSION < 16
if (SbStringCompareNoCase(field_values[i].c_str(),
find_value_name.c_str()) == 0) {
return true;
}
#else
if (strcasecmp(field_values[i].c_str(),
find_value_name.c_str()) == 0) {
return true;
}
#endif // SB_API_VERSION < 16

}
return false;
}
Expand Down Expand Up @@ -220,10 +234,17 @@ bool CORSPreflight::IsSafeResponseHeader(
}

for (size_t i = 0; i < CORS_exposed_header_name_list.size(); i++) {
#if SB_API_VERSION < 16
if (SbStringCompareNoCase(CORS_exposed_header_name_list.at(i).c_str(),
name.c_str()) == 0) {
return true;
}
#else
if (strcasecmp(CORS_exposed_header_name_list.at(i).c_str(),
name.c_str()) == 0) {
return true;
}
#endif //SB_API_VERSION < 16
}
return false;
}
Expand Down Expand Up @@ -381,12 +402,22 @@ void CORSPreflight::OnURLFetchComplete(const net::URLFetcher* source) {
if (HasFieldValue(headernames_vec, it.name())) {
continue;
}
#if SB_API_VERSION < 16
if (SbStringCompareNoCase(it.name().c_str(), kAuthorization) == 0 ||
(!HasFieldValue(headernames_vec, "*") &&
!IsSafeRequestHeader(it.name(), it.value()))) {
error_callback_.Run();
return;
}
#else
if (strcasecmp(it.name().c_str(), kAuthorization) == 0 ||
(!HasFieldValue(headernames_vec, "*") &&
!IsSafeRequestHeader(it.name(), it.value()))) {
error_callback_.Run();
return;
}
#endif //SB_API_VERSION < 16

}
// step 10-18 for adding entry to preflight cache.
std::string max_age_str;
Expand Down
7 changes: 7 additions & 0 deletions cobalt/loader/cors_preflight_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,17 @@ bool CORSPreflightCache::HaveEntry(
if (entry_ptr->allow_all_headers_except_non_wildcard) {
bool has_auth_header = false;
for (const auto& header : unsafe_headernames) {
#if SB_API_VERSION < 16
if (SbStringCompareNoCase(header.c_str(), kAuthorization)) {
has_auth_header = true;
break;
}
#else
if (strcasecmp(header.c_str(), kAuthorization)) {
has_auth_header = true;
break;
}
#endif //SB_API_VERSION < 16
}
// wildcard header is allowed if entry's allowed headers include it.
return !has_auth_header ||
Expand Down
4 changes: 4 additions & 0 deletions cobalt/loader/cors_preflight_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ class CORSPreflightCache : public base::RefCounted<CORSPreflightCache> {
// Case-insensitive comparator.
struct CaseInsensitiveCompare {
bool operator()(const std::string& lhs, const std::string& rhs) const {
#if SB_API_VERSION < 16
return SbStringCompareNoCase(lhs.c_str(), rhs.c_str()) < 0;
#else
return strcasecmp(lhs.c_str(), rhs.c_str()) < 0;
#endif //SB_API_VERSION < 16
}
};

Expand Down
12 changes: 12 additions & 0 deletions cobalt/renderer/rasterizer/skia/skia/src/ports/SkFontMgr_cobalt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,15 @@ void SkFontMgr_Cobalt::LoadLocaleDefault() {
std::string script =
icu::Locale::createCanonical(base::GetSystemLanguageScript().c_str())
.getScript();
#if SB_API_VERSION < 16
if (SbStringCompareNoCase(script.c_str(), ROBOTO_SCRIPT) == 0) {
return;
}
#else
if (strcasecmp(script.c_str(), ROBOTO_SCRIPT) == 0) {
return;
}
#endif // SB_API_VERSION < 16

default_fonts_loaded_event_.Reset();
for (int i = 0; i < families_.count(); i++) {
Expand Down Expand Up @@ -515,9 +521,15 @@ bool SkFontMgr_Cobalt::CheckIfFamilyMatchesLocaleScript(
}
std::string family_script =
icu::Locale::createCanonical(family_tag.c_str()).getScript();
#if SB_API_VERSION < 16
if (SbStringCompareNoCase(script, family_script.c_str()) != 0) {
return false;
}
#else
if (strcasecmp(script, family_script.c_str()) != 0) {
return false;
}
#endif //SB_API_VERSION < 16

sk_sp<SkTypeface> check_typeface(
new_family->MatchStyleWithoutLocking(SkFontStyle()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ SkFontStyleSet_Cobalt::SkFontStyleSet_Cobalt(
++extension;

// Only add font formats that match the format setting.
#if SB_API_VERSION < 16
if (font_format_setting == kTtf) {
if (SbStringCompareNoCase("ttf", extension) != 0 &&
SbStringCompareNoCase(extension, "ttc") != 0) {
Expand All @@ -241,6 +242,17 @@ SkFontStyleSet_Cobalt::SkFontStyleSet_Cobalt(
SbStringCompareNoCase("woff2", extension) != 0) {
continue;
}
#else
if (font_format_setting == kTtf) {
if (strcasecmp("ttf", extension) != 0 &&
strcasecmp(extension, "ttc") != 0) {
continue;
}
} else if (font_format_setting == kWoff2 &&
strcasecmp("woff2", extension) != 0) {
continue;
}
#endif //SB_API_VERSION < 16

SkFontStyle style(font_file.weight, SkFontStyle::kNormal_Width,
font_file.style == FontFileInfo::kItalic_FontStyle
Expand Down Expand Up @@ -272,13 +284,23 @@ SkFontStyleSet_Cobalt::SkFontStyleSet_Cobalt(
int* index = styles_index_map.find(font_name);
if (index != nullptr) {
// If style with name already exists in family, replace it.
#if SB_API_VERSION < 16
if (font_format_setting == kTtfPreferred &&
SbStringCompareNoCase("ttf", extension) == 0) {
styles_[*index].reset(font);
} else if (font_format_setting == kWoff2Preferred &&
SbStringCompareNoCase("woff2", extension) == 0) {
styles_[*index].reset(font);
}
#else
if (font_format_setting == kTtfPreferred &&
strcasecmp("ttf", extension) == 0) {
styles_[*index].reset(font);
} else if (font_format_setting == kWoff2Preferred &&
strcasecmp("woff2", extension) == 0) {
styles_[*index].reset(font);
}
#endif //SB_API_VERSION < 16
} else {
int count = styles_.count();
styles_index_map.set(font_name, count);
Expand Down
2 changes: 2 additions & 0 deletions starboard/client_porting/poem/strings_poem.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@

#include "starboard/string.h"

#if SB_API_VERSION < 16
#undef strcasecmp
#define strcasecmp(s1, s2) SbStringCompareNoCase(s1, s2)
#undef strncasecmp
#define strncasecmp(s1, s2) SbStringCompareNoCaseN(s1, s2)
#endif // SB_API_VERSION < 16

#endif // POEM_NO_EMULATION

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/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
6 changes: 6 additions & 0 deletions starboard/shared/starboard/media/mime_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,15 @@ 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 SB_API_VERSION < 16
if (SbStringCompareNoCase(params_[i].name.c_str(), name) == 0) {
return static_cast<int>(i);
}
#else
if (strcasecmp(params_[i].name.c_str(), name) == 0) {
return static_cast<int>(i);
}
#endif // SB_API_VERSION < 16
}
return kInvalidParamIndex;
}
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/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: 2 additions & 0 deletions third_party/musl/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ static_library("c_internal") {
"src/string/rindex.c",
"src/string/stpcpy.c",
"src/string/stpncpy.c",
"src/string/strcasecmp.c",
"src/string/strcat.c",
"src/string/strchr.c",
"src/string/strchrnul.c",
Expand All @@ -444,6 +445,7 @@ static_library("c_internal") {
"src/string/strlcat.c",
"src/string/strlcpy.c",
"src/string/strlen.c",
"src/string/strncasecmp.c",
"src/string/strncat.c",
"src/string/strncmp.c",
"src/string/strncpy.c",
Expand Down

0 comments on commit 5318a32

Please sign in to comment.