mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Bug 1285036 - Part 6: Add CString variants of ASCIIToLower/Upper() for the next patch. r=baku
This commit is contained in:
parent
1bc65bb8d9
commit
5a46237c13
@ -5583,16 +5583,16 @@ nsContentUtils::GetCurrentJSContextForThread()
|
||||
}
|
||||
}
|
||||
|
||||
/* static */
|
||||
template<typename StringType, typename CharType>
|
||||
void
|
||||
nsContentUtils::ASCIIToLower(nsAString& aStr)
|
||||
_ASCIIToLowerInSitu(StringType& aStr)
|
||||
{
|
||||
char16_t* iter = aStr.BeginWriting();
|
||||
char16_t* end = aStr.EndWriting();
|
||||
CharType* iter = aStr.BeginWriting();
|
||||
CharType* end = aStr.EndWriting();
|
||||
MOZ_ASSERT(iter && end);
|
||||
|
||||
while (iter != end) {
|
||||
char16_t c = *iter;
|
||||
CharType c = *iter;
|
||||
if (c >= 'A' && c <= 'Z') {
|
||||
*iter = c + ('a' - 'A');
|
||||
}
|
||||
@ -5602,19 +5602,33 @@ nsContentUtils::ASCIIToLower(nsAString& aStr)
|
||||
|
||||
/* static */
|
||||
void
|
||||
nsContentUtils::ASCIIToLower(const nsAString& aSource, nsAString& aDest)
|
||||
nsContentUtils::ASCIIToLower(nsAString& aStr)
|
||||
{
|
||||
return _ASCIIToLowerInSitu<nsAString, char16_t>(aStr);
|
||||
}
|
||||
|
||||
/* static */
|
||||
void
|
||||
nsContentUtils::ASCIIToLower(nsACString& aStr)
|
||||
{
|
||||
return _ASCIIToLowerInSitu<nsACString, char>(aStr);
|
||||
}
|
||||
|
||||
template<typename StringType, typename CharType>
|
||||
void
|
||||
_ASCIIToLowerCopy(const StringType& aSource, StringType& aDest)
|
||||
{
|
||||
uint32_t len = aSource.Length();
|
||||
aDest.SetLength(len);
|
||||
MOZ_ASSERT(aDest.Length() == len);
|
||||
|
||||
char16_t* dest = aDest.BeginWriting();
|
||||
CharType* dest = aDest.BeginWriting();
|
||||
MOZ_ASSERT(dest);
|
||||
|
||||
const char16_t* iter = aSource.BeginReading();
|
||||
const char16_t* end = aSource.EndReading();
|
||||
const CharType* iter = aSource.BeginReading();
|
||||
const CharType* end = aSource.EndReading();
|
||||
while (iter != end) {
|
||||
char16_t c = *iter;
|
||||
CharType c = *iter;
|
||||
*dest = (c >= 'A' && c <= 'Z') ?
|
||||
c + ('a' - 'A') : c;
|
||||
++iter;
|
||||
@ -5624,14 +5638,27 @@ nsContentUtils::ASCIIToLower(const nsAString& aSource, nsAString& aDest)
|
||||
|
||||
/* static */
|
||||
void
|
||||
nsContentUtils::ASCIIToUpper(nsAString& aStr)
|
||||
nsContentUtils::ASCIIToLower(const nsAString& aSource, nsAString& aDest) {
|
||||
return _ASCIIToLowerCopy<nsAString, char16_t>(aSource, aDest);
|
||||
}
|
||||
|
||||
/* static */
|
||||
void
|
||||
nsContentUtils::ASCIIToLower(const nsACString& aSource, nsACString& aDest) {
|
||||
return _ASCIIToLowerCopy<nsACString, char>(aSource, aDest);
|
||||
}
|
||||
|
||||
|
||||
template<typename StringType, typename CharType>
|
||||
void
|
||||
_ASCIIToUpperInSitu(StringType& aStr)
|
||||
{
|
||||
char16_t* iter = aStr.BeginWriting();
|
||||
char16_t* end = aStr.EndWriting();
|
||||
CharType* iter = aStr.BeginWriting();
|
||||
CharType* end = aStr.EndWriting();
|
||||
MOZ_ASSERT(iter && end);
|
||||
|
||||
while (iter != end) {
|
||||
char16_t c = *iter;
|
||||
CharType c = *iter;
|
||||
if (c >= 'a' && c <= 'z') {
|
||||
*iter = c + ('A' - 'a');
|
||||
}
|
||||
@ -5641,19 +5668,33 @@ nsContentUtils::ASCIIToUpper(nsAString& aStr)
|
||||
|
||||
/* static */
|
||||
void
|
||||
nsContentUtils::ASCIIToUpper(const nsAString& aSource, nsAString& aDest)
|
||||
nsContentUtils::ASCIIToUpper(nsAString& aStr)
|
||||
{
|
||||
return _ASCIIToUpperInSitu<nsAString, char16_t>(aStr);
|
||||
}
|
||||
|
||||
/* static */
|
||||
void
|
||||
nsContentUtils::ASCIIToUpper(nsACString& aStr)
|
||||
{
|
||||
return _ASCIIToUpperInSitu<nsACString, char>(aStr);
|
||||
}
|
||||
|
||||
template<typename StringType, typename CharType>
|
||||
void
|
||||
_ASCIIToUpperCopy(const StringType& aSource, StringType& aDest)
|
||||
{
|
||||
uint32_t len = aSource.Length();
|
||||
aDest.SetLength(len);
|
||||
MOZ_ASSERT(aDest.Length() == len);
|
||||
|
||||
char16_t* dest = aDest.BeginWriting();
|
||||
CharType* dest = aDest.BeginWriting();
|
||||
MOZ_ASSERT(dest);
|
||||
|
||||
const char16_t* iter = aSource.BeginReading();
|
||||
const char16_t* end = aSource.EndReading();
|
||||
const CharType* iter = aSource.BeginReading();
|
||||
const CharType* end = aSource.EndReading();
|
||||
while (iter != end) {
|
||||
char16_t c = *iter;
|
||||
CharType c = *iter;
|
||||
*dest = (c >= 'a' && c <= 'z') ?
|
||||
c + ('A' - 'a') : c;
|
||||
++iter;
|
||||
@ -5661,6 +5702,20 @@ nsContentUtils::ASCIIToUpper(const nsAString& aSource, nsAString& aDest)
|
||||
}
|
||||
}
|
||||
|
||||
/* static */
|
||||
void
|
||||
nsContentUtils::ASCIIToUpper(const nsAString& aSource, nsAString& aDest)
|
||||
{
|
||||
return _ASCIIToUpperCopy<nsAString, char16_t>(aSource, aDest);
|
||||
}
|
||||
|
||||
/* static */
|
||||
void
|
||||
nsContentUtils::ASCIIToUpper(const nsACString& aSource, nsACString& aDest)
|
||||
{
|
||||
return _ASCIIToUpperCopy<nsACString, char>(aSource, aDest);
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool
|
||||
nsContentUtils::EqualsIgnoreASCIICase(const nsAString& aStr1,
|
||||
|
@ -1749,13 +1749,17 @@ public:
|
||||
* Convert ASCII A-Z to a-z.
|
||||
*/
|
||||
static void ASCIIToLower(nsAString& aStr);
|
||||
static void ASCIIToLower(nsACString& aStr);
|
||||
static void ASCIIToLower(const nsAString& aSource, nsAString& aDest);
|
||||
static void ASCIIToLower(const nsACString& aSource, nsACString& aDest);
|
||||
|
||||
/**
|
||||
* Convert ASCII a-z to A-Z.
|
||||
*/
|
||||
static void ASCIIToUpper(nsAString& aStr);
|
||||
static void ASCIIToUpper(nsACString& aStr);
|
||||
static void ASCIIToUpper(const nsAString& aSource, nsAString& aDest);
|
||||
static void ASCIIToUpper(const nsACString& aSource, nsACString& aDest);
|
||||
|
||||
/**
|
||||
* Return whether aStr contains an ASCII uppercase character.
|
||||
|
Loading…
Reference in New Issue
Block a user