From 5a46237c13c2814c02ad594682eb45f82f9151f1 Mon Sep 17 00:00:00 2001 From: Thomas Wisniewski Date: Fri, 8 Jul 2016 12:51:09 -0400 Subject: [PATCH] Bug 1285036 - Part 6: Add CString variants of ASCIIToLower/Upper() for the next patch. r=baku --- dom/base/nsContentUtils.cpp | 93 +++++++++++++++++++++++++++++-------- dom/base/nsContentUtils.h | 4 ++ 2 files changed, 78 insertions(+), 19 deletions(-) diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 517478ccf69d..a509833dc4bf 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -5583,16 +5583,16 @@ nsContentUtils::GetCurrentJSContextForThread() } } -/* static */ +template 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(aStr); +} + +/* static */ +void +nsContentUtils::ASCIIToLower(nsACString& aStr) +{ + return _ASCIIToLowerInSitu(aStr); +} + +template +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(aSource, aDest); +} + +/* static */ +void +nsContentUtils::ASCIIToLower(const nsACString& aSource, nsACString& aDest) { + return _ASCIIToLowerCopy(aSource, aDest); +} + + +template +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(aStr); +} + +/* static */ +void +nsContentUtils::ASCIIToUpper(nsACString& aStr) +{ + return _ASCIIToUpperInSitu(aStr); +} + +template +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(aSource, aDest); +} + +/* static */ +void +nsContentUtils::ASCIIToUpper(const nsACString& aSource, nsACString& aDest) +{ + return _ASCIIToUpperCopy(aSource, aDest); +} + /* static */ bool nsContentUtils::EqualsIgnoreASCIICase(const nsAString& aStr1, diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index faa09e0c70b8..2882ed35a5f3 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -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.