--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -1623,147 +1623,16 @@ nsContentUtils::GetBidiKeyboard()
nsresult rv = CallGetService("@mozilla.org/widget/bidikeyboard;1", &sBidiKeyboard);
if (NS_FAILED(rv)) {
sBidiKeyboard = nullptr;
}
}
return sBidiKeyboard;
}
-template <class OutputIterator>
-struct NormalizeNewlinesCharTraits {
- public:
- typedef typename OutputIterator::value_type value_type;
-
- public:
- explicit NormalizeNewlinesCharTraits(OutputIterator& aIterator) : mIterator(aIterator) { }
- void writechar(typename OutputIterator::value_type aChar) {
- *mIterator++ = aChar;
- }
-
- private:
- OutputIterator mIterator;
-};
-
-template <class CharT>
-struct NormalizeNewlinesCharTraits<CharT*> {
- public:
- typedef CharT value_type;
-
- public:
- explicit NormalizeNewlinesCharTraits(CharT* aCharPtr) : mCharPtr(aCharPtr) { }
- void writechar(CharT aChar) {
- *mCharPtr++ = aChar;
- }
-
- private:
- CharT* mCharPtr;
-};
-
-template <class OutputIterator>
-class CopyNormalizeNewlines
-{
- public:
- typedef typename OutputIterator::value_type value_type;
-
- public:
- explicit CopyNormalizeNewlines(OutputIterator* aDestination,
- bool aLastCharCR = false) :
- mLastCharCR(aLastCharCR),
- mDestination(aDestination),
- mWritten(0)
- { }
-
- uint32_t GetCharsWritten() {
- return mWritten;
- }
-
- bool IsLastCharCR() {
- return mLastCharCR;
- }
-
- void write(const typename OutputIterator::value_type* aSource, uint32_t aSourceLength) {
-
- const typename OutputIterator::value_type* done_writing = aSource + aSourceLength;
-
- // If the last source buffer ended with a CR...
- if (mLastCharCR) {
- // ..and if the next one is a LF, then skip it since
- // we've already written out a newline
- if (aSourceLength && (*aSource == value_type('\n'))) {
- ++aSource;
- }
- mLastCharCR = false;
- }
-
- uint32_t num_written = 0;
- while ( aSource < done_writing ) {
- if (*aSource == value_type('\r')) {
- mDestination->writechar('\n');
- ++aSource;
- // If we've reached the end of the buffer, record
- // that we wrote out a CR
- if (aSource == done_writing) {
- mLastCharCR = true;
- }
- // If the next character is a LF, skip it
- else if (*aSource == value_type('\n')) {
- ++aSource;
- }
- }
- else {
- mDestination->writechar(*aSource++);
- }
- ++num_written;
- }
-
- mWritten += num_written;
- }
-
- private:
- bool mLastCharCR;
- OutputIterator* mDestination;
- uint32_t mWritten;
-};
-
-// static
-uint32_t
-nsContentUtils::CopyNewlineNormalizedUnicodeTo(const nsAString& aSource,
- uint32_t aSrcOffset,
- char16_t* aDest,
- uint32_t aLength,
- bool& aLastCharCR)
-{
- typedef NormalizeNewlinesCharTraits<char16_t*> sink_traits;
-
- sink_traits dest_traits(aDest);
- CopyNormalizeNewlines<sink_traits> normalizer(&dest_traits,aLastCharCR);
- nsReadingIterator<char16_t> fromBegin, fromEnd;
- copy_string(aSource.BeginReading(fromBegin).advance( int32_t(aSrcOffset) ),
- aSource.BeginReading(fromEnd).advance( int32_t(aSrcOffset+aLength) ),
- normalizer);
- aLastCharCR = normalizer.IsLastCharCR();
- return normalizer.GetCharsWritten();
-}
-
-// static
-uint32_t
-nsContentUtils::CopyNewlineNormalizedUnicodeTo(nsReadingIterator<char16_t>& aSrcStart, const nsReadingIterator<char16_t>& aSrcEnd, nsAString& aDest)
-{
- typedef nsWritingIterator<char16_t> WritingIterator;
- typedef NormalizeNewlinesCharTraits<WritingIterator> sink_traits;
-
- WritingIterator iter;
- aDest.BeginWriting(iter);
- sink_traits dest_traits(iter);
- CopyNormalizeNewlines<sink_traits> normalizer(&dest_traits);
- copy_string(aSrcStart, aSrcEnd, normalizer);
- return normalizer.GetCharsWritten();
-}
-
/**
* This is used to determine whether a character is in one of the classes
* which CSS says should be part of the first-letter. Currently, that is
* all punctuation classes (P*). Note that this is a change from CSS2
* which excluded Pc and Pd.
*
* https://www.w3.org/TR/css-pseudo-4/#first-letter-pseudo
* "Punctuation (i.e, characters that belong to the Punctuation (P*) Unicode
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -505,24 +505,16 @@ public:
* A pointer to the found nsIDocument. nullptr if the subdocument
* cannot be found, or if either aDocument or aOuterWindowId were
* invalid. If the outer window ID belongs to aDocument itself, this
* will return a pointer to aDocument.
*/
static nsIDocument* GetSubdocumentWithOuterWindowId(nsIDocument *aDocument,
uint64_t aOuterWindowId);
- static uint32_t CopyNewlineNormalizedUnicodeTo(const nsAString& aSource,
- uint32_t aSrcOffset,
- char16_t* aDest,
- uint32_t aLength,
- bool& aLastCharCR);
-
- static uint32_t CopyNewlineNormalizedUnicodeTo(nsReadingIterator<char16_t>& aSrcStart, const nsReadingIterator<char16_t>& aSrcEnd, nsAString& aDest);
-
static const nsDependentSubstring TrimCharsInSet(const char* aSet,
const nsAString& aValue);
template<bool IsWhitespace(char16_t)>
static const nsDependentSubstring TrimWhitespace(const nsAString& aStr,
bool aTrimTrailing = true);
/**
--- a/dom/xslt/base/txDouble.cpp
+++ b/dom/xslt/base/txDouble.cpp
@@ -22,29 +22,28 @@
/*
* Converts the given String to a double, if the String value does not
* represent a double, NaN will be returned
*/
class txStringToDouble
{
public:
- typedef char16_t input_type;
- typedef char16_t value_type;
txStringToDouble(): mState(eWhitestart), mSign(ePositive) {}
void
- write(const input_type* aSource, uint32_t aSourceLength)
+ Parse(const nsAString& aSource)
{
if (mState == eIllegal) {
return;
}
uint32_t i = 0;
char16_t c;
- for ( ; i < aSourceLength; ++i) {
+ auto len = aSource.Length();
+ for ( ; i < len; ++i) {
c = aSource[i];
switch (mState) {
case eWhitestart:
if (c == '-') {
mState = eDecimal;
mSign = eNegative;
}
else if (c >= '0' && c <= '9') {
@@ -122,18 +121,17 @@ private:
eNegative = -1,
ePositive = 1
} mSign;
};
double txDouble::toDouble(const nsAString& aSrc)
{
txStringToDouble sink;
- nsAString::const_iterator fromBegin, fromEnd;
- copy_string(aSrc.BeginReading(fromBegin), aSrc.EndReading(fromEnd), sink);
+ sink.Parse(aSrc);
return sink.getDouble();
}
/*
* Converts the value of the given double to a String, and places
* The result into the destination String.
* @return the given dest string
*/
--- a/js/xpconnect/src/XPCConvert.cpp
+++ b/js/xpconnect/src/XPCConvert.cpp
@@ -301,24 +301,24 @@ XPCConvert::NativeData2JS(MutableHandleV
return true;
}
allocLen *= sizeof(char16_t);
if (!allocLen.isValid()) {
return false;
}
- // ConvertUTF8toUTF16Func requires the destination to be one code unit
+ // ConvertUTF8toUTF16 requires the destination to be one code unit
// longer than the source.
char16_t* buffer =
static_cast<char16_t*>(JS_malloc(cx, (len + 1) * sizeof(char16_t)));;
if (!buffer) {
return false;
}
- size_t written = ConvertUTF8toUTF16Func(*utf8String, MakeSpan(buffer, len + 1));
+ size_t written = ConvertUTF8toUTF16(*utf8String, MakeSpan(buffer, len + 1));
buffer[written] = 0;
// JS_NewUCStringDontDeflate takes ownership on success, i.e. a
// successful call will make it the responsiblity of the JS VM
// to free the buffer.
// written can never exceed len + 1, so the truncation is OK.
JSString* str = JS_NewUCStringDontDeflate(cx, buffer, written);
if (!str) {
JS_free(cx, buffer);
--- a/netwerk/cookie/nsCookie.cpp
+++ b/netwerk/cookie/nsCookie.cpp
@@ -22,27 +22,39 @@ StrBlockCopy(const nsACString &aSource1,
const nsACString &aSource3,
const nsACString &aSource4,
char *&aDest1,
char *&aDest2,
char *&aDest3,
char *&aDest4,
char *&aDestEnd)
{
- char *toBegin = aDest1;
- nsACString::const_iterator fromBegin, fromEnd;
+ size_t len1 = aSource1.Length();
+ memcpy(aDest1, aSource1.BeginReading(), len1);
+ aDest1[len1] = 0;
+
+ aDest2 = aDest1 + len1 + 1;
+
+ size_t len2 = aSource2.Length();
+ memcpy(aDest2, aSource2.BeginReading(), len2);
+ aDest2[len2] = 0;
+
+ aDest3 = aDest2 + len2 + 1;
- *copy_string(aSource1.BeginReading(fromBegin), aSource1.EndReading(fromEnd), toBegin) = char(0);
- aDest2 = ++toBegin;
- *copy_string(aSource2.BeginReading(fromBegin), aSource2.EndReading(fromEnd), toBegin) = char(0);
- aDest3 = ++toBegin;
- *copy_string(aSource3.BeginReading(fromBegin), aSource3.EndReading(fromEnd), toBegin) = char(0);
- aDest4 = ++toBegin;
- *copy_string(aSource4.BeginReading(fromBegin), aSource4.EndReading(fromEnd), toBegin) = char(0);
- aDestEnd = toBegin;
+ size_t len3 = aSource3.Length();
+ memcpy(aDest3, aSource3.BeginReading(), len3);
+ aDest3[len3] = 0;
+
+ aDest4 = aDest3 + len3 + 1;
+
+ size_t len4 = aSource4.Length();
+ memcpy(aDest4, aSource4.BeginReading(), len4);
+ aDest4[len4] = 0;
+
+ aDestEnd = aDest4 + len4 + 1;
}
/******************************************************************************
* nsCookie:
* creation helper
******************************************************************************/
// This is a counter that keeps track of the last used creation time, each time
--- a/xpcom/base/nsAlgorithm.h
+++ b/xpcom/base/nsAlgorithm.h
@@ -54,22 +54,9 @@ NS_COUNT(InputIterator& aFirst, const In
uint32_t result = 0;
for (; aFirst != aLast; ++aFirst)
if (*aFirst == aValue) {
++result;
}
return result;
}
-template <class InputIterator, class OutputIterator>
-inline OutputIterator&
-copy_string(const InputIterator& aFirst, const InputIterator& aLast,
- OutputIterator& aResult)
-{
- typedef nsCharSourceTraits<InputIterator> source_traits;
- typedef nsCharSinkTraits<OutputIterator> sink_traits;
-
- sink_traits::write(aResult, source_traits::read(aFirst),
- source_traits::readable_distance(aFirst, aLast));
- return aResult;
-}
-
#endif // !defined(nsAlgorithm_h___)
--- a/xpcom/string/nsReadableUtils.cpp
+++ b/xpcom/string/nsReadableUtils.cpp
@@ -69,17 +69,17 @@ ToNewUTF8String(const nsAString& aSource
if (destLenVal > UINT32_MAX) {
return nullptr;
}
char* dest = static_cast<char*>(moz_xmalloc(destLenVal));
if (!dest) {
return nullptr;
}
- size_t written = ConvertUTF16toUTF8Func(aSource, MakeSpan(dest, destLenVal));
+ size_t written = ConvertUTF16toUTF8(aSource, MakeSpan(dest, destLenVal));
dest[written] = 0;
if (aUTF8Count) {
*aUTF8Count = written;
}
return dest;
}
@@ -128,17 +128,17 @@ ToNewUnicode(const nsACString& aSource)
ConvertLatin1toUTF16(aSource, MakeSpan(dest, len));
dest[len] = 0;
return dest;
}
char16_t*
UTF8ToNewUnicode(const nsACString& aSource, uint32_t* aUTF16Count)
{
- // Compute length plus one as required by ConvertUTF8toUTF16Func
+ // Compute length plus one as required by ConvertUTF8toUTF16
uint32_t lengthPlusOne = aSource.Length() + 1; // Can't overflow
mozilla::CheckedInt<size_t> allocLength(lengthPlusOne);
// Add space for zero-termination
allocLength += 1;
// We need UTF-16 units
allocLength *= sizeof(char16_t);
@@ -146,231 +146,99 @@ UTF8ToNewUnicode(const nsACString& aSour
return nullptr;
}
char16_t* dest = (char16_t*)moz_xmalloc(allocLength.value());
if (!dest) {
return nullptr;
}
- size_t written = ConvertUTF8toUTF16Func(aSource, MakeSpan(dest, lengthPlusOne));
+ size_t written = ConvertUTF8toUTF16(aSource, MakeSpan(dest, lengthPlusOne));
dest[written] = 0;
if (aUTF16Count) {
*aUTF16Count = written;
}
return dest;
}
char16_t*
CopyUnicodeTo(const nsAString& aSource, uint32_t aSrcOffset, char16_t* aDest,
uint32_t aLength)
{
- nsAString::const_iterator fromBegin, fromEnd;
- char16_t* toBegin = aDest;
- copy_string(aSource.BeginReading(fromBegin).advance(int32_t(aSrcOffset)),
- aSource.BeginReading(fromEnd).advance(int32_t(aSrcOffset + aLength)),
- toBegin);
+ MOZ_ASSERT(aSrcOffset + aLength <= aSource.Length());
+ memcpy(aDest, aSource.BeginReading() + aSrcOffset, size_t(aLength) * sizeof(char16_t));
return aDest;
}
void
-CopyUnicodeTo(const nsAString::const_iterator& aSrcStart,
- const nsAString::const_iterator& aSrcEnd,
- nsAString& aDest)
-{
- aDest.SetLength(Distance(aSrcStart, aSrcEnd));
-
- nsAString::char_iterator dest = aDest.BeginWriting();
- nsAString::const_iterator fromBegin(aSrcStart);
-
- copy_string(fromBegin, aSrcEnd, dest);
-}
-
-void
-AppendUnicodeTo(const nsAString::const_iterator& aSrcStart,
- const nsAString::const_iterator& aSrcEnd,
- nsAString& aDest)
-{
- uint32_t oldLength = aDest.Length();
- aDest.SetLength(oldLength + Distance(aSrcStart, aSrcEnd));
-
- nsAString::char_iterator dest = aDest.BeginWriting() + oldLength;
- nsAString::const_iterator fromBegin(aSrcStart);
-
- copy_string(fromBegin, aSrcEnd, dest);
-}
-
-/**
- * A character sink for in-place case conversion.
- */
-class ConvertToUpperCase
-{
-public:
- typedef char value_type;
-
- uint32_t
- write(const char* aSource, uint32_t aSourceLength)
- {
- char* cp = const_cast<char*>(aSource);
- const char* end = aSource + aSourceLength;
- while (cp != end) {
- char ch = *cp;
- if (ch >= 'a' && ch <= 'z') {
- *cp = ch - ('a' - 'A');
- }
- ++cp;
- }
- return aSourceLength;
- }
-};
-
-void
ToUpperCase(nsACString& aCString)
{
- ConvertToUpperCase converter;
- char* start;
- converter.write(aCString.BeginWriting(start), aCString.Length());
-}
-
-/**
- * A character sink for copying with case conversion.
- */
-class CopyToUpperCase
-{
-public:
- typedef char value_type;
-
- explicit CopyToUpperCase(nsACString::iterator& aDestIter,
- const nsACString::iterator& aEndIter)
- : mIter(aDestIter)
- , mEnd(aEndIter)
- {
+ char* cp = aCString.BeginWriting();
+ char* end = cp + aCString.Length();
+ while (cp != end) {
+ char ch = *cp;
+ if (ch >= 'a' && ch <= 'z') {
+ *cp = ch - ('a' - 'A');
+ }
+ ++cp;
}
-
- uint32_t
- write(const char* aSource, uint32_t aSourceLength)
- {
- uint32_t len = XPCOM_MIN(uint32_t(mEnd - mIter), aSourceLength);
- char* cp = mIter.get();
- const char* end = aSource + len;
- while (aSource != end) {
- char ch = *aSource;
- if ((ch >= 'a') && (ch <= 'z')) {
- *cp = ch - ('a' - 'A');
- } else {
- *cp = ch;
- }
- ++aSource;
- ++cp;
- }
- mIter.advance(len);
- return len;
- }
-
-protected:
- nsACString::iterator& mIter;
- const nsACString::iterator& mEnd;
-};
+}
void
ToUpperCase(const nsACString& aSource, nsACString& aDest)
{
- nsACString::const_iterator fromBegin, fromEnd;
- nsACString::iterator toBegin, toEnd;
aDest.SetLength(aSource.Length());
-
- CopyToUpperCase converter(aDest.BeginWriting(toBegin), aDest.EndWriting(toEnd));
- copy_string(aSource.BeginReading(fromBegin), aSource.EndReading(fromEnd),
- converter);
+ const char* src = aSource.BeginReading();
+ const char* end = src + aSource.Length();
+ char* dst = aDest.BeginWriting();
+ while (src != end) {
+ char ch = *src;
+ if (ch >= 'a' && ch <= 'z') {
+ *dst = ch - ('a' - 'A');
+ } else {
+ *dst = ch;
+ }
+ ++src;
+ ++dst;
+ }
}
-/**
- * A character sink for case conversion.
- */
-class ConvertToLowerCase
-{
-public:
- typedef char value_type;
-
- uint32_t
- write(const char* aSource, uint32_t aSourceLength)
- {
- char* cp = const_cast<char*>(aSource);
- const char* end = aSource + aSourceLength;
- while (cp != end) {
- char ch = *cp;
- if ((ch >= 'A') && (ch <= 'Z')) {
- *cp = ch + ('a' - 'A');
- }
- ++cp;
- }
- return aSourceLength;
- }
-};
-
void
ToLowerCase(nsACString& aCString)
{
- ConvertToLowerCase converter;
- char* start;
- converter.write(aCString.BeginWriting(start), aCString.Length());
-}
-
-/**
- * A character sink for copying with case conversion.
- */
-class CopyToLowerCase
-{
-public:
- typedef char value_type;
-
- explicit CopyToLowerCase(nsACString::iterator& aDestIter,
- const nsACString::iterator& aEndIter)
- : mIter(aDestIter)
- , mEnd(aEndIter)
- {
+ char* cp = aCString.BeginWriting();
+ char* end = cp + aCString.Length();
+ while (cp != end) {
+ char ch = *cp;
+ if (ch >= 'A' && ch <= 'Z') {
+ *cp = ch + ('a' - 'A');
+ }
+ ++cp;
}
-
- uint32_t
- write(const char* aSource, uint32_t aSourceLength)
- {
- uint32_t len = XPCOM_MIN(uint32_t(mEnd - mIter), aSourceLength);
- char* cp = mIter.get();
- const char* end = aSource + len;
- while (aSource != end) {
- char ch = *aSource;
- if ((ch >= 'A') && (ch <= 'Z')) {
- *cp = ch + ('a' - 'A');
- } else {
- *cp = ch;
- }
- ++aSource;
- ++cp;
- }
- mIter.advance(len);
- return len;
- }
-
-protected:
- nsACString::iterator& mIter;
- const nsACString::iterator& mEnd;
-};
+}
void
ToLowerCase(const nsACString& aSource, nsACString& aDest)
{
- nsACString::const_iterator fromBegin, fromEnd;
- nsACString::iterator toBegin, toEnd;
aDest.SetLength(aSource.Length());
-
- CopyToLowerCase converter(aDest.BeginWriting(toBegin), aDest.EndWriting(toEnd));
- copy_string(aSource.BeginReading(fromBegin), aSource.EndReading(fromEnd),
- converter);
+ const char* src = aSource.BeginReading();
+ const char* end = src + aSource.Length();
+ char* dst = aDest.BeginWriting();
+ while (src != end) {
+ char ch = *src;
+ if (ch >= 'A' && ch <= 'Z') {
+ *dst = ch + ('a' - 'A');
+ } else {
+ *dst = ch;
+ }
+ ++src;
+ ++dst;
+ }
}
bool
ParseString(const nsACString& aSource, char aDelimiter,
nsTArray<nsCString>& aArray)
{
nsACString::const_iterator start, end;
aSource.BeginReading(start);
--- a/xpcom/string/nsReadableUtils.h
+++ b/xpcom/string/nsReadableUtils.h
@@ -83,30 +83,30 @@ ConvertLatin1toUTF16(mozilla::Span<const
/**
* Lone surrogates are replaced with the REPLACEMENT CHARACTER.
*
* The length of aDest must be at least the length of aSource times three _plus one_.
*
* Returns the number of code units written.
*/
inline size_t
-ConvertUTF16toUTF8Func(mozilla::Span<const char16_t> aSource, mozilla::Span<char> aDest)
+ConvertUTF16toUTF8(mozilla::Span<const char16_t> aSource, mozilla::Span<char> aDest)
{
return encoding_mem_convert_utf16_to_utf8(aSource.Elements(), aSource.Length(), aDest.Elements(), aDest.Length());
}
/**
* Malformed byte sequences are replaced with the REPLACEMENT CHARACTER.
*
* The length of aDest must at least one greater than the length of aSource.
*
* Returns the number of code units written.
*/
inline size_t
-ConvertUTF8toUTF16Func(mozilla::Span<const char> aSource, mozilla::Span<char16_t> aDest)
+ConvertUTF8toUTF16(mozilla::Span<const char> aSource, mozilla::Span<char16_t> aDest)
{
return encoding_mem_convert_utf8_to_utf16(aSource.Elements(), aSource.Length(), aDest.Elements(), aDest.Length());
}
inline size_t
Distance(const nsReadingIterator<char16_t>& aStart,
const nsReadingIterator<char16_t>& aEnd)
{
@@ -360,46 +360,16 @@ char16_t* UTF8ToNewUnicode(const nsACStr
* @param aLength the number of 16-bit code units to copy
* @return pointer to destination buffer - identical to |aDest|
*/
char16_t* CopyUnicodeTo(const nsAString& aSource,
uint32_t aSrcOffset,
char16_t* aDest,
uint32_t aLength);
-
-/**
- * Copies 16-bit characters between iterators |aSrcStart| and
- * |aSrcEnd| to the writable string |aDest|. Similar to the
- * |nsString::Mid| method.
- *
- * After this operation |aDest| is not null terminated.
- *
- * @param aSrcStart start source iterator
- * @param aSrcEnd end source iterator
- * @param aDest destination for the copy
- */
-void CopyUnicodeTo(const nsAString::const_iterator& aSrcStart,
- const nsAString::const_iterator& aSrcEnd,
- nsAString& aDest);
-
-/**
- * Appends 16-bit characters between iterators |aSrcStart| and
- * |aSrcEnd| to the writable string |aDest|.
- *
- * After this operation |aDest| is not null terminated.
- *
- * @param aSrcStart start source iterator
- * @param aSrcEnd end source iterator
- * @param aDest destination for the copy
- */
-void AppendUnicodeTo(const nsAString::const_iterator& aSrcStart,
- const nsAString::const_iterator& aSrcEnd,
- nsAString& aDest);
-
/**
* Returns |true| if |aString| contains only ASCII characters, that is, characters in the range (0x00, 0x7F).
*
* @param aString a 16-bit wide string to scan
*/
inline bool IsASCII(mozilla::Span<const char16_t> aString)
{
return encoding_mem_is_basic_latin(aString.Elements(), aString.Length());