diff --git a/packages/react-native/ReactCommon/react/renderer/css/CSSHexColor.h b/packages/react-native/ReactCommon/react/renderer/css/CSSHexColor.h index 58607f67d4a..2a1268c4fe5 100644 --- a/packages/react-native/ReactCommon/react/renderer/css/CSSHexColor.h +++ b/packages/react-native/ReactCommon/react/renderer/css/CSSHexColor.h @@ -10,6 +10,8 @@ #include #include +#include + namespace facebook::react { namespace detail { @@ -18,13 +20,6 @@ enum class HexColorType { Short, }; -constexpr char toLower(char c) { - if (c >= 'A' && c <= 'Z') { - return static_cast(c + 32); - } - return c; -} - constexpr uint8_t hexToNumeric(std::string_view hex, HexColorType hexType) { int result = 0; for (char c : hex) { diff --git a/packages/react-native/ReactCommon/react/utils/fnv1a.h b/packages/react-native/ReactCommon/react/utils/fnv1a.h index 2acdeb3113b..4a945d968f7 100644 --- a/packages/react-native/ReactCommon/react/utils/fnv1a.h +++ b/packages/react-native/ReactCommon/react/utils/fnv1a.h @@ -11,6 +11,8 @@ #include #include +#include + namespace facebook::react { /** @@ -41,10 +43,7 @@ constexpr uint32_t fnv1a(std::string_view string) noexcept { constexpr uint32_t fnv1aLowercase(std::string_view string) { struct LowerCaseTransform { constexpr char operator()(char c) const { - if (c >= 'A' && c <= 'Z') { - return c + static_cast('a' - 'A'); - } - return c; + return toLower(c); } }; diff --git a/packages/react-native/ReactCommon/react/utils/iequals.h b/packages/react-native/ReactCommon/react/utils/iequals.h new file mode 100644 index 00000000000..b30bd5b9e9d --- /dev/null +++ b/packages/react-native/ReactCommon/react/utils/iequals.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include + +#include + +namespace facebook::react { + +/** + * constexpr check for case insensitive equality of two strings. + */ +constexpr bool iequals(std::string_view a, std::string_view b) { + if (a.size() != b.size()) { + return false; + } + + for (size_t i = 0; i < a.size(); i++) { + if (toLower(a[i]) != toLower(b[i])) { + return false; + } + } + + return true; +} + +} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/utils/toLower.h b/packages/react-native/ReactCommon/react/utils/toLower.h new file mode 100644 index 00000000000..27212d006dc --- /dev/null +++ b/packages/react-native/ReactCommon/react/utils/toLower.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +namespace facebook::react { + +/** + * constexpr version of tolower + */ +constexpr char toLower(char c) { + if (c >= 'A' && c <= 'Z') { + return static_cast(c + 32); + } + return c; +} + +} // namespace facebook::react