forked from mirrors/gecko-dev
Backed out 4 changesets (bug 1358297) for hazard build failures a=backout
Backed out changeset 95211a496191 (bug 1358297) Backed out changeset 3c1b426a5cce (bug 1358297) Backed out changeset 9201d345a1d5 (bug 1358297) Backed out changeset c926817dea60 (bug 1358297) MozReview-Commit-ID: 874DF43K7Dp
This commit is contained in:
parent
72eb995527
commit
6d6d039d43
17 changed files with 61 additions and 605 deletions
|
|
@ -167,7 +167,7 @@ nsDefaultURIFixup::GetFixupURIInfo(const nsACString& aStringURI,
|
|||
nsAutoCString uriString(aStringURI);
|
||||
|
||||
// Eliminate embedded newlines, which single-line text fields now allow:
|
||||
uriString.StripCRLF();
|
||||
uriString.StripChars("\r\n");
|
||||
// Cleanup the empty spaces that might be on each end:
|
||||
uriString.Trim(" ");
|
||||
|
||||
|
|
|
|||
|
|
@ -4780,7 +4780,7 @@ nsDocShell::LoadURIWithOptions(const char16_t* aURI,
|
|||
// Cleanup the empty spaces that might be on each end.
|
||||
uriString.Trim(" ");
|
||||
// Eliminate embedded newlines, which single-line text fields now allow:
|
||||
uriString.StripCRLF();
|
||||
uriString.StripChars("\r\n");
|
||||
NS_ENSURE_TRUE(!uriString.IsEmpty(), NS_ERROR_FAILURE);
|
||||
|
||||
rv = NS_NewURI(getter_AddRefs(uri), uriString);
|
||||
|
|
|
|||
|
|
@ -6684,7 +6684,9 @@ nsContentUtils::FlushLayoutForTree(nsPIDOMWindowOuter* aWindow)
|
|||
|
||||
void nsContentUtils::RemoveNewlines(nsString &aString)
|
||||
{
|
||||
aString.StripCRLF();
|
||||
// strip CR/LF and null
|
||||
static const char badChars[] = {'\r', '\n', 0};
|
||||
aString.StripChars(badChars);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
#include "nsFrameMessageManager.h"
|
||||
|
||||
#include "ContentChild.h"
|
||||
#include "nsASCIIMask.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsDOMClassInfoID.h"
|
||||
#include "nsError.h"
|
||||
|
|
@ -592,7 +591,7 @@ AllowMessage(size_t aDataLength, const nsAString& aMessageName)
|
|||
}
|
||||
|
||||
NS_ConvertUTF16toUTF8 messageName(aMessageName);
|
||||
messageName.StripTaggedASCII(ASCIIMask::Mask0to9());
|
||||
messageName.StripChars("0123456789");
|
||||
|
||||
Telemetry::Accumulate(Telemetry::MESSAGE_MANAGER_MESSAGE_SIZE2, messageName,
|
||||
aDataLength);
|
||||
|
|
@ -678,7 +677,7 @@ nsFrameMessageManager::SendMessage(const nsAString& aMessageName,
|
|||
// NOTE: We need to strip digit characters from the message name in order to
|
||||
// avoid a large number of buckets due to generated names from addons (such
|
||||
// as "ublock:sb:{N}"). See bug 1348113 comment 10.
|
||||
messageName.StripTaggedASCII(ASCIIMask::Mask0to9());
|
||||
messageName.StripChars("0123456789");
|
||||
Telemetry::Accumulate(Telemetry::IPC_SYNC_MESSAGE_MANAGER_LATENCY_MS,
|
||||
messageName, latencyMs);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5345,13 +5345,15 @@ HTMLInputElement::SanitizeValue(nsAString& aValue)
|
|||
case NS_FORM_INPUT_TEL:
|
||||
case NS_FORM_INPUT_PASSWORD:
|
||||
{
|
||||
aValue.StripCRLF();
|
||||
char16_t crlf[] = { char16_t('\r'), char16_t('\n'), 0 };
|
||||
aValue.StripChars(crlf);
|
||||
}
|
||||
break;
|
||||
case NS_FORM_INPUT_EMAIL:
|
||||
case NS_FORM_INPUT_URL:
|
||||
{
|
||||
aValue.StripCRLF();
|
||||
char16_t crlf[] = { char16_t('\r'), char16_t('\n'), 0 };
|
||||
aValue.StripChars(crlf);
|
||||
|
||||
aValue = nsContentUtils::TrimWhitespace<nsContentUtils::IsHTMLWhitespace>(aValue);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -533,7 +533,7 @@ TextEditRules::HandleNewLines(nsString& aString,
|
|||
aString.ReplaceChar(CRLF, ' ');
|
||||
break;
|
||||
case nsIPlaintextEditor::eNewlinesStrip:
|
||||
aString.StripCRLF();
|
||||
aString.StripChars(CRLF);
|
||||
break;
|
||||
case nsIPlaintextEditor::eNewlinesPasteToFirst:
|
||||
default: {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
#include "nsASCIIMask.h"
|
||||
#include "nsURLHelper.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIURLParser.h"
|
||||
|
|
@ -523,7 +522,7 @@ net_ExtractURLScheme(const nsACString &inURI,
|
|||
}
|
||||
|
||||
p.Claim(scheme);
|
||||
scheme.StripTaggedASCII(ASCIIMask::MaskCRLFTab());
|
||||
scheme.StripChars("\r\n\t");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
@ -592,6 +591,8 @@ net_IsAbsoluteURL(const nsACString& uri)
|
|||
void
|
||||
net_FilterURIString(const nsACString& input, nsACString& result)
|
||||
{
|
||||
const char kCharsToStrip[] = "\r\n\t";
|
||||
|
||||
result.Truncate();
|
||||
|
||||
auto start = input.BeginReading();
|
||||
|
|
@ -606,14 +607,9 @@ net_FilterURIString(const nsACString& input, nsACString& result)
|
|||
charFilter).base();
|
||||
|
||||
// Check if chars need to be stripped.
|
||||
bool needsStrip = false;
|
||||
const ASCIIMaskArray& mask = ASCIIMask::MaskCRLFTab();
|
||||
for (auto itr = start; itr != end; ++itr) {
|
||||
if (ASCIIMask::IsMasked(mask, *itr)) {
|
||||
needsStrip = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
auto itr = std::find_first_of(
|
||||
newStart, newEnd, std::begin(kCharsToStrip), std::end(kCharsToStrip));
|
||||
const bool needsStrip = itr != newEnd;
|
||||
|
||||
// Just use the passed in string rather than creating new copies if no
|
||||
// changes are necessary.
|
||||
|
|
@ -624,7 +620,7 @@ net_FilterURIString(const nsACString& input, nsACString& result)
|
|||
|
||||
result.Assign(Substring(newStart, newEnd));
|
||||
if (needsStrip) {
|
||||
result.StripTaggedASCII(mask);
|
||||
result.StripChars(kCharsToStrip);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -518,7 +518,7 @@ nsMIMEHeaderParamImpl::DoParameterInternal(const char *aHeaderValue,
|
|||
// if the parameter spans across multiple lines we have to strip out the
|
||||
// line continuation -- jht 4/29/98
|
||||
nsAutoCString tempStr(valueStart, valueEnd - valueStart);
|
||||
tempStr.StripCRLF();
|
||||
tempStr.StripChars("\r\n");
|
||||
char *res = ToNewCString(tempStr);
|
||||
NS_ENSURE_TRUE(res, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
|
|
@ -761,7 +761,7 @@ internalDecodeRFC2047Header(const char* aHeaderVal, const char* aDefaultCharset,
|
|||
nsAutoCString temp(aResult);
|
||||
temp.ReplaceSubstring("\n\t", " ");
|
||||
temp.ReplaceSubstring("\r\t", " ");
|
||||
temp.StripCRLF();
|
||||
temp.StripChars("\r\n");
|
||||
aResult = temp;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ with Files('**'):
|
|||
BUG_COMPONENT = ('Core', 'String')
|
||||
|
||||
EXPORTS += [
|
||||
'nsASCIIMask.h',
|
||||
'nsAString.h',
|
||||
'nsCharTraits.h',
|
||||
'nsDependentString.h',
|
||||
|
|
@ -39,7 +38,6 @@ EXPORTS += [
|
|||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'nsASCIIMask.cpp',
|
||||
'nsDependentString.cpp',
|
||||
'nsDependentSubstring.cpp',
|
||||
'nsPromiseFlatString.cpp',
|
||||
|
|
|
|||
|
|
@ -1,55 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsASCIIMask.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
constexpr bool TestWhitespace(char c)
|
||||
{
|
||||
return c == '\f' || c == '\t' || c == '\r' || c == '\n' || c == ' ';
|
||||
}
|
||||
constexpr ASCIIMaskArray sWhitespaceMask = CreateASCIIMask(TestWhitespace);
|
||||
|
||||
constexpr bool TestCRLF(char c)
|
||||
{
|
||||
return c == '\r' || c == '\n';
|
||||
}
|
||||
constexpr ASCIIMaskArray sCRLFMask = CreateASCIIMask(TestCRLF);
|
||||
|
||||
constexpr bool TestCRLFTab(char c)
|
||||
{
|
||||
return c == '\r' || c == '\n' || c == '\t';
|
||||
}
|
||||
constexpr ASCIIMaskArray sCRLFTabMask = CreateASCIIMask(TestCRLFTab);
|
||||
|
||||
constexpr bool TestZeroToNine(char c)
|
||||
{
|
||||
return c == '0' || c == '1' || c == '2' || c == '3' || c == '4' ||
|
||||
c == '5' || c == '6' || c == '7' || c == '8' || c == '9';
|
||||
}
|
||||
constexpr ASCIIMaskArray sZeroToNineMask = CreateASCIIMask(TestZeroToNine);
|
||||
|
||||
const ASCIIMaskArray& ASCIIMask::MaskWhitespace()
|
||||
{
|
||||
return sWhitespaceMask;
|
||||
}
|
||||
|
||||
const ASCIIMaskArray& ASCIIMask::MaskCRLF()
|
||||
{
|
||||
return sCRLFMask;
|
||||
}
|
||||
|
||||
const ASCIIMaskArray& ASCIIMask::MaskCRLFTab()
|
||||
{
|
||||
return sCRLFTabMask;
|
||||
}
|
||||
|
||||
const ASCIIMaskArray& ASCIIMask::Mask0to9()
|
||||
{
|
||||
return sZeroToNineMask;
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef nsASCIIMask_h_
|
||||
#define nsASCIIMask_h_
|
||||
|
||||
#include <array>
|
||||
#include "mozilla/IndexSequence.h"
|
||||
|
||||
typedef std::array<bool, 128> ASCIIMaskArray;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
// Boolean arrays, fixed size and filled in at compile time, meant to
|
||||
// record something about each of the (standard) ASCII characters.
|
||||
// No extended ASCII for now, there has been no use case.
|
||||
// If you have loops that go through a string character by character
|
||||
// and test for equality to a certain set of characters before deciding
|
||||
// on a course of action, chances are building up one of these arrays
|
||||
// and using it is going to be faster, especially if the set of
|
||||
// characters is more than one long, and known at compile time.
|
||||
class ASCIIMask
|
||||
{
|
||||
public:
|
||||
// Preset masks for some common character groups
|
||||
// When testing, you must check if the index is < 128 or use IsMasked()
|
||||
//
|
||||
// if (someChar < 128 && MaskCRLF()[someChar]) this is \r or \n
|
||||
|
||||
static const ASCIIMaskArray& MaskCRLF();
|
||||
static const ASCIIMaskArray& Mask0to9();
|
||||
static const ASCIIMaskArray& MaskCRLFTab();
|
||||
static const ASCIIMaskArray& MaskWhitespace();
|
||||
|
||||
static MOZ_ALWAYS_INLINE bool IsMasked(const ASCIIMaskArray& aMask, uint32_t aChar)
|
||||
{
|
||||
return aChar < 128 && aMask[aChar];
|
||||
}
|
||||
};
|
||||
|
||||
// Outside of the preset ones, use these templates to create more masks.
|
||||
//
|
||||
// The example creation will look like this:
|
||||
//
|
||||
// constexpr bool TestABC(char c) { return c == 'A' || c == 'B' || c == 'C'; }
|
||||
// constexpr std::array<bool, 128> sABCMask = CreateASCIIMask(TestABC);
|
||||
// ...
|
||||
// if (someChar < 128 && sABCMask[someChar]) this is A or B or C
|
||||
|
||||
|
||||
namespace details
|
||||
{
|
||||
template<typename F, size_t... Indices>
|
||||
constexpr std::array<bool, 128> CreateASCIIMask(F fun, mozilla::IndexSequence<Indices...>)
|
||||
{
|
||||
return {{ fun(Indices)... }};
|
||||
}
|
||||
} // namespace details
|
||||
|
||||
template<typename F>
|
||||
constexpr std::array<bool, 128> CreateASCIIMask(F fun)
|
||||
{
|
||||
return details::CreateASCIIMask(fun, mozilla::MakeIndexSequence<128>::Type{});
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // nsASCIIMask_h_
|
||||
|
|
@ -540,6 +540,8 @@ StripChars2(char16_t* aString,uint32_t aLength,const char* aSet) {
|
|||
|
||||
/* ***** END RICKG BLOCK ***** */
|
||||
|
||||
static const char* kWhitespace="\f\t\r\n ";
|
||||
|
||||
// This function is used to implement FindCharInSet and friends
|
||||
template <class CharT>
|
||||
#ifndef __SUNPRO_CC
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsTArray.h"
|
||||
#include "nsASCIIMask.h"
|
||||
#include "mozilla/CheckedInt.h"
|
||||
|
||||
/**
|
||||
|
|
@ -402,9 +401,10 @@ nsTString_CharT::SetCharAt( char16_t aChar, uint32_t aIndex )
|
|||
void
|
||||
nsTString_CharT::StripChars( const char* aSet )
|
||||
{
|
||||
if (!StripChars(aSet, mozilla::fallible)) {
|
||||
if (!EnsureMutable())
|
||||
AllocFailed(mLength);
|
||||
}
|
||||
|
||||
mLength = nsBufferRoutines<CharT>::strip_chars(mData, mLength, aSet);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
@ -421,20 +421,13 @@ nsTString_CharT::StripChars( const char* aSet, const fallible_t& )
|
|||
void
|
||||
nsTString_CharT::StripWhitespace()
|
||||
{
|
||||
if (!StripWhitespace(mozilla::fallible)) {
|
||||
AllocFailed(mLength);
|
||||
}
|
||||
StripChars(kWhitespace);
|
||||
}
|
||||
|
||||
bool
|
||||
nsTString_CharT::StripWhitespace( const fallible_t& )
|
||||
nsTString_CharT::StripWhitespace(const fallible_t& aFallible)
|
||||
{
|
||||
if (!EnsureMutable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
StripTaggedASCII(mozilla::ASCIIMask::MaskWhitespace());
|
||||
return true;
|
||||
return StripChars(kWhitespace, aFallible);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -673,50 +666,19 @@ nsTString_CharT::Trim( const char* aSet, bool aTrimLeading, bool aTrimTrailing,
|
|||
|
||||
|
||||
/**
|
||||
* nsTString::CompressWhitespace.
|
||||
* nsTString::CompressWhitespace
|
||||
*/
|
||||
|
||||
void
|
||||
nsTString_CharT::CompressWhitespace( bool aTrimLeading, bool aTrimTrailing )
|
||||
{
|
||||
// Quick exit
|
||||
if (mLength == 0) {
|
||||
return;
|
||||
}
|
||||
const char* set = kWhitespace;
|
||||
|
||||
if (!EnsureMutable())
|
||||
AllocFailed(mLength);
|
||||
ReplaceChar(set, ' ');
|
||||
Trim(set, aTrimLeading, aTrimTrailing);
|
||||
|
||||
const ASCIIMaskArray& mask = mozilla::ASCIIMask::MaskWhitespace();
|
||||
|
||||
char_type* to = mData;
|
||||
char_type* from = mData;
|
||||
char_type* end = mData + mLength;
|
||||
|
||||
// Compresses runs of whitespace down to a normal space ' ' and convert
|
||||
// any whitespace to a normal space. This assumes that whitespace is
|
||||
// all standard 7-bit ASCII.
|
||||
bool skipWS = aTrimLeading;
|
||||
while (from < end) {
|
||||
uint32_t theChar = *from++;
|
||||
if (mozilla::ASCIIMask::IsMasked(mask, theChar)) {
|
||||
if (!skipWS) {
|
||||
*to++ = ' ';
|
||||
skipWS = true;
|
||||
}
|
||||
} else {
|
||||
*to++ = theChar;
|
||||
skipWS = false;
|
||||
}
|
||||
}
|
||||
|
||||
// If we need to trim the trailing whitespace, back up one character.
|
||||
if (aTrimTrailing && skipWS && to > mData) {
|
||||
to--;
|
||||
}
|
||||
|
||||
*to = char_type(0); // add the null
|
||||
mLength = to - mData;
|
||||
// this one does some questionable fu... just copying the old code!
|
||||
mLength = nsBufferRoutines<char_type>::compress_chars(mData, mLength, set);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsASCIIMask.h"
|
||||
#include "mozilla/CheckedInt.h"
|
||||
#include "mozilla/double-conversion.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
|
|
@ -882,8 +881,7 @@ nsTStringRepr_CharT::FindChar(char_type aChar, index_type aOffset) const
|
|||
void
|
||||
nsTSubstring_CharT::StripChar(char_type aChar, int32_t aOffset)
|
||||
{
|
||||
// Note that this implicitly guarantees mLength > 0
|
||||
if (aOffset >= int32_t(mLength)) {
|
||||
if (mLength == 0 || aOffset >= int32_t(mLength)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -910,7 +908,6 @@ nsTSubstring_CharT::StripChar(char_type aChar, int32_t aOffset)
|
|||
void
|
||||
nsTSubstring_CharT::StripChars(const char_type* aChars, uint32_t aOffset)
|
||||
{
|
||||
// Note that this implicitly guarantees mLength > 0
|
||||
if (aOffset >= uint32_t(mLength)) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -940,45 +937,6 @@ nsTSubstring_CharT::StripChars(const char_type* aChars, uint32_t aOffset)
|
|||
mLength = to - mData;
|
||||
}
|
||||
|
||||
void
|
||||
nsTSubstring_CharT::StripTaggedASCII(const ASCIIMaskArray& aToStrip,
|
||||
uint32_t aOffset)
|
||||
{
|
||||
// Note that this implicitly guarantees mLength > 0
|
||||
if (aOffset >= uint32_t(mLength)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnsureMutable()) {
|
||||
AllocFailed(mLength);
|
||||
}
|
||||
|
||||
char_type* to = mData + aOffset;
|
||||
char_type* from = mData + aOffset;
|
||||
char_type* end = mData + mLength;
|
||||
|
||||
while (from < end) {
|
||||
uint32_t theChar = (uint32_t)*from++;
|
||||
// Replacing this with a call to ASCIIMask::IsMasked
|
||||
// regresses performance somewhat, so leaving it inlined.
|
||||
if (!mozilla::ASCIIMask::IsMasked(aToStrip, theChar)) {
|
||||
// Not stripped, copy this char.
|
||||
*to++ = (char_type)theChar;
|
||||
}
|
||||
}
|
||||
*to = char_type(0); // add the null
|
||||
mLength = to - mData;
|
||||
}
|
||||
|
||||
void
|
||||
nsTSubstring_CharT::StripCRLF(uint32_t aOffset)
|
||||
{
|
||||
// Expanding this call to copy the code from StripTaggedASCII
|
||||
// instead of just calling it does somewhat help with performance
|
||||
// but it is not worth it given the duplicated code.
|
||||
StripTaggedASCII(mozilla::ASCIIMask::MaskCRLF(), aOffset);
|
||||
}
|
||||
|
||||
struct MOZ_STACK_CLASS PrintfAppend_CharT : public mozilla::PrintfTarget
|
||||
{
|
||||
explicit PrintfAppend_CharT(nsTSubstring_CharT* aString)
|
||||
|
|
|
|||
|
|
@ -1014,31 +1014,6 @@ public:
|
|||
|
||||
void StripChars(const char_type* aChars, uint32_t aOffset = 0);
|
||||
|
||||
/**
|
||||
* This method is used to remove all occurrences of some characters this
|
||||
* from this string. The characters removed have the corresponding
|
||||
* entries in the bool array set to true; we retain all characters
|
||||
* with code beyond 127.
|
||||
* THE CALLER IS RESPONSIBLE for making sure the complete boolean
|
||||
* array, 128 entries, is properly initialized.
|
||||
*
|
||||
* See also: ASCIIMask class.
|
||||
*
|
||||
* @param aToStrip -- Array where each entry is true if the
|
||||
* corresponding ASCII character is to be stripped. All
|
||||
* characters beyond code 127 are retained. Note that this
|
||||
* parameter is of ASCIIMaskArray type, but we expand the typedef
|
||||
* to avoid having to include nsASCIIMask.h in this include file
|
||||
* as it brings other includes.
|
||||
* @param aOffset -- where in this string to start stripping chars
|
||||
*/
|
||||
void StripTaggedASCII(const std::array<bool, 128>& aToStrip, uint32_t aOffset = 0);
|
||||
|
||||
/**
|
||||
* A shortcut to strip \r and \n.
|
||||
*/
|
||||
void StripCRLF(uint32_t aOffset = 0);
|
||||
|
||||
/**
|
||||
* If the string uses a shared buffer, this method
|
||||
* clears the pointer without releasing the buffer.
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "nsASCIIMask.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStringBuffer.h"
|
||||
#include "nsReadableUtils.h"
|
||||
|
|
@ -15,7 +14,6 @@
|
|||
#include "mozilla/Unused.h"
|
||||
#include "nsTArray.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "gtest/MozGTestBench.h" // For MOZ_GTEST_BENCH
|
||||
|
||||
namespace TestStrings {
|
||||
|
||||
|
|
@ -278,22 +276,6 @@ TEST(Strings, trim)
|
|||
nsCString s(text);
|
||||
s.Trim(set);
|
||||
EXPECT_STREQ(s.get(), "a");
|
||||
|
||||
s.AssignLiteral("\t \t\t \t");
|
||||
s.Trim(set);
|
||||
EXPECT_STREQ(s.get(), "");
|
||||
|
||||
s.AssignLiteral(" ");
|
||||
s.Trim(set);
|
||||
EXPECT_STREQ(s.get(), "");
|
||||
|
||||
s.AssignLiteral(" ");
|
||||
s.Trim(set, false, true);
|
||||
EXPECT_STREQ(s.get(), "");
|
||||
|
||||
s.AssignLiteral(" ");
|
||||
s.Trim(set, true, false);
|
||||
EXPECT_STREQ(s.get(), "");
|
||||
}
|
||||
|
||||
TEST(Strings, replace_substr)
|
||||
|
|
@ -303,16 +285,16 @@ TEST(Strings, replace_substr)
|
|||
s.ReplaceSubstring("ppp", "www");
|
||||
EXPECT_STREQ(s.get(), "abc-www-qqq-www-xyz");
|
||||
|
||||
s.AssignLiteral("foobar");
|
||||
s.Assign("foobar");
|
||||
s.ReplaceSubstring("foo", "bar");
|
||||
s.ReplaceSubstring("bar", "");
|
||||
EXPECT_STREQ(s.get(), "");
|
||||
|
||||
s.AssignLiteral("foofoofoo");
|
||||
s.Assign("foofoofoo");
|
||||
s.ReplaceSubstring("foo", "foo");
|
||||
EXPECT_STREQ(s.get(), "foofoofoo");
|
||||
|
||||
s.AssignLiteral("foofoofoo");
|
||||
s.Assign("foofoofoo");
|
||||
s.ReplaceSubstring("of", "fo");
|
||||
EXPECT_STREQ(s.get(), "fofoofooo");
|
||||
}
|
||||
|
|
@ -338,86 +320,77 @@ TEST(Strings, replace_substr_2)
|
|||
TEST(Strings, replace_substr_3)
|
||||
{
|
||||
nsCString s;
|
||||
s.AssignLiteral("abcabcabc");
|
||||
s.Assign("abcabcabc");
|
||||
s.ReplaceSubstring("ca", "X");
|
||||
EXPECT_STREQ(s.get(), "abXbXbc");
|
||||
|
||||
s.AssignLiteral("abcabcabc");
|
||||
s.Assign("abcabcabc");
|
||||
s.ReplaceSubstring("ca", "XYZ");
|
||||
EXPECT_STREQ(s.get(), "abXYZbXYZbc");
|
||||
|
||||
s.AssignLiteral("abcabcabc");
|
||||
s.Assign("abcabcabc");
|
||||
s.ReplaceSubstring("ca", "XY");
|
||||
EXPECT_STREQ(s.get(), "abXYbXYbc");
|
||||
|
||||
s.AssignLiteral("abcabcabc");
|
||||
s.Assign("abcabcabc");
|
||||
s.ReplaceSubstring("ca", "XYZ!");
|
||||
EXPECT_STREQ(s.get(), "abXYZ!bXYZ!bc");
|
||||
|
||||
s.AssignLiteral("abcdabcdabcd");
|
||||
s.Assign("abcdabcdabcd");
|
||||
s.ReplaceSubstring("bcd", "X");
|
||||
EXPECT_STREQ(s.get(), "aXaXaX");
|
||||
|
||||
s.AssignLiteral("abcdabcdabcd");
|
||||
s.Assign("abcdabcdabcd");
|
||||
s.ReplaceSubstring("bcd", "XYZ!");
|
||||
EXPECT_STREQ(s.get(), "aXYZ!aXYZ!aXYZ!");
|
||||
|
||||
s.AssignLiteral("abcdabcdabcd");
|
||||
s.Assign("abcdabcdabcd");
|
||||
s.ReplaceSubstring("bcd", "XY");
|
||||
EXPECT_STREQ(s.get(), "aXYaXYaXY");
|
||||
|
||||
s.AssignLiteral("abcdabcdabcd");
|
||||
s.Assign("abcdabcdabcd");
|
||||
s.ReplaceSubstring("bcd", "XYZABC");
|
||||
EXPECT_STREQ(s.get(), "aXYZABCaXYZABCaXYZABC");
|
||||
|
||||
s.AssignLiteral("abcdabcdabcd");
|
||||
s.Assign("abcdabcdabcd");
|
||||
s.ReplaceSubstring("bcd", "XYZ");
|
||||
EXPECT_STREQ(s.get(), "aXYZaXYZaXYZ");
|
||||
|
||||
s.AssignLiteral("abcdabcdabcd");
|
||||
s.Assign("abcdabcdabcd");
|
||||
s.ReplaceSubstring("bcd", "XYZ!");
|
||||
EXPECT_STREQ(s.get(), "aXYZ!aXYZ!aXYZ!");
|
||||
|
||||
s.AssignLiteral("abcdabcdabcd");
|
||||
s.Assign("abcdabcdabcd");
|
||||
s.ReplaceSubstring("ab", "X");
|
||||
EXPECT_STREQ(s.get(), "XcdXcdXcd");
|
||||
|
||||
s.AssignLiteral("abcdabcdabcd");
|
||||
s.Assign("abcdabcdabcd");
|
||||
s.ReplaceSubstring("ab", "XYZABC");
|
||||
EXPECT_STREQ(s.get(), "XYZABCcdXYZABCcdXYZABCcd");
|
||||
|
||||
s.AssignLiteral("abcdabcdabcd");
|
||||
s.Assign("abcdabcdabcd");
|
||||
s.ReplaceSubstring("ab", "XY");
|
||||
EXPECT_STREQ(s.get(), "XYcdXYcdXYcd");
|
||||
|
||||
s.AssignLiteral("abcdabcdabcd");
|
||||
s.Assign("abcdabcdabcd");
|
||||
s.ReplaceSubstring("ab", "XYZ!");
|
||||
EXPECT_STREQ(s.get(), "XYZ!cdXYZ!cdXYZ!cd");
|
||||
|
||||
s.AssignLiteral("abcdabcdabcd");
|
||||
s.Assign("abcdabcdabcd");
|
||||
s.ReplaceSubstring("notfound", "X");
|
||||
EXPECT_STREQ(s.get(), "abcdabcdabcd");
|
||||
|
||||
s.AssignLiteral("abcdabcdabcd");
|
||||
s.Assign("abcdabcdabcd");
|
||||
s.ReplaceSubstring("notfound", "longlongstring");
|
||||
EXPECT_STREQ(s.get(), "abcdabcdabcd");
|
||||
}
|
||||
|
||||
TEST(Strings, strip_ws)
|
||||
{
|
||||
const char* texts[] = {"",
|
||||
" a $ ",
|
||||
"Some\fother\t thing\r\n",
|
||||
"And \f\t\r\n even\nmore\r \f"};
|
||||
const char* results[] = {"",
|
||||
"a$",
|
||||
"Someotherthing",
|
||||
"Andevenmore"};
|
||||
for (size_t i=0; i<sizeof(texts)/sizeof(texts[0]); i++) {
|
||||
nsCString s(texts[i]);
|
||||
s.StripWhitespace();
|
||||
EXPECT_STREQ(s.get(), results[i]);
|
||||
}
|
||||
const char text[] = " a $ ";
|
||||
nsCString s(text);
|
||||
s.StripWhitespace();
|
||||
EXPECT_STREQ(s.get(), "a$");
|
||||
}
|
||||
|
||||
TEST(Strings, equals_ic)
|
||||
|
|
@ -672,7 +645,7 @@ TEST(Strings, rfindcharinset)
|
|||
index = buf.RFindCharInSet("l", 5);
|
||||
EXPECT_EQ(index, 3);
|
||||
|
||||
buf.AssignLiteral("abcdefghijkabc");
|
||||
buf.Assign("abcdefghijkabc");
|
||||
|
||||
index = buf.RFindCharInSet("ab");
|
||||
EXPECT_EQ(index, 12);
|
||||
|
|
@ -1089,290 +1062,4 @@ TEST(Strings, Split)
|
|||
EXPECT_EQ(counter, (size_t)2);
|
||||
}
|
||||
|
||||
constexpr bool TestSomeChars(char c)
|
||||
{
|
||||
return c == 'a' || c == 'c' || c == 'e' || c == '7' ||
|
||||
c == 'G' || c == 'Z' || c == '\b' || c == '?';
|
||||
}
|
||||
TEST(Strings,ASCIIMask)
|
||||
{
|
||||
const ASCIIMaskArray& maskCRLF = mozilla::ASCIIMask::MaskCRLF();
|
||||
EXPECT_TRUE(maskCRLF['\n'] && mozilla::ASCIIMask::IsMasked(maskCRLF, '\n'));
|
||||
EXPECT_TRUE(maskCRLF['\r'] && mozilla::ASCIIMask::IsMasked(maskCRLF, '\r'));
|
||||
EXPECT_FALSE(maskCRLF['g'] || mozilla::ASCIIMask::IsMasked(maskCRLF, 'g'));
|
||||
EXPECT_FALSE(maskCRLF[' '] || mozilla::ASCIIMask::IsMasked(maskCRLF, ' '));
|
||||
EXPECT_FALSE(maskCRLF['\0'] || mozilla::ASCIIMask::IsMasked(maskCRLF, '\0'));
|
||||
EXPECT_FALSE(mozilla::ASCIIMask::IsMasked(maskCRLF, 14324));
|
||||
|
||||
const ASCIIMaskArray& mask0to9 = mozilla::ASCIIMask::Mask0to9();
|
||||
EXPECT_TRUE(mask0to9['9'] && mozilla::ASCIIMask::IsMasked(mask0to9, '9'));
|
||||
EXPECT_TRUE(mask0to9['0'] && mozilla::ASCIIMask::IsMasked(mask0to9, '0'));
|
||||
EXPECT_TRUE(mask0to9['4'] && mozilla::ASCIIMask::IsMasked(mask0to9, '4'));
|
||||
EXPECT_FALSE(mask0to9['g'] || mozilla::ASCIIMask::IsMasked(mask0to9, 'g'));
|
||||
EXPECT_FALSE(mask0to9[' '] || mozilla::ASCIIMask::IsMasked(mask0to9, ' '));
|
||||
EXPECT_FALSE(mask0to9['\n'] || mozilla::ASCIIMask::IsMasked(mask0to9, '\n'));
|
||||
EXPECT_FALSE(mask0to9['\0'] || mozilla::ASCIIMask::IsMasked(mask0to9, '\0'));
|
||||
EXPECT_FALSE(mozilla::ASCIIMask::IsMasked(maskCRLF, 14324));
|
||||
|
||||
const ASCIIMaskArray& maskWS = mozilla::ASCIIMask::MaskWhitespace();
|
||||
EXPECT_TRUE(maskWS[' '] && mozilla::ASCIIMask::IsMasked(maskWS, ' '));
|
||||
EXPECT_TRUE(maskWS['\t'] && mozilla::ASCIIMask::IsMasked(maskWS, '\t'));
|
||||
EXPECT_FALSE(maskWS['8'] || mozilla::ASCIIMask::IsMasked(maskWS, '8'));
|
||||
EXPECT_FALSE(maskWS['\0'] || mozilla::ASCIIMask::IsMasked(maskWS, '\0'));
|
||||
EXPECT_FALSE(mozilla::ASCIIMask::IsMasked(maskCRLF, 14324));
|
||||
|
||||
constexpr ASCIIMaskArray maskSome = mozilla::CreateASCIIMask(TestSomeChars);
|
||||
EXPECT_TRUE(maskSome['a'] && mozilla::ASCIIMask::IsMasked(maskSome, 'a'));
|
||||
EXPECT_TRUE(maskSome['c'] && mozilla::ASCIIMask::IsMasked(maskSome, 'c'));
|
||||
EXPECT_TRUE(maskSome['e'] && mozilla::ASCIIMask::IsMasked(maskSome, 'e'));
|
||||
EXPECT_TRUE(maskSome['7'] && mozilla::ASCIIMask::IsMasked(maskSome, '7'));
|
||||
EXPECT_TRUE(maskSome['G'] && mozilla::ASCIIMask::IsMasked(maskSome, 'G'));
|
||||
EXPECT_TRUE(maskSome['Z'] && mozilla::ASCIIMask::IsMasked(maskSome, 'Z'));
|
||||
EXPECT_TRUE(maskSome['\b'] && mozilla::ASCIIMask::IsMasked(maskSome, '\b'));
|
||||
EXPECT_TRUE(maskSome['?'] && mozilla::ASCIIMask::IsMasked(maskSome, '?'));
|
||||
EXPECT_FALSE(maskSome['8'] || mozilla::ASCIIMask::IsMasked(maskSome, '8'));
|
||||
EXPECT_FALSE(maskSome['\0'] || mozilla::ASCIIMask::IsMasked(maskSome, '\0'));
|
||||
EXPECT_FALSE(mozilla::ASCIIMask::IsMasked(maskCRLF, 14324));
|
||||
}
|
||||
|
||||
template <typename T> void
|
||||
CompressWhitespaceHelper()
|
||||
{
|
||||
T s;
|
||||
s.AssignLiteral("abcabcabc");
|
||||
s.CompressWhitespace(true, true);
|
||||
EXPECT_TRUE(s.EqualsLiteral("abcabcabc"));
|
||||
|
||||
s.AssignLiteral(" \n\rabcabcabc\r\n");
|
||||
s.CompressWhitespace(true, true);
|
||||
EXPECT_TRUE(s.EqualsLiteral("abcabcabc"));
|
||||
|
||||
s.AssignLiteral(" \n\rabc abc abc\r\n");
|
||||
s.CompressWhitespace(true, true);
|
||||
EXPECT_TRUE(s.EqualsLiteral("abc abc abc"));
|
||||
|
||||
s.AssignLiteral(" \n\rabc\r abc\n abc\r\n");
|
||||
s.CompressWhitespace(true, true);
|
||||
EXPECT_TRUE(s.EqualsLiteral("abc abc abc"));
|
||||
|
||||
s.AssignLiteral(" \n\rabc\r \nabc\n \rabc\r\n");
|
||||
s.CompressWhitespace(true, true);
|
||||
EXPECT_TRUE(s.EqualsLiteral("abc abc abc"));
|
||||
|
||||
s.AssignLiteral(" \n\rabc\r abc\n abc\r\n");
|
||||
s.CompressWhitespace(false, true);
|
||||
EXPECT_TRUE(s.EqualsLiteral(" abc abc abc"));
|
||||
|
||||
s.AssignLiteral(" \n\rabc\r abc\n abc\r\n");
|
||||
s.CompressWhitespace(true, false);
|
||||
EXPECT_TRUE(s.EqualsLiteral("abc abc abc "));
|
||||
|
||||
s.AssignLiteral(" \n\rabc\r abc\n abc\r\n");
|
||||
s.CompressWhitespace(false, false);
|
||||
EXPECT_TRUE(s.EqualsLiteral(" abc abc abc "));
|
||||
|
||||
s.AssignLiteral(" \r\n ");
|
||||
s.CompressWhitespace(true, true);
|
||||
EXPECT_TRUE(s.EqualsLiteral(""));
|
||||
|
||||
s.AssignLiteral(" \r\n \t");
|
||||
s.CompressWhitespace(true, true);
|
||||
EXPECT_TRUE(s.EqualsLiteral(""));
|
||||
|
||||
s.AssignLiteral("\n \r\n \t");
|
||||
s.CompressWhitespace(false, false);
|
||||
EXPECT_TRUE(s.EqualsLiteral(" "));
|
||||
|
||||
s.AssignLiteral("\n \r\n \t");
|
||||
s.CompressWhitespace(false, true);
|
||||
EXPECT_TRUE(s.EqualsLiteral(""));
|
||||
|
||||
s.AssignLiteral("\n \r\n \t");
|
||||
s.CompressWhitespace(true, false);
|
||||
EXPECT_TRUE(s.EqualsLiteral(""));
|
||||
|
||||
s.AssignLiteral("");
|
||||
s.CompressWhitespace(false, false);
|
||||
EXPECT_TRUE(s.EqualsLiteral(""));
|
||||
|
||||
s.AssignLiteral("");
|
||||
s.CompressWhitespace(false, true);
|
||||
EXPECT_TRUE(s.EqualsLiteral(""));
|
||||
|
||||
s.AssignLiteral("");
|
||||
s.CompressWhitespace(true, false);
|
||||
EXPECT_TRUE(s.EqualsLiteral(""));
|
||||
|
||||
s.AssignLiteral("");
|
||||
s.CompressWhitespace(true, true);
|
||||
EXPECT_TRUE(s.EqualsLiteral(""));
|
||||
}
|
||||
|
||||
TEST(Strings, CompressWhitespace)
|
||||
{
|
||||
CompressWhitespaceHelper<nsCString>();
|
||||
}
|
||||
|
||||
TEST(Strings, CompressWhitespaceW)
|
||||
{
|
||||
CompressWhitespaceHelper<nsString>();
|
||||
|
||||
nsString str, result;
|
||||
str.AssignLiteral(u"\u263A is\r\n ;-)");
|
||||
result.AssignLiteral(u"\u263A is ;-)");
|
||||
str.CompressWhitespace(true, true);
|
||||
EXPECT_TRUE(str == result);
|
||||
}
|
||||
|
||||
template <typename T> void
|
||||
StripCRLFHelper()
|
||||
{
|
||||
T s;
|
||||
s.AssignLiteral("abcabcabc");
|
||||
s.StripCRLF();
|
||||
EXPECT_TRUE(s.EqualsLiteral("abcabcabc"));
|
||||
|
||||
s.AssignLiteral(" \n\rabcabcabc\r\n");
|
||||
s.StripCRLF();
|
||||
EXPECT_TRUE(s.EqualsLiteral(" abcabcabc"));
|
||||
|
||||
s.AssignLiteral(" \n\rabc abc abc\r\n");
|
||||
s.StripCRLF();
|
||||
EXPECT_TRUE(s.EqualsLiteral(" abc abc abc"));
|
||||
|
||||
s.AssignLiteral(" \n\rabc\r abc\n abc\r\n");
|
||||
s.StripCRLF();
|
||||
EXPECT_TRUE(s.EqualsLiteral(" abc abc abc"));
|
||||
|
||||
s.AssignLiteral(" \n\rabc\r \nabc\n \rabc\r\n");
|
||||
s.StripCRLF();
|
||||
EXPECT_TRUE(s.EqualsLiteral(" abc abc abc"));
|
||||
|
||||
s.AssignLiteral(" \n\rabc\r abc\n abc\r\n");
|
||||
s.StripCRLF();
|
||||
EXPECT_TRUE(s.EqualsLiteral(" abc abc abc"));
|
||||
|
||||
s.AssignLiteral(" \r\n ");
|
||||
s.StripCRLF();
|
||||
EXPECT_TRUE(s.EqualsLiteral(" "));
|
||||
|
||||
s.AssignLiteral(" \r\n \t");
|
||||
s.StripCRLF();
|
||||
EXPECT_TRUE(s.EqualsLiteral(" \t"));
|
||||
|
||||
s.AssignLiteral("\n \r\n \t");
|
||||
s.StripCRLF();
|
||||
EXPECT_TRUE(s.EqualsLiteral(" \t"));
|
||||
|
||||
s.AssignLiteral("");
|
||||
s.StripCRLF();
|
||||
EXPECT_TRUE(s.EqualsLiteral(""));
|
||||
}
|
||||
|
||||
TEST(Strings, StripCRLF)
|
||||
{
|
||||
StripCRLFHelper<nsCString>();
|
||||
}
|
||||
|
||||
TEST(Strings, StripCRLFW)
|
||||
{
|
||||
StripCRLFHelper<nsString>();
|
||||
|
||||
nsString str, result;
|
||||
str.AssignLiteral(u"\u263A is\r\n ;-)");
|
||||
result.AssignLiteral(u"\u263A is ;-)");
|
||||
str.StripCRLF();
|
||||
EXPECT_TRUE(str == result);
|
||||
}
|
||||
|
||||
#define TestExample1 "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium,\n totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi\r architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur\n aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui\r\n\r dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
|
||||
|
||||
#define TestExample2 "At vero eos et accusamus et iusto odio dignissimos ducimus\n\n qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt\r\r \n mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."
|
||||
|
||||
#define TestExample3 " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis ac tellus eget velit viverra viverra id sit amet neque. Sed id consectetur mi, vestibulum aliquet arcu. Curabitur sagittis accumsan convallis. Sed eu condimentum ipsum, a laoreet tortor. Orci varius natoque penatibus et magnis dis \r\r\n\n parturient montes, nascetur ridiculus mus. Sed non tellus nec ante sodales placerat a nec risus. Cras vel bibendum sapien, nec ullamcorper felis. Pellentesque congue eget nisi sit amet vehicula. Morbi pulvinar turpis justo, in commodo dolor vulputate id. Curabitur in dui urna. Vestibulum placerat dui in sem congue, ut faucibus nibh rutrum. Duis mattis turpis facilisis ullamcorper tincidunt. Vestibulum pharetra tortor at enim sagittis, dapibus consectetur ex blandit. Curabitur ac fringilla quam. In ornare lectus ut ipsum mattis venenatis. Etiam in mollis lectus, sed luctus risus.\nCras dapibus\f\t \n finibus justo sit amet dictum. Aliquam non elit diam. Fusce magna nulla, bibendum in massa a, commodo finibus lectus. Sed rutrum a augue id imperdiet. Aliquam sagittis sodales felis, a tristique ligula. Aliquam erat volutpat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Duis volutpat interdum lorem et congue. Phasellus porttitor posuere justo eget euismod. Nam a condimentum turpis, sit amet gravida lacus. Vestibulum dolor diam, lobortis ac metus et, convallis dapibus tellus. Ut nec metus in velit malesuada tincidunt et eget justo. Curabitur ut libero bibendum, porttitor diam vitae, aliquet justo. "
|
||||
|
||||
#define TestExample4 " Donec feugiat volutpat massa. Cras ornare lacinia porta. Fusce in feugiat nunc. Praesent non felis varius diam feugiat ultrices ultricies a risus. Donec maximus nisi nisl, non consectetur nulla eleifend in. Nulla in massa interdum, eleifend orci a, vestibulum est. Mauris aliquet, massa et convallis mollis, felis augue vestibulum augue, in lobortis metus eros a quam. Nam ac diam ornare, vestibulum elit sit amet, consectetur ante. Praesent massa mauris, pulvinar sit amet sapien vel, tempus gravida neque. Praesent id quam sit amet est maximus molestie eget at turpis. Nunc sit amet orci id arcu dapibus fermentum non eu erat.\f\tSuspendisse commodo nunc sem, eu congue eros condimentum vel. Nullam sit amet posuere arcu. Nulla facilisi. Mauris dapibus iaculis massa sed gravida. Nullam vitae urna at tortor feugiat auctor ut sit amet dolor. Proin rutrum at nunc et faucibus. Quisque suscipit id nibh a aliquet. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam a dapibus erat, id imperdiet mauris. Nulla blandit libero non magna dapibus tristique. Integer hendrerit imperdiet lorem, quis facilisis lacus semper ut. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae Nullam dignissim elit in congue ultricies. Quisque erat odio, maximus mollis laoreet id, iaculis at turpis. "
|
||||
|
||||
#define TestExample5 "Donec id risus urna. Nunc consequat lacinia urna id bibendum. Nulla faucibus faucibus enim. Cras ex risus, ultrices id semper vitae, luctus ut nulla. Sed vehicula tellus sed purus imperdiet efficitur. Suspendisse feugiat\n\n\n imperdiet odio, sed porta lorem feugiat nec. Curabitur laoreet massa venenatis\r\n risus ornare\r\n, vitae feugiat tortor accumsan. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas id scelerisque mauris, eget facilisis erat. Ut nec pulvinar risus, sed iaculis ante. Mauris tincidunt, risus et pretium elementum, leo nisi consectetur ligula, tincidunt suscipit erat velit eget libero. Sed ac est tempus, consequat dolor mattis, mattis mi. "
|
||||
|
||||
// Note the five calls in the loop, so divide by 100k
|
||||
MOZ_GTEST_BENCH(Strings, PerfStripWhitespace, [] {
|
||||
nsCString test1(TestExample1);
|
||||
nsCString test2(TestExample2);
|
||||
nsCString test3(TestExample3);
|
||||
nsCString test4(TestExample4);
|
||||
nsCString test5(TestExample5);
|
||||
for (int i = 0; i < 20000; i++) {
|
||||
test1.StripWhitespace();
|
||||
test2.StripWhitespace();
|
||||
test3.StripWhitespace();
|
||||
test4.StripWhitespace();
|
||||
test5.StripWhitespace();
|
||||
}
|
||||
});
|
||||
|
||||
MOZ_GTEST_BENCH(Strings, PerfStripCharsWhitespace, [] {
|
||||
// This is the unoptimized (original) version of
|
||||
// StripWhitespace using StripChars.
|
||||
nsCString test1(TestExample1);
|
||||
nsCString test2(TestExample2);
|
||||
nsCString test3(TestExample3);
|
||||
nsCString test4(TestExample4);
|
||||
nsCString test5(TestExample5);
|
||||
for (int i = 0; i < 20000; i++) {
|
||||
test1.StripChars("\f\t\r\n ");
|
||||
test2.StripChars("\f\t\r\n ");
|
||||
test3.StripChars("\f\t\r\n ");
|
||||
test4.StripChars("\f\t\r\n ");
|
||||
test5.StripChars("\f\t\r\n ");
|
||||
}
|
||||
});
|
||||
|
||||
MOZ_GTEST_BENCH(Strings, PerfCompressWhitespace, [] {
|
||||
nsCString test1(TestExample1);
|
||||
nsCString test2(TestExample2);
|
||||
nsCString test3(TestExample3);
|
||||
nsCString test4(TestExample4);
|
||||
nsCString test5(TestExample5);
|
||||
for (int i = 0; i < 20000; i++) {
|
||||
test1.CompressWhitespace();
|
||||
test2.CompressWhitespace();
|
||||
test3.CompressWhitespace();
|
||||
test4.CompressWhitespace();
|
||||
test5.CompressWhitespace();
|
||||
}
|
||||
});
|
||||
|
||||
MOZ_GTEST_BENCH(Strings, PerfStripCRLF, [] {
|
||||
nsCString test1(TestExample1);
|
||||
nsCString test2(TestExample2);
|
||||
nsCString test3(TestExample3);
|
||||
nsCString test4(TestExample4);
|
||||
nsCString test5(TestExample5);
|
||||
for (int i = 0; i < 20000; i++) {
|
||||
test1.StripCRLF();
|
||||
test2.StripCRLF();
|
||||
test3.StripCRLF();
|
||||
test4.StripCRLF();
|
||||
test5.StripCRLF();
|
||||
}
|
||||
});
|
||||
|
||||
MOZ_GTEST_BENCH(Strings, PerfStripCharsCRLF, [] {
|
||||
// This is the unoptimized (original) version of
|
||||
// stripping \r\n using StripChars.
|
||||
nsCString test1(TestExample1);
|
||||
nsCString test2(TestExample2);
|
||||
nsCString test3(TestExample3);
|
||||
nsCString test4(TestExample4);
|
||||
nsCString test5(TestExample5);
|
||||
for (int i = 0; i < 20000; i++) {
|
||||
test1.StripChars("\r\n");
|
||||
test2.StripChars("\r\n");
|
||||
test3.StripChars("\r\n");
|
||||
test4.StripChars("\r\n");
|
||||
test5.StripChars("\r\n");
|
||||
}
|
||||
});
|
||||
|
||||
} // namespace TestStrings
|
||||
|
|
|
|||
|
|
@ -915,7 +915,7 @@ NS_IMETHODIMP nsXULWindow::SetTitle(const char16_t* aTitle)
|
|||
{
|
||||
NS_ENSURE_STATE(mWindow);
|
||||
mTitle.Assign(aTitle);
|
||||
mTitle.StripCRLF();
|
||||
mTitle.StripChars("\n\r");
|
||||
NS_ENSURE_SUCCESS(mWindow->SetTitle(mTitle), NS_ERROR_FAILURE);
|
||||
|
||||
// Tell the window mediator that a title has changed
|
||||
|
|
|
|||
Loading…
Reference in a new issue