Bug 1449082 - Make NS_IsAscii constexpr. r=froydnj

MozReview-Commit-ID: GbXFwCzUwgV

--HG--
extra : rebase_source : 4e7ceae0bda793247286901cfffdff5575800edb
This commit is contained in:
Masatoshi Kimura 2018-03-27 23:59:55 +09:00
Родитель 68bc832e63
Коммит 2002810e0f
2 изменённых файлов: 54 добавлений и 32 удалений

Просмотреть файл

@ -216,12 +216,6 @@ NS_IsLower(char aChar)
return aChar != (char)nsLowerUpperUtils::kLower2Upper[(unsigned char)aChar];
}
bool
NS_IsAscii(char16_t aChar)
{
return (0x0080 > aChar);
}
bool
NS_IsAscii(const char16_t* aString)
{
@ -259,28 +253,6 @@ NS_IsAscii(const char* aString, uint32_t aLength)
return true;
}
bool
NS_IsAsciiAlpha(char16_t aChar)
{
return (aChar >= 'A' && aChar <= 'Z') ||
(aChar >= 'a' && aChar <= 'z');
}
bool
NS_IsAsciiWhitespace(char16_t aChar)
{
return aChar == ' ' ||
aChar == '\r' ||
aChar == '\n' ||
aChar == '\t';
}
bool
NS_IsAsciiDigit(char16_t aChar)
{
return aChar >= '0' && aChar <= '9';
}
#ifndef XPCOM_GLUE_AVOID_NSPR
void

Просмотреть файл

@ -98,14 +98,64 @@ NS_ToLower(char aChar)
bool NS_IsUpper(char aChar);
bool NS_IsLower(char aChar);
bool NS_IsAscii(char16_t aChar);
constexpr bool
NS_IsAscii(char16_t aChar)
{
return (0x0080 > aChar);
}
bool NS_IsAscii(const char16_t* aString);
bool NS_IsAsciiAlpha(char16_t aChar);
bool NS_IsAsciiDigit(char16_t aChar);
bool NS_IsAsciiWhitespace(char16_t aChar);
bool NS_IsAscii(const char* aString);
bool NS_IsAscii(const char* aString, uint32_t aLength);
// These three functions are `constexpr` alternatives to NS_IsAscii. It should
// only be used for compile-time computation because it uses recursion.
// XXX: once support for GCC 4.9 is dropped, this function should be removed
// and NS_IsAscii should be made `constexpr`.
constexpr bool
NS_ConstExprIsAscii(const char16_t* aString)
{
return !*aString ? true :
!NS_IsAscii(*aString) ? false : NS_ConstExprIsAscii(aString + 1);
}
constexpr bool
NS_ConstExprIsAscii(const char* aString)
{
return !*aString ? true :
!NS_IsAscii(*aString) ? false : NS_ConstExprIsAscii(aString + 1);
}
constexpr bool
NS_ConstExprIsAscii(const char* aString, uint32_t aLength)
{
return aLength == 0 ? true :
!NS_IsAscii(*aString) ? false :
NS_ConstExprIsAscii(aString + 1, aLength - 1);
}
constexpr bool
NS_IsAsciiAlpha(char16_t aChar)
{
return (aChar >= 'A' && aChar <= 'Z') ||
(aChar >= 'a' && aChar <= 'z');
}
constexpr bool
NS_IsAsciiWhitespace(char16_t aChar)
{
return aChar == ' ' ||
aChar == '\r' ||
aChar == '\n' ||
aChar == '\t';
}
constexpr bool
NS_IsAsciiDigit(char16_t aChar)
{
return aChar >= '0' && aChar <= '9';
}
#ifndef XPCOM_GLUE_AVOID_NSPR
void NS_MakeRandomString(char* aBuf, int32_t aBufLen);
#endif