Skip to content

Commit

Permalink
change
Browse files Browse the repository at this point in the history
  • Loading branch information
madhurajayaraman committed Nov 16, 2023
1 parent 285f66e commit 619882e
Show file tree
Hide file tree
Showing 20 changed files with 31 additions and 122 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
6 changes: 3 additions & 3 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,7 +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)) ==
strncasecmp(algorithm.prefix, begin, strlen(algorithm.prefix)) ==
0) {
prefix = algorithm.prefix;
*hash_algorithm = algorithm.type;
Expand Down
6 changes: 0 additions & 6 deletions cobalt/debug/console/command_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,9 @@ 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
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
8 changes: 2 additions & 6 deletions cobalt/dom/on_screen_keyboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,8 @@ bool ParseColor(const char* color_str, int& r, int& g, int& b) {
}

// Handle rgb color notation rgb(R, G, B)
#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) {
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
31 changes: 1 addition & 30 deletions cobalt/loader/cors_preflight.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,9 @@ 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 @@ -138,17 +132,10 @@ 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 @@ -185,7 +172,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 @@ -234,17 +221,10 @@ 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 @@ -402,21 +382,12 @@ 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.
Expand Down
7 changes: 0 additions & 7 deletions cobalt/loader/cors_preflight_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,10 @@ 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: 0 additions & 4 deletions cobalt/loader/cors_preflight_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ 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
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
12 changes: 0 additions & 12 deletions cobalt/renderer/rasterizer/skia/skia/src/ports/SkFontMgr_cobalt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,9 @@ 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 @@ -521,15 +515,9 @@ 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,17 +232,6 @@ 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) {
continue;
}
} else if (font_format_setting == kWoff2 &&
SbStringCompareNoCase("woff2", extension) != 0) {
continue;
}
#else
if (font_format_setting == kTtf) {
if (strcasecmp("ttf", extension) != 0 &&
strcasecmp(extension, "ttc") != 0) {
Expand All @@ -252,7 +241,6 @@ SkFontStyleSet_Cobalt::SkFontStyleSet_Cobalt(
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 @@ -284,23 +272,13 @@ 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/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/nplb/string_duplicate_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ void RunTest(const char* input) {
char* dupe = SbStringDuplicate(input);
const char* kNull = NULL;
EXPECT_NE(kNull, dupe);
#if SB_API_VERSION < 16
EXPECT_EQ(0, SbStringCompareNoCase(input, dupe));
#endif //SB_API_VERSION < 16
EXPECT_EQ(strlen(input), strlen(dupe));
SbMemoryDeallocate(dupe);
}
Expand Down
6 changes: 0 additions & 6 deletions starboard/shared/starboard/media/mime_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,9 @@ 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: 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
Loading

0 comments on commit 619882e

Please sign in to comment.