Bug 1772006 - Part 5: Simplify and move the string searching APIs from ns[T]StringObsolete, r=xpcom-reviewers,necko-reviewers,eeejay,dragana,barret

The biggest set of APIs from ns[T]StringObsolete which are still heavily used
are the string searching APIs. It appears the intention was for these to be
replaced by the `FindInReadable` APIs, however that doesn't appear to have
happened.

In addition, the APIs have some quirks around their handling of mixed character
widths. These APIs generally supported both narrow strings and the native
string type, probably because char16_t string literals weren't available until
c++11. Finally they also used easy-to-confuse unlabeled boolean and integer
optional arguments to control behaviour.

These patches do the following major changes to the searching APIs:

1. The ASCII case-insensitive search method was split out as
   LowerCaseFindASCII, rather than using a boolean. This should be less
   error-prone and more explicit, and allows the method to continue to use
   narrow string literals for all string types (as only ASCII is supported).
2. The other [R]Find methods were restricted to only support arguments with
   matching character types. I considered adding a FindASCII method which would
   use narrow string literals for both wide and narrow strings but it would've
   been the same amount of work as changing all of the literals to unicode
   literals.
   This ends up being the bulk of the changes in the patch.
3. All find methods were re-implemented using std::basic_string_view's find
   algorithm or stl algorithms to reduce code complexity, and avoid the need to
   carry around the logic from nsStringObsolete.cpp.
4. The implementations were moved to nsTStringRepr.cpp.
5. An overload of Find was added to try to catch callers which previously
   called `Find(..., false)` or `Find(..., true)` to set case-sensitivity, due
   to booleans normally implicitly coercing to `index_type`. This should
   probably be removed at some point, but may be useful during the transition.

Differential Revision: https://phabricator.services.mozilla.com/D148300
This commit is contained in:
Nika Layzell 2022-07-30 00:12:48 +00:00
Родитель 997047e2a4
Коммит c15823d075
54 изменённых файлов: 375 добавлений и 638 удалений

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

@ -214,7 +214,7 @@ class AccAttributes {
void NameAsString(nsString& aName) {
mName->ToString(aName);
if (aName.Find("aria-", false, 0, 1) == 0) {
if (StringBeginsWith(aName, u"aria-"_ns)) {
// Found 'aria-'
aName.ReplaceLiteral(0, 5, u"");
}

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

@ -8,6 +8,7 @@
#include "DocAccessibleWrap.h"
#include "nsObjCExceptions.h"
#include "nsCocoaUtils.h"
#include "nsUnicharUtils.h"
#include "LocalAccessible-inl.h"
#include "nsAccUtils.h"
@ -293,7 +294,7 @@ bool AccessibleWrap::ApplyPostFilter(const EWhichPostFilter& aSearchKey,
"Only search text supported");
nsAutoString name;
Name(name);
return name.Find(aSearchText, true) != kNotFound;
return CaseInsensitiveFindInReadable(aSearchText, name);
}
////////////////////////////////////////////////////////////////////////////////

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

@ -29,9 +29,6 @@
using namespace mozilla;
using namespace mozilla::a11y;
template <typename String>
static void EscapeAttributeChars(String& aStr);
////////////////////////////////////////////////////////////////////////////////
// ia2Accessible
////////////////////////////////////////////////////////////////////////////////
@ -589,10 +586,9 @@ ia2Accessible::get_selectionRanges(IA2Range** aRanges, long* aNRanges) {
////////////////////////////////////////////////////////////////////////////////
// Helpers
template <typename String>
static inline void EscapeAttributeChars(String& aStr) {
static inline void EscapeAttributeChars(nsString& aStr) {
int32_t offset = 0;
static const char kCharsToEscape[] = ":;=,\\";
static const char16_t kCharsToEscape[] = u":;=,\\";
while ((offset = aStr.FindCharInSet(kCharsToEscape, offset)) != kNotFound) {
aStr.Insert('\\', offset);
offset += 2;

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

@ -169,7 +169,7 @@ uiaRawElmProvider::GetPropertyValue(PROPERTYID aPropertyId,
nsAutoString value;
attribIter.AttrName()->ToString(attribName);
attribIter.AttrValue(attribValue);
if (attribName.Find("aria-", false, 0, 1) == 0) {
if (StringBeginsWith(attribName, u"aria-"_ns)) {
// Found 'aria-'
attribName.ReplaceLiteral(0, 5, u"");
}

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

@ -206,12 +206,12 @@ KeyBinding XULMenuitemAccessible::KeyboardShortcut() const {
keyElm->GetAttr(kNameSpaceID_None, nsGkAtoms::modifiers, modifiersStr);
uint32_t modifierMask = 0;
if (modifiersStr.Find("shift") != -1) modifierMask |= KeyBinding::kShift;
if (modifiersStr.Find("alt") != -1) modifierMask |= KeyBinding::kAlt;
if (modifiersStr.Find("meta") != -1) modifierMask |= KeyBinding::kMeta;
if (modifiersStr.Find("os") != -1) modifierMask |= KeyBinding::kOS;
if (modifiersStr.Find("control") != -1) modifierMask |= KeyBinding::kControl;
if (modifiersStr.Find("accel") != -1) {
if (modifiersStr.Find(u"shift") != -1) modifierMask |= KeyBinding::kShift;
if (modifiersStr.Find(u"alt") != -1) modifierMask |= KeyBinding::kAlt;
if (modifiersStr.Find(u"meta") != -1) modifierMask |= KeyBinding::kMeta;
if (modifiersStr.Find(u"os") != -1) modifierMask |= KeyBinding::kOS;
if (modifiersStr.Find(u"control") != -1) modifierMask |= KeyBinding::kControl;
if (modifiersStr.Find(u"accel") != -1) {
modifierMask |= KeyBinding::AccelModifier();
}

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

@ -10464,8 +10464,8 @@ nsViewportInfo Document::GetViewportInfo(const ScreenIntSize& aDisplaySize) {
if (RefPtr<DocumentType> docType = GetDoctype()) {
nsAutoString docId;
docType->GetPublicId(docId);
if ((docId.Find("WAP") != -1) || (docId.Find("Mobile") != -1) ||
(docId.Find("WML") != -1)) {
if ((docId.Find(u"WAP") != -1) || (docId.Find(u"Mobile") != -1) ||
(docId.Find(u"WML") != -1)) {
// We're making an assumption that the docType can't change here
mViewportType = DisplayWidthHeight;
return nsViewportInfo(aDisplaySize, defaultScale,

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

@ -10764,7 +10764,7 @@ bool nsContentUtils::IsURIInList(nsIURI* aURI, const nsCString& aList) {
ToLowerCase(host);
for (;;) {
int32_t index = token.Find(host, false);
int32_t index = token.Find(host);
if (index >= 0 &&
static_cast<uint32_t>(index) + host.Length() <= token.Length()) {
// If we found a full match, return true.
@ -10793,7 +10793,7 @@ bool nsContentUtils::IsURIInList(nsIURI* aURI, const nsCString& aList) {
}
int32_t startIndexOfCurrentLevel = host[0] == '*' ? 1 : 0;
int32_t startIndexOfNextLevel =
host.Find(".", false, startIndexOfCurrentLevel + 1);
host.Find(".", startIndexOfCurrentLevel + 1);
if (startIndexOfNextLevel <= 0) {
break;
}

2
dom/cache/QuotaClient.cpp поставляемый
Просмотреть файл

@ -281,7 +281,7 @@ Result<UsageInfo, nsresult> CacheQuotaClient::InitOrigin(
// Ignore transient sqlite files and marker files
if (leafName.EqualsLiteral("caches.sqlite-journal") ||
leafName.EqualsLiteral("caches.sqlite-shm") ||
leafName.Find("caches.sqlite-mj"_ns, false, 0, 0) == 0 ||
StringBeginsWith(leafName, u"caches.sqlite-mj"_ns) ||
leafName.EqualsLiteral("context_open.marker")) {
break;
}

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

@ -281,18 +281,18 @@ void DocumentL10n::MaybeRecordTelemetry() {
nsCString key;
if (documentURI.Find("chrome://browser/content/browser.xhtml") == 0) {
if (documentURI.Find(u"chrome://browser/content/browser.xhtml") == 0) {
if (mIsFirstBrowserWindow) {
key = "browser_first_window";
mIsFirstBrowserWindow = false;
} else {
key = "browser_new_window";
}
} else if (documentURI.Find("about:home") == 0) {
} else if (documentURI.Find(u"about:home") == 0) {
key = "about:home";
} else if (documentURI.Find("about:newtab") == 0) {
} else if (documentURI.Find(u"about:newtab") == 0) {
key = "about:newtab";
} else if (documentURI.Find("about:preferences") == 0) {
} else if (documentURI.Find(u"about:preferences") == 0) {
key = "about:preferences";
} else {
return;

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

@ -322,7 +322,7 @@ static void RecordCommonRtpTelemetry(const T& list, const T& lastList,
const bool isRemote) {
using namespace Telemetry;
for (const auto& s : list) {
const bool isAudio = s.mKind.Value().Find("audio") != -1;
const bool isAudio = s.mKind.Value().Find(u"audio") != -1;
if (s.mPacketsLost.WasPassed() && s.mPacketsReceived.WasPassed()) {
if (const uint64_t total =
s.mPacketsLost.Value() + s.mPacketsReceived.Value()) {
@ -372,7 +372,7 @@ void PeerConnectionCtx::DeliverStats(
// Record bandwidth telemetry
for (const auto& s : aReport->mInboundRtpStreamStats) {
if (s.mBytesReceived.WasPassed()) {
const bool isAudio = s.mKind.Value().Find("audio") != -1;
const bool isAudio = s.mKind.Value().Find(u"audio") != -1;
for (const auto& lastS : lastReport->mInboundRtpStreamStats) {
if (lastS.mId == s.mId) {
int32_t deltaMs = s.mTimestamp.Value() - lastS.mTimestamp.Value();
@ -400,7 +400,7 @@ void PeerConnectionCtx::DeliverStats(
lastReport->mRemoteInboundRtpStreamStats, true);
for (const auto& s : aReport->mRemoteInboundRtpStreamStats) {
if (s.mRoundTripTime.WasPassed()) {
const bool isAudio = s.mKind.Value().Find("audio") != -1;
const bool isAudio = s.mKind.Value().Find(u"audio") != -1;
HistogramID id = isAudio ? WEBRTC_AUDIO_QUALITY_OUTBOUND_RTT
: WEBRTC_VIDEO_QUALITY_OUTBOUND_RTT;
Accumulate(id, s.mRoundTripTime.Value() * 1000);

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

@ -418,8 +418,7 @@ void WebrtcGlobalInformation::GetLogging(
MOZ_ASSERT(XRE_IsParentProcess());
nsAutoCString pattern;
CopyUTF16toUTF8(aPattern, pattern);
nsAutoString pattern(aPattern);
// CallbackObject does not support threadsafe refcounting, and must be
// destroyed on main.
@ -625,7 +624,7 @@ static void StoreLongTermICEStatisticsImpl_m(RTCStatsReportInternal* report) {
report->mClosed = true;
for (const auto& inboundRtpStats : report->mInboundRtpStreamStats) {
bool isVideo = (inboundRtpStats.mId.Value().Find("video") != -1);
bool isVideo = (inboundRtpStats.mId.Value().Find(u"video") != -1);
if (!isVideo) {
continue;
}

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

@ -1127,26 +1127,26 @@ void nsContentSecurityUtils::AssertAboutPageHasCSP(Document* aDocument) {
nsAutoString parsedPolicyStr;
for (uint32_t i = 0; i < policyCount; ++i) {
csp->GetPolicyString(i, parsedPolicyStr);
if (parsedPolicyStr.Find("default-src") >= 0) {
if (parsedPolicyStr.Find(u"default-src") >= 0) {
foundDefaultSrc = true;
}
if (parsedPolicyStr.Find("object-src 'none'") >= 0) {
if (parsedPolicyStr.Find(u"object-src 'none'") >= 0) {
foundObjectSrc = true;
}
if (parsedPolicyStr.Find("'unsafe-eval'") >= 0) {
if (parsedPolicyStr.Find(u"'unsafe-eval'") >= 0) {
foundUnsafeEval = true;
}
if (parsedPolicyStr.Find("'unsafe-inline'") >= 0) {
if (parsedPolicyStr.Find(u"'unsafe-inline'") >= 0) {
foundUnsafeInline = true;
}
if (parsedPolicyStr.Find("script-src") >= 0) {
if (parsedPolicyStr.Find(u"script-src") >= 0) {
foundScriptSrc = true;
}
if (parsedPolicyStr.Find("worker-src") >= 0) {
if (parsedPolicyStr.Find(u"worker-src") >= 0) {
foundWorkerSrc = true;
}
if (parsedPolicyStr.Find("http:") >= 0 ||
parsedPolicyStr.Find("https:") >= 0) {
if (parsedPolicyStr.Find(u"http:") >= 0 ||
parsedPolicyStr.Find(u"https:") >= 0) {
foundWebScheme = true;
}
}

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

@ -436,7 +436,7 @@ nsPlainTextSerializer::AppendText(nsIContent* aText, int32_t aStartOffset,
// We have to split the string across newlines
// to match parser behavior
int32_t start = 0;
int32_t offset = textstr.FindCharInSet("\n\r");
int32_t offset = textstr.FindCharInSet(u"\n\r");
while (offset != kNotFound) {
if (offset > start) {
// Pass in the line
@ -447,7 +447,7 @@ nsPlainTextSerializer::AppendText(nsIContent* aText, int32_t aStartOffset,
DoAddText();
start = offset + 1;
offset = textstr.FindCharInSet("\n\r", start);
offset = textstr.FindCharInSet(u"\n\r", start);
}
// Consume the last bit of the string if there's any left
@ -644,13 +644,13 @@ nsresult nsPlainTextSerializer::DoOpenContainer(const nsAtom* aTag) {
nsAutoString style;
int32_t whitespace;
if (NS_SUCCEEDED(GetAttributeValue(nsGkAtoms::style, style)) &&
(kNotFound != (whitespace = style.Find("white-space:")))) {
if (kNotFound != style.Find("pre-wrap", true, whitespace)) {
(kNotFound != (whitespace = style.Find(u"white-space:")))) {
if (kNotFound != style.LowerCaseFindASCII("pre-wrap", whitespace)) {
#ifdef DEBUG_preformatted
printf("Set mPreFormattedMail based on style pre-wrap\n");
#endif
mPreFormattedMail = true;
} else if (kNotFound != style.Find("pre", true, whitespace)) {
} else if (kNotFound != style.LowerCaseFindASCII("pre", whitespace)) {
#ifdef DEBUG_preformatted
printf("Set mPreFormattedMail based on style pre\n");
#endif
@ -1583,7 +1583,7 @@ void nsPlainTextSerializer::Write(const nsAString& aStr) {
int32_t bol = 0;
while (bol < totLen) { // Loop over lines
// Find a place where we may have to do whitespace compression
nextpos = str.FindCharInSet(" \t\n\r", bol);
nextpos = str.FindCharInSet(u" \t\n\r", bol);
#ifdef DEBUG_wrapping
nsAutoString remaining;
str.Right(remaining, totLen - bol);

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

@ -1430,7 +1430,7 @@ nsresult nsWebBrowserPersist::SaveURIInternal(
const char* kWhitespace = "\b\t\r\n ";
nsAutoCString extraHeaders(aExtraHeaders);
while (true) {
crlf = extraHeaders.Find("\r\n", true);
crlf = extraHeaders.Find("\r\n");
if (crlf == -1) break;
extraHeaders.Mid(oneHeader, 0, crlf);
extraHeaders.Cut(0, crlf + 2);

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

@ -1984,7 +1984,7 @@ XMLHttpRequestMainThread::OnStartRequest(nsIRequest* request) {
}
} else if (!(type.EqualsLiteral("text/xml") ||
type.EqualsLiteral("application/xml") ||
type.RFind("+xml", true, -1, 4) != kNotFound)) {
StringEndsWith(type, "+xml"_ns))) {
// Follow https://xhr.spec.whatwg.org/
// If final MIME type is not null, text/html, text/xml, application/xml,
// or does not end in +xml, return null.

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

@ -5894,9 +5894,9 @@ NS_IMETHODIMP EditorBase::GetWrapWidth(int32_t* aWrapColumn) {
//
static void CutStyle(const char* stylename, nsString& styleValue) {
// Find the current wrapping type:
int32_t styleStart = styleValue.Find(stylename, true);
int32_t styleStart = styleValue.LowerCaseFindASCII(stylename);
if (styleStart >= 0) {
int32_t styleEnd = styleValue.Find(";", false, styleStart);
int32_t styleEnd = styleValue.Find(u";", styleStart);
if (styleEnd > styleStart) {
styleValue.Cut(styleStart, styleEnd - styleStart + 1);
} else {

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

@ -1219,13 +1219,12 @@ EditActionResult HTMLEditor::HandleInsertText(
} else {
constexpr auto tabStr = u"\t"_ns;
constexpr auto spacesStr = u" "_ns;
char specialChars[] = {TAB, nsCRT::LF, 0};
nsAutoString insertionString(aInsertionString); // For FindCharInSet().
while (pos != -1 &&
pos < AssertedCast<int32_t>(insertionString.Length())) {
int32_t oldPos = pos;
int32_t subStrLen;
pos = insertionString.FindCharInSet(specialChars, oldPos);
pos = insertionString.FindCharInSet(u"\t\n", oldPos);
if (pos != -1) {
subStrLen = pos - oldPos;

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

@ -1449,14 +1449,14 @@ void RemoveFragComments(nsCString& aStr) {
// remove the StartFragment/EndFragment comments from the str, if present
int32_t startCommentIndx = aStr.Find("<!--StartFragment");
if (startCommentIndx >= 0) {
int32_t startCommentEnd = aStr.Find("-->", false, startCommentIndx);
int32_t startCommentEnd = aStr.Find("-->", startCommentIndx);
if (startCommentEnd > startCommentIndx) {
aStr.Cut(startCommentIndx, (startCommentEnd + 3) - startCommentIndx);
}
}
int32_t endCommentIndx = aStr.Find("<!--EndFragment");
if (endCommentIndx >= 0) {
int32_t endCommentEnd = aStr.Find("-->", false, endCommentIndx);
int32_t endCommentEnd = aStr.Find("-->", endCommentIndx);
if (endCommentEnd > endCommentIndx) {
aStr.Cut(endCommentIndx, (endCommentEnd + 3) - endCommentIndx);
}

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

@ -2892,7 +2892,7 @@ void gfxPlatform::InitWebGLConfig() {
// It causes the linking of some shaders to fail. See bug 1485441.
nsAutoString renderer;
gfxInfo->GetAdapterDeviceID(renderer);
if (renderer.Find("Adreno (TM) 630") != -1) {
if (renderer.Find(u"Adreno (TM) 630") != -1) {
gfxVars::SetAllowEglRbab(false);
}
}

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

@ -962,10 +962,10 @@ gfxPlatformGtk::CreateGlobalHardwareVsyncSource() {
nsCOMPtr<nsIGfxInfo> gfxInfo = components::GfxInfo::Service();
nsString windowProtocol;
gfxInfo->GetWindowProtocol(windowProtocol);
bool isXwayland = windowProtocol.Find("xwayland") != -1;
bool isXwayland = windowProtocol.Find(u"xwayland") != -1;
nsString adapterDriverVendor;
gfxInfo->GetAdapterDriverVendor(adapterDriverVendor);
bool isMesa = adapterDriverVendor.Find("mesa") != -1;
bool isMesa = adapterDriverVendor.Find(u"mesa") != -1;
// Only use GLX vsync when the OpenGL compositor / WebRender is being used.
// The extra cost of initializing a GLX context while blocking the main thread

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

@ -29,68 +29,68 @@ TEST(AppDateTimeFormat, FormatPRExplodedTime)
nsresult rv =
AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
ASSERT_TRUE(NS_SUCCEEDED(rv));
ASSERT_TRUE(formattedTime.Find("January") != kNotFound);
ASSERT_TRUE(formattedTime.Find("1970") != kNotFound);
ASSERT_TRUE(formattedTime.Find("12:00:00 AM") != kNotFound ||
formattedTime.Find("00:00:00") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"January") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"1970") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"12:00:00 AM") != kNotFound ||
formattedTime.Find(u"00:00:00") != kNotFound);
prExplodedTime = {0, 0, 19, 0, 1, 0, 1970, 4, 0, {(19 * 60), 0}};
rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
ASSERT_TRUE(NS_SUCCEEDED(rv));
ASSERT_TRUE(formattedTime.Find("January") != kNotFound);
ASSERT_TRUE(formattedTime.Find("1970") != kNotFound);
ASSERT_TRUE(formattedTime.Find("12:19:00 AM") != kNotFound ||
formattedTime.Find("00:19:00") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"January") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"1970") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"12:19:00 AM") != kNotFound ||
formattedTime.Find(u"00:19:00") != kNotFound);
prExplodedTime = {0, 0, 0, 7, 1,
0, 1970, 4, 0, {(6 * 60 * 60), (1 * 60 * 60)}};
rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
ASSERT_TRUE(NS_SUCCEEDED(rv));
ASSERT_TRUE(formattedTime.Find("January") != kNotFound);
ASSERT_TRUE(formattedTime.Find("1970") != kNotFound);
ASSERT_TRUE(formattedTime.Find("7:00:00 AM") != kNotFound ||
formattedTime.Find("07:00:00") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"January") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"1970") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"7:00:00 AM") != kNotFound ||
formattedTime.Find(u"07:00:00") != kNotFound);
prExplodedTime = {
0, 0, 29, 11, 1,
0, 1970, 4, 0, {(10 * 60 * 60) + (29 * 60), (1 * 60 * 60)}};
rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
ASSERT_TRUE(NS_SUCCEEDED(rv));
ASSERT_TRUE(formattedTime.Find("January") != kNotFound);
ASSERT_TRUE(formattedTime.Find("1970") != kNotFound);
ASSERT_TRUE(formattedTime.Find("11:29:00 AM") != kNotFound ||
formattedTime.Find("11:29:00") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"January") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"1970") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"11:29:00 AM") != kNotFound ||
formattedTime.Find(u"11:29:00") != kNotFound);
prExplodedTime = {0, 0, 37, 23, 31, 11, 1969, 3, 364, {-(23 * 60), 0}};
rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
ASSERT_TRUE(NS_SUCCEEDED(rv));
ASSERT_TRUE(formattedTime.Find("December") != kNotFound);
ASSERT_TRUE(formattedTime.Find("31") != kNotFound);
ASSERT_TRUE(formattedTime.Find("1969") != kNotFound);
ASSERT_TRUE(formattedTime.Find("11:37:00 PM") != kNotFound ||
formattedTime.Find("23:37:00") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"December") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"31") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"1969") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"11:37:00 PM") != kNotFound ||
formattedTime.Find(u"23:37:00") != kNotFound);
prExplodedTime = {0, 0, 0, 17, 31, 11, 1969, 3, 364, {-(7 * 60 * 60), 0}};
rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
ASSERT_TRUE(NS_SUCCEEDED(rv));
ASSERT_TRUE(formattedTime.Find("December") != kNotFound);
ASSERT_TRUE(formattedTime.Find("31") != kNotFound);
ASSERT_TRUE(formattedTime.Find("1969") != kNotFound);
ASSERT_TRUE(formattedTime.Find("5:00:00 PM") != kNotFound ||
formattedTime.Find("17:00:00") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"December") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"31") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"1969") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"5:00:00 PM") != kNotFound ||
formattedTime.Find(u"17:00:00") != kNotFound);
prExplodedTime = {
0, 0, 47, 14, 31,
11, 1969, 3, 364, {-((10 * 60 * 60) + (13 * 60)), (1 * 60 * 60)}};
rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
ASSERT_TRUE(NS_SUCCEEDED(rv));
ASSERT_TRUE(formattedTime.Find("December") != kNotFound);
ASSERT_TRUE(formattedTime.Find("31") != kNotFound);
ASSERT_TRUE(formattedTime.Find("1969") != kNotFound);
ASSERT_TRUE(formattedTime.Find("2:47:00 PM") != kNotFound ||
formattedTime.Find("14:47:00") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"December") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"31") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"1969") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"2:47:00 PM") != kNotFound ||
formattedTime.Find(u"14:47:00") != kNotFound);
}
TEST(AppDateTimeFormat, DateFormatSelectors)
@ -158,70 +158,70 @@ TEST(AppDateTimeFormat, FormatPRExplodedTimeForeign)
nsresult rv =
AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
ASSERT_TRUE(NS_SUCCEEDED(rv));
ASSERT_TRUE(formattedTime.Find("1.") != kNotFound);
ASSERT_TRUE(formattedTime.Find("Januar") != kNotFound);
ASSERT_TRUE(formattedTime.Find("1970") != kNotFound);
ASSERT_TRUE(formattedTime.Find("12:00:00 AM") != kNotFound ||
formattedTime.Find("00:00:00") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"1.") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"Januar") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"1970") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"12:00:00 AM") != kNotFound ||
formattedTime.Find(u"00:00:00") != kNotFound);
prExplodedTime = {0, 0, 19, 0, 1, 0, 1970, 4, 0, {(19 * 60), 0}};
rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
ASSERT_TRUE(NS_SUCCEEDED(rv));
ASSERT_TRUE(formattedTime.Find("1.") != kNotFound);
ASSERT_TRUE(formattedTime.Find("Januar") != kNotFound);
ASSERT_TRUE(formattedTime.Find("1970") != kNotFound);
ASSERT_TRUE(formattedTime.Find("12:19:00 AM") != kNotFound ||
formattedTime.Find("00:19:00") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"1.") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"Januar") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"1970") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"12:19:00 AM") != kNotFound ||
formattedTime.Find(u"00:19:00") != kNotFound);
prExplodedTime = {0, 0, 0, 7, 1,
0, 1970, 4, 0, {(6 * 60 * 60), (1 * 60 * 60)}};
rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
ASSERT_TRUE(NS_SUCCEEDED(rv));
ASSERT_TRUE(formattedTime.Find("1.") != kNotFound);
ASSERT_TRUE(formattedTime.Find("Januar") != kNotFound);
ASSERT_TRUE(formattedTime.Find("1970") != kNotFound);
ASSERT_TRUE(formattedTime.Find("7:00:00 AM") != kNotFound ||
formattedTime.Find("07:00:00") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"1.") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"Januar") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"1970") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"7:00:00 AM") != kNotFound ||
formattedTime.Find(u"07:00:00") != kNotFound);
prExplodedTime = {
0, 0, 29, 11, 1,
0, 1970, 4, 0, {(10 * 60 * 60) + (29 * 60), (1 * 60 * 60)}};
rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
ASSERT_TRUE(NS_SUCCEEDED(rv));
ASSERT_TRUE(formattedTime.Find("1.") != kNotFound);
ASSERT_TRUE(formattedTime.Find("Januar") != kNotFound);
ASSERT_TRUE(formattedTime.Find("1970") != kNotFound);
ASSERT_TRUE(formattedTime.Find("11:29:00 AM") != kNotFound ||
formattedTime.Find("11:29:00") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"1.") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"Januar") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"1970") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"11:29:00 AM") != kNotFound ||
formattedTime.Find(u"11:29:00") != kNotFound);
prExplodedTime = {0, 0, 37, 23, 31, 11, 1969, 3, 364, {-(23 * 60), 0}};
rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
ASSERT_TRUE(NS_SUCCEEDED(rv));
ASSERT_TRUE(formattedTime.Find("31.") != kNotFound);
ASSERT_TRUE(formattedTime.Find("Dezember") != kNotFound);
ASSERT_TRUE(formattedTime.Find("1969") != kNotFound);
ASSERT_TRUE(formattedTime.Find("11:37:00 PM") != kNotFound ||
formattedTime.Find("23:37:00") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"31.") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"Dezember") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"1969") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"11:37:00 PM") != kNotFound ||
formattedTime.Find(u"23:37:00") != kNotFound);
prExplodedTime = {0, 0, 0, 17, 31, 11, 1969, 3, 364, {-(7 * 60 * 60), 0}};
rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
ASSERT_TRUE(NS_SUCCEEDED(rv));
ASSERT_TRUE(formattedTime.Find("31.") != kNotFound);
ASSERT_TRUE(formattedTime.Find("Dezember") != kNotFound);
ASSERT_TRUE(formattedTime.Find("1969") != kNotFound);
ASSERT_TRUE(formattedTime.Find("5:00:00 PM") != kNotFound ||
formattedTime.Find("17:00:00") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"31.") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"Dezember") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"1969") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"5:00:00 PM") != kNotFound ||
formattedTime.Find(u"17:00:00") != kNotFound);
prExplodedTime = {
0, 0, 47, 14, 31,
11, 1969, 3, 364, {-((10 * 60 * 60) + (13 * 60)), (1 * 60 * 60)}};
rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
ASSERT_TRUE(NS_SUCCEEDED(rv));
ASSERT_TRUE(formattedTime.Find("31.") != kNotFound);
ASSERT_TRUE(formattedTime.Find("Dezember") != kNotFound);
ASSERT_TRUE(formattedTime.Find("1969") != kNotFound);
ASSERT_TRUE(formattedTime.Find("2:47:00 PM") != kNotFound ||
formattedTime.Find("14:47:00") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"31.") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"Dezember") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"1969") != kNotFound);
ASSERT_TRUE(formattedTime.Find(u"2:47:00 PM") != kNotFound ||
formattedTime.Find(u"14:47:00") != kNotFound);
}
TEST(AppDateTimeFormat, DateFormatSelectorsForeign)

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

@ -597,19 +597,19 @@ static void ParseAlignAttribute(nsString& aValue, eAlign& aAlign,
// ToInteger ignores the whitespaces around the number
aValue.CompressWhitespace(true, false);
if (0 == aValue.Find("top")) {
if (0 == aValue.Find(u"top")) {
len = 3; // 3 is the length of 'top'
aAlign = eAlign_top;
} else if (0 == aValue.Find("bottom")) {
} else if (0 == aValue.Find(u"bottom")) {
len = 6; // 6 is the length of 'bottom'
aAlign = eAlign_bottom;
} else if (0 == aValue.Find("center")) {
} else if (0 == aValue.Find(u"center")) {
len = 6; // 6 is the length of 'center'
aAlign = eAlign_center;
} else if (0 == aValue.Find("baseline")) {
} else if (0 == aValue.Find(u"baseline")) {
len = 8; // 8 is the length of 'baseline'
aAlign = eAlign_baseline;
} else if (0 == aValue.Find("axis")) {
} else if (0 == aValue.Find(u"axis")) {
len = 4; // 4 is the length of 'axis'
aAlign = eAlign_axis;
}

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

@ -3820,7 +3820,7 @@ nsresult NS_HasRootDomain(const nsACString& aInput, const nsACString& aHost,
}
// If aHost is not found, we know we do not have it as a root domain.
int32_t index = nsAutoCString(aInput).Find(aHost.BeginReading());
int32_t index = nsAutoCString(aInput).Find(aHost);
if (index == kNotFound) {
return NS_OK;
}

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

@ -1084,13 +1084,12 @@ nsresult Http2Compressor::EncodeHeaderBlock(
while (true) {
int32_t startIndex = crlfIndex + 2;
crlfIndex = nvInput.Find("\r\n", false, startIndex);
crlfIndex = nvInput.Find("\r\n", startIndex);
if (crlfIndex == -1) {
break;
}
int32_t colonIndex =
nvInput.Find(":", false, startIndex, crlfIndex - startIndex);
int32_t colonIndex = Substring(nvInput, 0, crlfIndex).Find(":", startIndex);
if (colonIndex == -1) {
break;
}
@ -1151,7 +1150,7 @@ nsresult Http2Compressor::EncodeHeaderBlock(
int32_t nextCookie = valueIndex;
while (haveMoreCookies) {
int32_t semiSpaceIndex =
nvInput.Find("; ", false, nextCookie, crlfIndex - nextCookie);
Substring(nvInput, 0, crlfIndex).Find("; ", nextCookie);
if (semiSpaceIndex == -1) {
haveMoreCookies = false;
semiSpaceIndex = crlfIndex;

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

@ -111,8 +111,8 @@ Result<std::tuple<int64_t, int64_t, int64_t>, nsresult>
ParseContentRangeHeaderString(const nsAutoCString& aRangeStr) {
// Parse the range header: e.g. Content-Range: bytes 7000-7999/8000.
const int32_t spacePos = aRangeStr.Find(" "_ns);
const int32_t dashPos = aRangeStr.Find("-"_ns, true, spacePos);
const int32_t slashPos = aRangeStr.Find("/"_ns, true, dashPos);
const int32_t dashPos = aRangeStr.Find("-"_ns, spacePos);
const int32_t slashPos = aRangeStr.Find("/"_ns, dashPos);
nsAutoCString rangeStartText;
aRangeStr.Mid(rangeStartText, spacePos + 1, dashPos - (spacePos + 1));

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

@ -1135,7 +1135,7 @@ mozTXTToHTMLConv::ScanHTML(const nsAString& input, uint32_t whattodo,
// if a tag, skip until </a>.
// Make sure there's a white-space character after, not to match "abbr".
{
i = aInString.Find("</a>", true, i);
i = aInString.LowerCaseFindASCII("</a>", i);
if (i == kNotFound) {
i = lengthOfInString;
} else {
@ -1144,7 +1144,7 @@ mozTXTToHTMLConv::ScanHTML(const nsAString& input, uint32_t whattodo,
} else if (Substring(aInString, i + 1, 3).LowerCaseEqualsASCII("!--"))
// if out-commended code, skip until -->
{
i = aInString.Find("-->", false, i);
i = aInString.Find(u"-->", i);
if (i == kNotFound) {
i = lengthOfInString;
} else {
@ -1155,7 +1155,7 @@ mozTXTToHTMLConv::ScanHTML(const nsAString& input, uint32_t whattodo,
canFollow.FindChar(aInString[i + 6]) != kNotFound)
// if style tag, skip until </style>
{
i = aInString.Find("</style>", true, i);
i = aInString.LowerCaseFindASCII("</style>", i);
if (i == kNotFound) {
i = lengthOfInString;
} else {
@ -1167,7 +1167,7 @@ mozTXTToHTMLConv::ScanHTML(const nsAString& input, uint32_t whattodo,
canFollow.FindChar(aInString[i + 7]) != kNotFound)
// if script tag, skip until </script>
{
i = aInString.Find("</script>", true, i);
i = aInString.LowerCaseFindASCII("</script>", i);
if (i == kNotFound) {
i = lengthOfInString;
} else {
@ -1179,7 +1179,7 @@ mozTXTToHTMLConv::ScanHTML(const nsAString& input, uint32_t whattodo,
// if head tag, skip until </head>
// Make sure not to match <header>.
{
i = aInString.Find("</head>", true, i);
i = aInString.LowerCaseFindASCII("</head>", i);
if (i == kNotFound) {
i = lengthOfInString;
} else {

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

@ -332,7 +332,7 @@ void nsClientAuthRememberService::GetEntryKey(
bool nsClientAuthRememberService::IsPrivateBrowsingKey(
const nsCString& entryKey) {
const int32_t separator = entryKey.Find(":", false, 0, -1);
const int32_t separator = entryKey.Find(":");
nsCString suffix;
if (separator >= 0) {
entryKey.Left(suffix, separator);

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

@ -597,7 +597,7 @@ nsAutoCompleteController::HandleKeyNavigation(uint32_t aKey, bool* _retval) {
input->GetTextValue(inputValue);
if (NS_SUCCEEDED(GetDefaultCompleteValue(-1, false, value))) {
nsAutoString suggestedValue;
int32_t pos = inputValue.Find(" >> ");
int32_t pos = inputValue.Find(u" >> ");
if (pos > 0) {
inputValue.Right(suggestedValue, inputValue.Length() - pos - 4);
} else {
@ -1231,7 +1231,7 @@ nsresult nsAutoCompleteController::EnterMatch(bool aIsPopupSelection,
nsAutoString inputValue;
input->GetTextValue(inputValue);
nsAutoString suggestedValue;
int32_t pos = inputValue.Find(" >> ");
int32_t pos = inputValue.Find(u" >> ");
if (pos > 0) {
inputValue.Right(suggestedValue, inputValue.Length() - pos - 4);
} else {

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

@ -641,7 +641,7 @@ void MatchGlob::Init(JSContext* aCx, const nsAString& aGlob,
mGlob = aGlob;
// Check for a literal match with no glob metacharacters.
auto index = mGlob.FindCharInSet(aAllowQuestion ? "*?" : "*");
auto index = mGlob.FindCharInSet(aAllowQuestion ? u"*?" : u"*");
if (index < 0) {
mPathLiteral = mGlob;
return;

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

@ -63,7 +63,7 @@ void Category::GetSupportedNames(nsTArray<nsString>& aNames) {
//
// We need to ensure that we found _only_ the exact category by checking
// it is followed by a dot.
if (identifier.Find(mName, false, 0, 1) == 0 &&
if (StringBeginsWith(identifier, mName) &&
identifier.CharAt(mName.Length()) == '.') {
const char* metricName = &identifierBuf[mName.Length() + 1];
aNames.AppendElement()->AssignASCII(metricName);

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

@ -128,7 +128,7 @@ static bool IsMatchWildcard(const nsACString& aHost, const nsACString& aOverride
tokenEnd = overrideLength; // no '*' char, match rest of string
}
nsAutoCString token(Substring(override, tokenStart, tokenEnd - tokenStart));
offset = host.Find(token, /* aIgnoreCase = */ false, offset);
offset = host.Find(token, offset);
if (offset == -1 || (!star && offset)) {
return false;
}

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

@ -140,7 +140,7 @@ static bool IsMatchWildcard(const nsACString& aHost,
}
nsAutoCString token(
Substring(override, tokenStart, tokenEnd - tokenStart));
offset = host.Find(token, /* aIgnoreCase = */ false, offset);
offset = host.Find(token, offset);
if (offset == -1 || (!star && offset)) {
return false;
}

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

@ -79,8 +79,7 @@ static void GdkErrorHandler(const gchar* log_domain, GLogLevelFlags log_level,
}
constexpr auto minorCodeString = " minor_code "_ns;
start = buffer.Find(minorCodeString, /* aIgnoreCase = */ false,
endptr - buffer.BeginReading());
start = buffer.Find(minorCodeString, endptr - buffer.BeginReading());
if (!start) {
MOZ_CRASH_UNSAFE(message);
}

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

@ -1240,7 +1240,7 @@ nsresult nsXREDirProvider::GetUpdateRootDir(nsIFile** aResult,
return NS_ERROR_FAILURE;
}
int32_t dotIndex = appDirPath.RFind(".app");
int32_t dotIndex = appDirPath.RFind(u".app");
if (dotIndex == kNotFound) {
dotIndex = appDirPath.Length();
}

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

@ -773,7 +773,7 @@ NS_IMETHODIMP nsExternalHelperAppService::CreateListener(
}
nsAutoString extension;
int32_t dotidx = fileName.RFind(".");
int32_t dotidx = fileName.RFind(u".");
if (dotidx != -1) {
extension = Substring(fileName, dotidx + 1);
}
@ -3332,7 +3332,7 @@ nsExternalHelperAppService::ValidateFileNameForSaving(
}
} else {
// Determine the current extension for the filename.
int32_t dotidx = fileName.RFind(".");
int32_t dotidx = fileName.RFind(u".");
if (dotidx != -1) {
CopyUTF16toUTF8(Substring(fileName, dotidx + 1), extension);
}
@ -3438,7 +3438,7 @@ nsExternalHelperAppService::ValidateFileNameForSaving(
ModifyExtensionType modify =
ShouldModifyExtension(mimeInfo, originalExtension);
if (modify == ModifyExtension_Replace) {
int32_t dotidx = fileName.RFind(".");
int32_t dotidx = fileName.RFind(u".");
if (dotidx != -1) {
// Remove the existing extension and replace it.
fileName.Truncate(dotidx);
@ -3471,7 +3471,7 @@ nsExternalHelperAppService::ValidateFileNameForSaving(
// If no filename is present, use a default filename.
if (!(aFlags & VALIDATE_NO_DEFAULT_FILENAME) &&
(fileName.Length() == 0 || fileName.RFind(".") == 0)) {
(fileName.Length() == 0 || fileName.RFind(u".") == 0)) {
nsCOMPtr<nsIStringBundleService> stringService =
mozilla::components::StringBundle::Service();
if (stringService) {
@ -3635,7 +3635,7 @@ void nsExternalHelperAppService::SanitizeFileName(nsAString& aFileName,
if (bytesLength > maxBytes && !outFileName.IsEmpty()) {
// Get the sanitized extension from the filename without the dot.
nsAutoCString extension;
int32_t dotidx = outFileName.RFind(".");
int32_t dotidx = outFileName.RFind(u".");
if (dotidx != -1) {
extension = NS_ConvertUTF16toUTF8(Substring(outFileName, dotidx + 1));
}

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

@ -553,7 +553,7 @@ void nsMIMEInfoWin::ProcessPath(nsCOMPtr<nsIMutableArray>& appList,
WCHAR exe[MAX_PATH + 1];
uint32_t len = GetModuleFileNameW(nullptr, exe, MAX_PATH);
if (len < MAX_PATH && len != 0) {
int32_t index = lower.Find(exe);
int32_t index = lower.Find(reinterpret_cast<const char16_t*>(exe));
if (index != -1) return;
}

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

@ -481,9 +481,9 @@ nsresult GfxInfo::GetFeatureStatusImpl(
// have
// manufacturer=amazon
if (cModel.Find("SGH-I717", true) != -1 ||
cModel.Find("SGH-I727", true) != -1 ||
cModel.Find("SGH-I757", true) != -1) {
if (cModel.LowerCaseFindASCII("sgh-i717") != -1 ||
cModel.LowerCaseFindASCII("sgh-i727") != -1 ||
cModel.LowerCaseFindASCII("sgh-i757") != -1) {
isWhitelisted = false;
}
@ -498,13 +498,13 @@ nsresult GfxInfo::GetFeatureStatusImpl(
// Blocklist:
// Samsung devices from bug 812881 and 853522.
// Motorola XT890 from bug 882342.
bool isBlocklisted = cModel.Find("GT-P3100", true) != -1 ||
cModel.Find("GT-P3110", true) != -1 ||
cModel.Find("GT-P3113", true) != -1 ||
cModel.Find("GT-P5100", true) != -1 ||
cModel.Find("GT-P5110", true) != -1 ||
cModel.Find("GT-P5113", true) != -1 ||
cModel.Find("XT890", true) != -1;
bool isBlocklisted = cModel.LowerCaseFindASCII("gt-p3100") != -1 ||
cModel.LowerCaseFindASCII("gt-p3110") != -1 ||
cModel.LowerCaseFindASCII("gt-p3113") != -1 ||
cModel.LowerCaseFindASCII("gt-p5100") != -1 ||
cModel.LowerCaseFindASCII("gt-p5110") != -1 ||
cModel.LowerCaseFindASCII("gt-p5113") != -1 ||
cModel.LowerCaseFindASCII("xt890") != -1;
if (isBlocklisted) {
*aStatus = nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
@ -513,7 +513,7 @@ nsresult GfxInfo::GetFeatureStatusImpl(
}
} else if (CompareVersions(mOSVersion.get(), "4.3.0") < 0) {
// Blocklist all Sony devices
if (cManufacturer.Find("Sony", true) != -1) {
if (cManufacturer.LowerCaseFindASCII("sony") != -1) {
*aStatus = nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
aFailureId = "FEATURE_FAILURE_4_3_SONY";
return NS_OK;
@ -560,27 +560,25 @@ nsresult GfxInfo::GetFeatureStatusImpl(
if (aFeature == FEATURE_WEBRENDER) {
const bool isMali4xx =
mGLStrings->Renderer().Find("Mali-4", /*ignoreCase*/ true) >= 0;
mGLStrings->Renderer().LowerCaseFindASCII("mali-4") >= 0;
const bool isPowerVrG6110 =
mGLStrings->Renderer().Find("PowerVR Rogue G6110",
/* ignoreCase */ true) >= 0;
mGLStrings->Renderer().LowerCaseFindASCII("powervr rogue g6110") >= 0;
const bool isVivanteGC7000UL =
mGLStrings->Renderer().Find("Vivante GC7000UL",
/* ignoreCase */ true) >= 0;
mGLStrings->Renderer().LowerCaseFindASCII("vivante gc7000ul") >= 0;
const bool isPowerVrFenceSyncCrash =
(mGLStrings->Renderer().Find("PowerVR Rogue G6200",
/* ignoreCase */ true) >= 0 ||
mGLStrings->Renderer().Find("PowerVR Rogue G6430",
/* ignoreCase */ true) >= 0 ||
mGLStrings->Renderer().Find("PowerVR Rogue GX6250",
/* ignoreCase */ true) >= 0) &&
(mGLStrings->Version().Find("3283119", /* ignoreCase */ true) >= 0 ||
mGLStrings->Version().Find("3443629", /* ignoreCase */ true) >= 0 ||
mGLStrings->Version().Find("3573678", /* ignoreCase */ true) >= 0 ||
mGLStrings->Version().Find("3830101", /* ignoreCase */ true) >= 0);
(mGLStrings->Renderer().LowerCaseFindASCII("powervr rogue g6200") >=
0 ||
mGLStrings->Renderer().LowerCaseFindASCII("powervr rogue g6430") >=
0 ||
mGLStrings->Renderer().LowerCaseFindASCII("powervr rogue gx6250") >=
0) &&
(mGLStrings->Version().Find("3283119") >= 0 ||
mGLStrings->Version().Find("3443629") >= 0 ||
mGLStrings->Version().Find("3573678") >= 0 ||
mGLStrings->Version().Find("3830101") >= 0);
if (isMali4xx) {
// Mali 4xx does not support GLES 3.
@ -625,8 +623,8 @@ nsresult GfxInfo::GetFeatureStatusImpl(
// encountered any correctness or stability issues with them, loading them
// fails more often than not, so is a waste of time. Better to just not
// even attempt to cache them. See bug 1615574.
const bool isAdreno3xx = mGLStrings->Renderer().Find(
"Adreno (TM) 3", /*ignoreCase*/ true) >= 0;
const bool isAdreno3xx =
mGLStrings->Renderer().LowerCaseFindASCII("adreno (tm) 3") >= 0;
if (isAdreno3xx) {
*aStatus = nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
aFailureId = "FEATURE_FAILURE_ADRENO_3XX";
@ -642,7 +640,7 @@ nsresult GfxInfo::GetFeatureStatusImpl(
// disable for all Mali-T regardless of version. See bug 1689064 and bug
// 1707283 for details.
const bool isMaliT =
mGLStrings->Renderer().Find("Mali-T", /*ignoreCase*/ true) >= 0;
mGLStrings->Renderer().LowerCaseFindASCII("mali-t") >= 0;
if (isMaliT) {
*aStatus = nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
aFailureId = "FEATURE_FAILURE_BUG_1689064";
@ -657,9 +655,9 @@ nsresult GfxInfo::GetFeatureStatusImpl(
// On Mali-Txxx due to bug 1680087 and bug 1707815.
// On Adreno 3xx GPUs due to bug 1695771.
const bool isMaliT =
mGLStrings->Renderer().Find("Mali-T", /*ignoreCase*/ true) >= 0;
const bool isAdreno3xx = mGLStrings->Renderer().Find(
"Adreno (TM) 3", /*ignoreCase*/ true) >= 0;
mGLStrings->Renderer().LowerCaseFindASCII("mali-t") >= 0;
const bool isAdreno3xx =
mGLStrings->Renderer().LowerCaseFindASCII("adreno (tm) 3") >= 0;
if (isMaliT || isAdreno3xx) {
*aStatus = nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
aFailureId = "FEATURE_FAILURE_BUG_1680087_1695771_1707815";
@ -674,7 +672,7 @@ nsresult GfxInfo::GetFeatureStatusImpl(
// Swizzling appears to be buggy on PowerVR Rogue devices with webrender.
// See bug 1704783.
const bool isPowerVRRogue =
mGLStrings->Renderer().Find("PowerVR Rogue", /*ignoreCase*/ true) >= 0;
mGLStrings->Renderer().LowerCaseFindASCII("powervr rogue") >= 0;
if (isPowerVRRogue) {
*aStatus = nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
aFailureId = "FEATURE_FAILURE_POWERVR_ROGUE";

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

@ -581,13 +581,13 @@ void GfxInfo::GetData() {
if (!ddxDriver.IsEmpty()) {
PRInt32 start = 0;
PRInt32 loc = ddxDriver.Find(";", PR_FALSE, start);
PRInt32 loc = ddxDriver.Find(";", start);
while (loc != kNotFound) {
nsCString line(ddxDriver.get() + start, loc - start);
mDdxDrivers.AppendElement(std::move(line));
start = loc + 1;
loc = ddxDriver.Find(";", PR_FALSE, start);
loc = ddxDriver.Find(";", start);
}
}

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

@ -400,7 +400,7 @@ nsDependentCSubstring IMContextWrapper::GetIMName() const {
return im;
}
int32_t atIMValueEnd = xmodifiers.Find("@", false, atIMValueStart);
int32_t atIMValueEnd = xmodifiers.Find("@", atIMValueStart);
if (atIMValueEnd > atIMValueStart) {
return nsDependentCSubstring(xmodifiersChar + atIMValueStart,
atIMValueEnd - atIMValueStart);
@ -3039,10 +3039,11 @@ nsresult IMContextWrapper::GetCurrentParagraph(nsAString& aText,
}
// Get only the focused paragraph, by looking for newlines
int32_t parStart =
(selOffset == 0) ? 0
: textContent.RFind("\n", false, selOffset - 1, -1) + 1;
int32_t parEnd = textContent.Find("\n", false, selOffset + selLength, -1);
int32_t parStart = 0;
if (selOffset > 0) {
parStart = Substring(textContent, 0, selOffset - 1).RFind(u"\n") + 1;
}
int32_t parEnd = textContent.Find(u"\n", selOffset + selLength);
if (parEnd < 0) {
parEnd = textContent.Length();
}

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

@ -356,7 +356,7 @@ bool nsNativeTheme::IsBottomTab(nsIFrame* aFrame) {
nsGkAtoms::_class, classStr);
}
// FIXME: This looks bogus, shouldn't this be looking at GetClasses()?
return !classStr.IsEmpty() && classStr.Find("tab-bottom") != kNotFound;
return !classStr.IsEmpty() && classStr.Find(u"tab-bottom") != kNotFound;
}
bool nsNativeTheme::IsFirstTab(nsIFrame* aFrame) {

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

@ -300,13 +300,13 @@ static nsresult GetKeyValues(const WCHAR* keyLocation, const WCHAR* keyName,
// The device ID is a string like PCI\VEN_15AD&DEV_0405&SUBSYS_040515AD
// this function is used to extract the id's out of it
uint32_t ParseIDFromDeviceID(const nsAString& key, const char* prefix,
uint32_t ParseIDFromDeviceID(const nsAString& key, const nsAString& prefix,
int length) {
nsAutoString id(key);
ToUpperCase(id);
int32_t start = id.Find(prefix);
if (start != -1) {
id.Cut(0, start + strlen(prefix));
id.Cut(0, start + prefix.Length());
id.Truncate(length);
}
if (id.Equals(L"QCOM", nsCaseInsensitiveStringComparator)) {
@ -605,9 +605,9 @@ nsresult GfxInfo::Init() {
uint32_t adapterDeviceID[2] = {0, 0};
uint32_t adapterSubsysID[2] = {0, 0};
adapterVendorID[0] = ParseIDFromDeviceID(mDeviceID[0], "VEN_", 4);
adapterDeviceID[0] = ParseIDFromDeviceID(mDeviceID[0], "&DEV_", 4);
adapterSubsysID[0] = ParseIDFromDeviceID(mDeviceID[0], "&SUBSYS_", 8);
adapterVendorID[0] = ParseIDFromDeviceID(mDeviceID[0], u"VEN_"_ns, 4);
adapterDeviceID[0] = ParseIDFromDeviceID(mDeviceID[0], u"&DEV_"_ns, 4);
adapterSubsysID[0] = ParseIDFromDeviceID(mDeviceID[0], u"&SUBSYS_"_ns, 8);
// Sometimes we don't get the valid device using this method. For now,
// allow zero vendor or device as valid, as long as the other value is
@ -660,8 +660,8 @@ nsresult GfxInfo::Init() {
continue;
}
deviceID2 = value;
adapterVendorID[1] = ParseIDFromDeviceID(deviceID2, "VEN_", 4);
adapterDeviceID[1] = ParseIDFromDeviceID(deviceID2, "&DEV_", 4);
adapterVendorID[1] = ParseIDFromDeviceID(deviceID2, u"VEN_"_ns, 4);
adapterDeviceID[1] = ParseIDFromDeviceID(deviceID2, u"&DEV_"_ns, 4);
// Skip the devices we already considered, as well as any
// "zero" ones.
if ((adapterVendorID[0] == adapterVendorID[1] &&
@ -717,7 +717,7 @@ nsresult GfxInfo::Init() {
mDriverVersion[0] = driverVersion2;
mDriverDate[0] = driverDate2;
adapterSubsysID[0] =
ParseIDFromDeviceID(mDeviceID[0], "&SUBSYS_", 8);
ParseIDFromDeviceID(mDeviceID[0], u"&SUBSYS_"_ns, 8);
continue;
}
@ -728,7 +728,7 @@ nsresult GfxInfo::Init() {
mDriverVersion[1] = driverVersion2;
mDriverDate[1] = driverDate2;
adapterSubsysID[1] =
ParseIDFromDeviceID(mDeviceID[1], "&SUBSYS_", 8);
ParseIDFromDeviceID(mDeviceID[1], u"&SUBSYS_"_ns, 8);
mAdapterVendorID[1].AppendPrintf("0x%04x", adapterVendorID[1]);
mAdapterDeviceID[1].AppendPrintf("0x%04x", adapterDeviceID[1]);
mAdapterSubsysID[1].AppendPrintf("%08x", adapterSubsysID[1]);

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

@ -1479,8 +1479,11 @@ bool IMMHandler::HandleDocumentFeed(nsWindow* aWindow, LPARAM lParam,
// Get the focused paragraph, we decide that it starts from the previous CRLF
// (or start of the editor) to the next one (or the end of the editor).
int32_t paragraphStart = str.RFind("\n", false, targetOffset, -1) + 1;
int32_t paragraphEnd = str.Find("\r", false, targetOffset + targetLength, -1);
int32_t paragraphStart = 0;
if (targetOffset > 0) {
paragraphStart = Substring(str, 0, targetOffset).RFind(u"\n") + 1;
}
int32_t paragraphEnd = str.Find(u"\r", targetOffset + targetLength);
if (paragraphEnd < 0) {
paragraphEnd = str.Length();
}

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

@ -457,7 +457,7 @@ nsBaseWinFilePicker::SetDefaultString(const nsAString& aString) {
// First, make sure the file name is not too long.
int32_t nameLength;
int32_t nameIndex = mDefaultFilePath.RFind("\\");
int32_t nameIndex = mDefaultFilePath.RFind(u"\\");
if (nameIndex == kNotFound)
nameIndex = 0;
else
@ -466,7 +466,7 @@ nsBaseWinFilePicker::SetDefaultString(const nsAString& aString) {
mDefaultFilename.Assign(Substring(mDefaultFilePath, nameIndex));
if (nameLength > MAX_PATH) {
int32_t extIndex = mDefaultFilePath.RFind(".");
int32_t extIndex = mDefaultFilePath.RFind(u".");
if (extIndex == kNotFound) extIndex = mDefaultFilePath.Length();
// Let's try to shave the needed characters from the name part.
@ -478,8 +478,8 @@ nsBaseWinFilePicker::SetDefaultString(const nsAString& aString) {
// Then, we need to replace illegal characters. At this stage, we cannot
// replace the backslash as the string might represent a file path.
mDefaultFilePath.ReplaceChar(FILE_ILLEGAL_CHARACTERS, '-');
mDefaultFilename.ReplaceChar(FILE_ILLEGAL_CHARACTERS, '-');
mDefaultFilePath.ReplaceChar(u"" FILE_ILLEGAL_CHARACTERS, u'-');
mDefaultFilename.ReplaceChar(u"" FILE_ILLEGAL_CHARACTERS, u'-');
return NS_OK;
}
@ -567,7 +567,7 @@ bool nsFilePicker::IsDefaultPathLink() {
}
bool nsFilePicker::IsDefaultPathHtml() {
int32_t extIndex = mDefaultFilePath.RFind(".");
int32_t extIndex = mDefaultFilePath.RFind(u".");
if (extIndex >= 0) {
nsAutoString ext;
mDefaultFilePath.Right(ext, mDefaultFilePath.Length() - extIndex);

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

@ -513,8 +513,9 @@ static bool InitLog(const EnvCharType* aEnvVar, const char* aMsg,
return true;
}
if (!XRE_IsParentProcess()) {
bool hasLogExtension =
fname.RFind(".log", true, -1, 4) == kNotFound ? false : true;
nsTString<EnvCharType> extension;
extension.AssignLiteral(".log");
bool hasLogExtension = StringEndsWith(fname, extension);
if (hasLogExtension) {
fname.Cut(fname.Length() - 4, 4);
}

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

@ -1109,9 +1109,9 @@ static void CleanupHandlerPath(nsString& aPath) {
aPath.Append(' ');
// case insensitive
int32_t index = aPath.Find(".exe ", true);
if (index == kNotFound) index = aPath.Find(".dll ", true);
if (index == kNotFound) index = aPath.Find(".cpl ", true);
int32_t index = aPath.LowerCaseFindASCII(".exe ");
if (index == kNotFound) index = aPath.LowerCaseFindASCII(".dll ");
if (index == kNotFound) index = aPath.LowerCaseFindASCII(".cpl ");
if (index != kNotFound) aPath.Truncate(index + 4);
aPath.Trim(" ", true, true);
@ -1126,15 +1126,15 @@ static void StripRundll32(nsString& aCommandString) {
// C:\Windows\System32\rundll32.exe "path to dll", var var
// rundll32.exe "path to dll", var var
constexpr auto rundllSegment = u"rundll32.exe "_ns;
constexpr auto rundllSegmentShort = u"rundll32 "_ns;
constexpr auto rundllSegment = "rundll32.exe "_ns;
constexpr auto rundllSegmentShort = "rundll32 "_ns;
// case insensitive
int32_t strLen = rundllSegment.Length();
int32_t index = aCommandString.Find(rundllSegment, true);
int32_t index = aCommandString.LowerCaseFindASCII(rundllSegment);
if (index == kNotFound) {
strLen = rundllSegmentShort.Length();
index = aCommandString.Find(rundllSegmentShort, true);
index = aCommandString.LowerCaseFindASCII(rundllSegmentShort);
}
if (index != kNotFound) {

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

@ -628,26 +628,6 @@ static
return kNotFound;
}
template <class L, class R>
#ifndef __SUNPRO_CC
static
#endif /* !__SUNPRO_CC */
int32_t
RFindSubstring(const L* big, uint32_t bigLen, const R* little,
uint32_t littleLen, bool ignoreCase) {
if (littleLen > bigLen) return kNotFound;
int32_t i, max = int32_t(bigLen - littleLen);
const L* iter = big + max;
for (i = max; iter >= big; --i, --iter) {
if (nsBufferRoutines<L>::compare(iter, little, littleLen, ignoreCase) == 0)
return i;
}
return kNotFound;
}
template <class CharT, class SetCharT>
#ifndef __SUNPRO_CC
static
@ -675,187 +655,12 @@ static
return kNotFound;
}
template <class CharT, class SetCharT>
#ifndef __SUNPRO_CC
static
#endif /* !__SUNPRO_CC */
int32_t
RFindCharInSet(const CharT* data, uint32_t dataLen, const SetCharT* set) {
CharT filter = nsBufferRoutines<CharT>::get_find_in_set_filter(set);
for (const CharT* iter = data + dataLen - 1; iter >= data; --iter) {
CharT currentChar = *iter;
if (currentChar & filter)
continue; // char is not in filter set; go on with next char.
// test all chars
const CharT* charInSet = set;
CharT setChar = *charInSet;
while (setChar) {
if (setChar == currentChar)
return iter - data; // found it! return index of the found char.
setChar = *(++charInSet);
}
}
return kNotFound;
}
/**
* this method changes the meaning of |offset| and |count|:
*
* upon return,
* |offset| specifies start of search range
* |count| specifies length of search range
*/
static void Find_ComputeSearchRange(uint32_t bigLen, uint32_t littleLen,
int32_t& offset, int32_t& count) {
// |count| specifies how many iterations to make from |offset|
if (offset < 0) {
offset = 0;
} else if (uint32_t(offset) > bigLen) {
count = 0;
return;
}
int32_t maxCount = bigLen - offset;
if (count < 0 || count > maxCount) {
count = maxCount;
} else {
count += littleLen;
if (count > maxCount) count = maxCount;
}
}
/**
* this method changes the meaning of |offset| and |count|:
*
* upon entry,
* |offset| specifies the end point from which to search backwards
* |count| specifies the number of iterations from |offset|
*
* upon return,
* |offset| specifies start of search range
* |count| specifies length of search range
*
*
* EXAMPLE
*
* + -- littleLen=4 -- +
* : :
* |____|____|____|____|____|____|____|____|____|____|____|____|
* : :
* offset=5 bigLen=12
*
* if count = 4, then we expect this function to return offset = 2 and
* count = 7.
*
*/
static void RFind_ComputeSearchRange(uint32_t bigLen, uint32_t littleLen,
int32_t& offset, int32_t& count) {
if (littleLen > bigLen) {
offset = 0;
count = 0;
return;
}
if (offset < 0) offset = bigLen - littleLen;
if (count < 0) count = offset + 1;
int32_t start = offset - count + 1;
if (start < 0) start = 0;
count = offset + littleLen - start;
offset = start;
}
//-----------------------------------------------------------------------------
#include "nsTStringObsolete.cpp"
//-----------------------------------------------------------------------------
// specialized methods:
namespace mozilla::detail {
template <typename T>
template <typename Q, typename EnableIfChar16>
int32_t nsTStringRepr<T>::Find(const self_type& aString, int32_t aOffset,
int32_t aCount) const {
// this method changes the meaning of aOffset and aCount:
Find_ComputeSearchRange(this->mLength, aString.Length(), aOffset, aCount);
// Capture the raw buffer locally to help msvc deduce the type.
const char_type* str = aString.BeginReading();
int32_t result = FindSubstring(this->mData + aOffset, aCount, str,
aString.Length(), false);
if (result != kNotFound) result += aOffset;
return result;
}
template int32_t nsTStringRepr<char16_t>::Find(const self_type&, int32_t,
int32_t) const;
template <typename T>
template <typename Q, typename EnableIfChar16>
int32_t nsTStringRepr<T>::Find(const char_type* aString, int32_t aOffset,
int32_t aCount) const {
return Find(nsTDependentString<T>(aString), aOffset, aCount);
}
template int32_t nsTStringRepr<char16_t>::Find(const char_type*, int32_t,
int32_t) const;
template <typename T>
template <typename Q, typename EnableIfChar16>
int32_t nsTStringRepr<T>::RFind(const self_type& aString, int32_t aOffset,
int32_t aCount) const {
// this method changes the meaning of aOffset and aCount:
RFind_ComputeSearchRange(this->mLength, aString.Length(), aOffset, aCount);
// Capture the raw buffer locally to help msvc deduce the type.
const char_type* str = aString.BeginReading();
int32_t result = RFindSubstring(this->mData + aOffset, aCount, str,
aString.Length(), false);
if (result != kNotFound) result += aOffset;
return result;
}
template int32_t nsTStringRepr<char16_t>::RFind(const self_type&, int32_t,
int32_t) const;
template <typename T>
template <typename Q, typename EnableIfChar16>
int32_t nsTStringRepr<T>::RFind(const char_type* aString, int32_t aOffset,
int32_t aCount) const {
return RFind(nsTDependentString<T>(aString), aOffset, aCount);
}
template int32_t nsTStringRepr<char16_t>::RFind(const char_type*, int32_t,
int32_t) const;
template <typename T>
template <typename Q, typename EnableIfChar16>
int32_t nsTStringRepr<T>::FindCharInSet(const char* aSet,
int32_t aOffset) const {
if (aOffset < 0)
aOffset = 0;
else if (aOffset >= int32_t(this->mLength))
return kNotFound;
int32_t result =
::FindCharInSet(this->mData + aOffset, this->mLength - aOffset, aSet);
if (result != kNotFound) result += aOffset;
return result;
}
template int32_t nsTStringRepr<char16_t>::FindCharInSet(const char*,
int32_t) const;
} // namespace mozilla::detail
template <typename T>
template <typename Q, typename EnableIfChar16>
void nsTSubstring<T>::ReplaceChar(const char* aSet, char16_t aNewChar) {

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

@ -180,15 +180,6 @@ class nsTString : public nsTSubstring<T> {
char_type operator[](index_type aIndex) const { return CharAt(aIndex); }
int32_t RFindCharInSet(const self_type& aString, int32_t aOffset = -1) const {
return repr_type::RFindCharInSet(aString.get(), aOffset);
}
using repr_type::RFindCharInSet;
int32_t FindCharInSet(const self_type& aString, int32_t aOffset = 0) const {
return repr_type::FindCharInSet(aString.get(), aOffset);
}
using repr_type::FindCharInSet;
/**
* Perform string to double-precision float conversion.
*

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

@ -8,87 +8,6 @@
#include "nsASCIIMask.h"
#include "mozilla/CheckedInt.h"
namespace mozilla::detail {
template <typename T>
int32_t nsTStringRepr<T>::Find(const nsTStringRepr<char>& aString,
bool aIgnoreCase, int32_t aOffset,
int32_t aCount) const {
// this method changes the meaning of aOffset and aCount:
Find_ComputeSearchRange(this->mLength, aString.Length(), aOffset, aCount);
int32_t result =
FindSubstring(this->mData + aOffset, aCount, aString.BeginReading(),
aString.Length(), aIgnoreCase);
if (result != kNotFound) result += aOffset;
return result;
}
template <typename T>
int32_t nsTStringRepr<T>::Find(const char* aString, bool aIgnoreCase,
int32_t aOffset, int32_t aCount) const {
return Find(nsTDependentString<char>(aString), aIgnoreCase, aOffset, aCount);
}
template <typename T>
int32_t nsTStringRepr<T>::RFind(const nsTStringRepr<char>& aString,
bool aIgnoreCase, int32_t aOffset,
int32_t aCount) const {
// this method changes the meaning of aOffset and aCount:
RFind_ComputeSearchRange(this->mLength, aString.Length(), aOffset, aCount);
int32_t result =
RFindSubstring(this->mData + aOffset, aCount, aString.BeginReading(),
aString.Length(), aIgnoreCase);
if (result != kNotFound) result += aOffset;
return result;
}
template <typename T>
int32_t nsTStringRepr<T>::RFind(const char* aString, bool aIgnoreCase,
int32_t aOffset, int32_t aCount) const {
return RFind(nsTDependentString<char>(aString), aIgnoreCase, aOffset, aCount);
}
template <typename T>
int32_t nsTStringRepr<T>::RFindChar(char16_t aChar, int32_t aOffset,
int32_t aCount) const {
return nsBufferRoutines<T>::rfind_char(this->mData, this->mLength, aOffset,
aChar, aCount);
}
template <typename T>
int32_t nsTStringRepr<T>::FindCharInSet(const char_type* aSet,
int32_t aOffset) const {
if (aOffset < 0)
aOffset = 0;
else if (aOffset >= int32_t(this->mLength))
return kNotFound;
int32_t result =
::FindCharInSet(this->mData + aOffset, this->mLength - aOffset, aSet);
if (result != kNotFound) result += aOffset;
return result;
}
/**
* nsTString::RFindCharInSet
*/
template <typename T>
int32_t nsTStringRepr<T>::RFindCharInSet(const char_type* aSet,
int32_t aOffset) const {
// We want to pass a "data length" to ::RFindCharInSet
if (aOffset < 0 || aOffset > int32_t(this->mLength))
aOffset = this->mLength;
else
++aOffset;
return ::RFindCharInSet(this->mData, aOffset, aSet);
}
} // namespace mozilla::detail
/**
* nsTSubstring::ReplaceChar,ReplaceSubstring
*/

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

@ -107,6 +107,71 @@ bool nsTStringRepr<T>::LowerCaseEqualsASCII(const char* aData) const {
this->mData, this->mLength, aData) == 0;
}
template <typename T>
int32_t nsTStringRepr<T>::Find(const string_view& aString,
index_type aOffset) const {
auto idx = View().find(aString, aOffset);
return idx == string_view::npos ? kNotFound : idx;
}
template <typename T>
int32_t nsTStringRepr<T>::LowerCaseFindASCII(const std::string_view& aString,
index_type aOffset) const {
if (aOffset > Length()) {
return kNotFound;
}
auto begin = BeginReading();
auto end = EndReading();
auto it =
std::search(begin + aOffset, end, aString.begin(), aString.end(),
[](char_type l, char r) {
MOZ_ASSERT(!(r & ~0x7F), "Unexpected non-ASCII character");
MOZ_ASSERT(char_traits::ASCIIToLower(r) == char_type(r),
"Search string must be ASCII lowercase");
return char_traits::ASCIIToLower(l) == char_type(r);
});
return it == end ? kNotFound : std::distance(begin, it);
}
template <typename T>
int32_t nsTStringRepr<T>::RFind(const string_view& aString) const {
auto idx = View().rfind(aString);
return idx == string_view::npos ? kNotFound : idx;
}
template <typename T>
typename nsTStringRepr<T>::size_type nsTStringRepr<T>::CountChar(
char_type aChar) const {
return std::count(BeginReading(), EndReading(), aChar);
}
template <typename T>
int32_t nsTStringRepr<T>::FindChar(char_type aChar, index_type aOffset) const {
auto idx = View().find(aChar, aOffset);
return idx == string_view::npos ? kNotFound : idx;
}
template <typename T>
int32_t nsTStringRepr<T>::RFindChar(char_type aChar, int32_t aOffset) const {
auto idx = View().rfind(aChar, aOffset != -1 ? aOffset : string_view::npos);
return idx == string_view::npos ? kNotFound : idx;
}
template <typename T>
int32_t nsTStringRepr<T>::FindCharInSet(const string_view& aSet,
index_type aOffset) const {
auto idx = View().find_first_of(aSet, aOffset);
return idx == string_view::npos ? kNotFound : idx;
}
template <typename T>
int32_t nsTStringRepr<T>::RFindCharInSet(const string_view& aSet,
int32_t aOffset) const {
auto idx =
View().find_last_of(aSet, aOffset != -1 ? aOffset : string_view::npos);
return idx == string_view::npos ? kNotFound : idx;
}
template <typename T>
bool nsTStringRepr<T>::EqualsIgnoreCase(const std::string_view& aString) const {
return std::equal(BeginReading(), EndReading(), aString.begin(),

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

@ -16,6 +16,7 @@
#include "mozilla/fallible.h"
#include "nsStringBuffer.h"
#include "nsStringFlags.h"
#include "nsStringFwd.h"
#include "nsStringIterator.h"
#include "nsCharTraits.h"
@ -217,11 +218,6 @@ class nsTStringRepr {
char_type Last() const;
size_type NS_FASTCALL CountChar(char_type) const;
int32_t NS_FASTCALL FindChar(char_type, index_type aOffset = 0) const;
bool Contains(char_type aChar) const;
// Equality.
bool NS_FASTCALL Equals(const self_type&) const;
bool NS_FASTCALL Equals(const self_type&, comparator_type) const;
@ -341,99 +337,88 @@ class nsTStringRepr {
}
/**
* Search for the given substring within this string.
*
* @param aString is substring to be sought in this
* @param aIgnoreCase selects case sensitivity
* @param aOffset tells us where in this string to start searching
* @param aCount tells us how far from the offset we are to search. Use
* -1 to search the whole string.
* @return offset in string, or kNotFound
*/
int32_t Find(const nsTStringRepr<char>& aString, bool aIgnoreCase = false,
int32_t aOffset = 0, int32_t aCount = -1) const;
int32_t Find(const char* aString, bool aIgnoreCase = false,
int32_t aOffset = 0, int32_t aCount = -1) const;
template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>>
int32_t Find(const self_type& aString, int32_t aOffset = 0,
int32_t aCount = -1) const;
template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>>
int32_t Find(const char_type* aString, int32_t aOffset = 0,
int32_t aCount = -1) const;
#ifdef MOZ_USE_CHAR16_WRAPPER
template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>>
int32_t Find(char16ptr_t aString, int32_t aOffset = 0,
int32_t aCount = -1) const {
return Find(static_cast<const char16_t*>(aString), aOffset, aCount);
}
#endif
/**
* This methods scans the string backwards, looking for the given string
* Search for the given substring within this string.
*
* @param aString is substring to be sought in this
* @param aIgnoreCase tells us whether or not to do caseless compare
* @param aOffset tells us where in this string to start searching.
* Use -1 to search from the end of the string.
* @param aCount tells us how many iterations to make starting at the
* given offset.
* @param aOffset tells us where in this string to start searching
* @return offset in string, or kNotFound
*/
int32_t Find(const string_view& aString, index_type aOffset = 0) const;
// Case aIgnoreCase option only with char versions
int32_t RFind(const nsTStringRepr<char>& aString, bool aIgnoreCase = false,
int32_t aOffset = -1, int32_t aCount = -1) const;
int32_t RFind(const char* aCString, bool aIgnoreCase = false,
int32_t aOffset = -1, int32_t aCount = -1) const;
template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>>
int32_t RFind(const self_type& aString, int32_t aOffset = -1,
int32_t aCount = -1) const;
template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>>
int32_t RFind(const char_type* aString, int32_t aOffset = -1,
int32_t aCount = -1) const;
// Previously there was an overload of `Find()` which took a bool second
// argument. Avoid issues by explicitly preventing that overload.
// TODO: Remove this at some point.
template <typename I,
typename = std::enable_if_t<!std::is_same_v<I, index_type> &&
std::is_convertible_v<I, index_type>>>
int32_t Find(const string_view& aString, I aOffset) const {
static_assert(!std::is_same_v<I, bool>, "offset must not be `bool`");
return Find(aString, static_cast<index_type>(aOffset));
}
/**
* Search for given char within this string
* Search for the given ASCII substring within this string, ignoring case.
*
* @param aChar is the character to search for
* @param aOffset tells us where in this string to start searching
* @param aCount tells us how far from the offset we are to search.
* Use -1 to search the whole string.
* @return offset in string, or kNotFound
* @param aString is substring to be sought in this
* @param aOffset tells us where in this string to start searching
* @return offset in string, or kNotFound
*/
int32_t LowerCaseFindASCII(const std::string_view& aString,
index_type aOffset = 0) const;
// int32_t FindChar( char16_t aChar, int32_t aOffset=0,
// int32_t aCount=-1 ) const;
int32_t RFindChar(char16_t aChar, int32_t aOffset = -1,
int32_t aCount = -1) const;
/**
* Scan the string backwards, looking for the given substring.
*
* @param aString is substring to be sought in this
* @return offset in string, or kNotFound
*/
int32_t RFind(const string_view& aString) const;
size_type CountChar(char_type) const;
bool Contains(char_type aChar) const { return FindChar(aChar) != kNotFound; }
/**
* Search for the first instance of a given char within this string
*
* @param aChar is the character to search for
* @param aOffset tells us where in this string to start searching
* @return offset in string, or kNotFound
*/
int32_t FindChar(char_type aChar, index_type aOffset = 0) const;
/**
* Search for the last instance of a given char within this string
*
* @param aChar is the character to search for
* @param aOffset tells us where in this string to start searching
* @return offset in string, or kNotFound
*/
int32_t RFindChar(char_type aChar, int32_t aOffset = -1) const;
/**
* This method searches this string for the first character found in
* the given string.
*
* @param aString contains set of chars to be found
* @param aSet contains set of chars to be found
* @param aOffset tells us where in this string to start searching
* (counting from left)
* @return offset in string, or kNotFound
*/
int32_t FindCharInSet(const char_type* aString, int32_t aOffset = 0) const;
template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>>
int32_t FindCharInSet(const char* aSet, int32_t aOffset = 0) const;
int32_t FindCharInSet(const string_view& aSet, index_type aOffset = 0) const;
/**
* This method searches this string for the last character found in
* the given string.
*
* @param aString contains set of chars to be found
* @param aSet contains set of chars to be found
* @param aOffset tells us where in this string to start searching
* (counting from left)
* @return offset in string, or kNotFound
*/
int32_t RFindCharInSet(const char_type* aString, int32_t aOffset = -1) const;
int32_t RFindCharInSet(const string_view& aSet, int32_t aOffset = -1) const;
protected:
nsTStringRepr() = delete; // Never instantiate directly

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

@ -983,38 +983,6 @@ void nsTSubstring<T>::SetIsVoid(bool aVal) {
}
}
namespace mozilla {
namespace detail {
template <typename T>
typename nsTStringRepr<T>::size_type nsTStringRepr<T>::CountChar(
char_type aChar) const {
const char_type* start = this->mData;
const char_type* end = this->mData + this->mLength;
return NS_COUNT(start, end, aChar);
}
template <typename T>
int32_t nsTStringRepr<T>::FindChar(char_type aChar, index_type aOffset) const {
if (aOffset < this->mLength) {
const char_type* result = char_traits::find(this->mData + aOffset,
this->mLength - aOffset, aChar);
if (result) {
return result - this->mData;
}
}
return -1;
}
template <typename T>
bool nsTStringRepr<T>::Contains(char_type aChar) const {
return FindChar(aChar) != kNotFound;
}
} // namespace detail
} // namespace mozilla
template <typename T>
void nsTSubstring<T>::StripChar(char_type aChar) {
if (this->mLength == 0) {

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

@ -613,33 +613,42 @@ TEST_F(Strings, test2) {
TEST_F(Strings, find) {
nsCString src("<!DOCTYPE blah blah blah>");
int32_t i = src.Find("DOCTYPE", true, 2, 1);
int32_t i = src.Find("DOCTYPE", 2);
EXPECT_EQ(i, 2);
i = src.Find("DOCTYPE");
EXPECT_EQ(i, 2);
}
TEST_F(Strings, lower_case_find) {
nsCString src("<!DOCTYPE blah blah blah>");
int32_t i = src.LowerCaseFindASCII("doctype", 2);
EXPECT_EQ(i, 2);
i = src.LowerCaseFindASCII("doctype");
EXPECT_EQ(i, 2);
}
TEST_F(Strings, rfind) {
const char text[] = "<!DOCTYPE blah blah blah>";
const char term[] = "bLaH";
const char text[] = "<!DOCTYPE blah bLaH bLaH>";
nsCString src(text);
int32_t i;
i = src.RFind(term, true, 3, -1);
EXPECT_EQ(i, kNotFound);
i = src.RFind(term, true, -1, -1);
i = src.RFind("bLaH");
EXPECT_EQ(i, 20);
i = src.RFind(term, true, 13, -1);
i = src.RFind("blah");
EXPECT_EQ(i, 10);
i = src.RFind(term, true, 22, 3);
EXPECT_EQ(i, 20);
i = src.RFind("BLAH");
EXPECT_EQ(i, kNotFound);
}
TEST_F(Strings, rfind_2) {
const char text[] = "<!DOCTYPE blah blah blah>";
nsCString src(text);
int32_t i = src.RFind("TYPE", false, 5, -1);
int32_t i = src.RFind("TYPE");
EXPECT_EQ(i, 5);
}

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

@ -1991,7 +1991,7 @@ NS_IMETHODIMP AppWindow::SavePersistentAttributes() {
ErrorResult rv;
// (only for size elements which are persisted)
if ((mPersistentAttributesDirty & PAD_POSITION) && gotRestoredBounds) {
if (persistString.Find("screenX") >= 0) {
if (persistString.Find(u"screenX") >= 0) {
sizeString.Truncate();
sizeString.AppendInt(NSToIntRound(rect.X() / posScale.scale));
docShellElement->SetAttribute(SCREENX_ATTRIBUTE, sizeString, rv);
@ -1999,7 +1999,7 @@ NS_IMETHODIMP AppWindow::SavePersistentAttributes() {
Unused << SetPersistentValue(nsGkAtoms::screenX, sizeString);
}
}
if (persistString.Find("screenY") >= 0) {
if (persistString.Find(u"screenY") >= 0) {
sizeString.Truncate();
sizeString.AppendInt(NSToIntRound(rect.Y() / posScale.scale));
docShellElement->SetAttribute(SCREENY_ATTRIBUTE, sizeString, rv);
@ -2012,7 +2012,7 @@ NS_IMETHODIMP AppWindow::SavePersistentAttributes() {
if ((mPersistentAttributesDirty & PAD_SIZE) && gotRestoredBounds) {
LayoutDeviceIntRect innerRect =
rect - GetOuterToInnerSizeDifference(mWindow);
if (persistString.Find("width") >= 0) {
if (persistString.Find(u"width") >= 0) {
sizeString.Truncate();
sizeString.AppendInt(NSToIntRound(innerRect.Width() / sizeScale.scale));
docShellElement->SetAttribute(WIDTH_ATTRIBUTE, sizeString, rv);
@ -2020,7 +2020,7 @@ NS_IMETHODIMP AppWindow::SavePersistentAttributes() {
Unused << SetPersistentValue(nsGkAtoms::width, sizeString);
}
}
if (persistString.Find("height") >= 0) {
if (persistString.Find(u"height") >= 0) {
sizeString.Truncate();
sizeString.AppendInt(NSToIntRound(innerRect.Height() / sizeScale.scale));
docShellElement->SetAttribute(HEIGHT_ATTRIBUTE, sizeString, rv);
@ -2043,7 +2043,7 @@ NS_IMETHODIMP AppWindow::SavePersistentAttributes() {
else
sizeString.Assign(SIZEMODE_NORMAL);
docShellElement->SetAttribute(MODE_ATTRIBUTE, sizeString, rv);
if (shouldPersist && persistString.Find("sizemode") >= 0) {
if (shouldPersist && persistString.Find(u"sizemode") >= 0) {
Unused << SetPersistentValue(nsGkAtoms::sizemode, sizeString);
}
}
@ -2054,7 +2054,7 @@ NS_IMETHODIMP AppWindow::SavePersistentAttributes() {
sizeString.Assign(u"false"_ns);
}
docShellElement->SetAttribute(TILED_ATTRIBUTE, sizeString, rv);
if (persistString.Find("zlevel") >= 0) {
if (persistString.Find(u"zlevel") >= 0) {
uint32_t zLevel;
nsCOMPtr<nsIWindowMediator> mediator(
do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));

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

@ -242,7 +242,7 @@ nsContentTreeOwner::SetPersistence(bool aPersistPosition, bool aPersistSize,
int32_t index;
// Set X
index = persistString.Find("screenX");
index = persistString.Find(u"screenX");
if (!aPersistPosition && index >= 0) {
persistString.Cut(index, 7);
saveString = true;
@ -251,7 +251,7 @@ nsContentTreeOwner::SetPersistence(bool aPersistPosition, bool aPersistSize,
saveString = true;
}
// Set Y
index = persistString.Find("screenY");
index = persistString.Find(u"screenY");
if (!aPersistPosition && index >= 0) {
persistString.Cut(index, 7);
saveString = true;
@ -260,7 +260,7 @@ nsContentTreeOwner::SetPersistence(bool aPersistPosition, bool aPersistSize,
saveString = true;
}
// Set CX
index = persistString.Find("width");
index = persistString.Find(u"width");
if (!aPersistSize && index >= 0) {
persistString.Cut(index, 5);
saveString = true;
@ -269,7 +269,7 @@ nsContentTreeOwner::SetPersistence(bool aPersistPosition, bool aPersistSize,
saveString = true;
}
// Set CY
index = persistString.Find("height");
index = persistString.Find(u"height");
if (!aPersistSize && index >= 0) {
persistString.Cut(index, 6);
saveString = true;
@ -278,7 +278,7 @@ nsContentTreeOwner::SetPersistence(bool aPersistPosition, bool aPersistSize,
saveString = true;
}
// Set SizeMode
index = persistString.Find("sizemode");
index = persistString.Find(u"sizemode");
if (!aPersistSizeMode && (index >= 0)) {
persistString.Cut(index, 8);
saveString = true;
@ -307,18 +307,17 @@ nsContentTreeOwner::GetPersistence(bool* aPersistPosition, bool* aPersistSize,
// data structure doesn't quite match the question, but it's close enough
// for what we want (since this method is never actually called...)
if (aPersistPosition)
*aPersistPosition =
persistString.Find("screenX") >= 0 || persistString.Find("screenY") >= 0
? true
: false;
if (aPersistSize)
if (aPersistPosition) {
*aPersistPosition = persistString.Find(u"screenX") >= 0 ||
persistString.Find(u"screenY") >= 0;
}
if (aPersistSize) {
*aPersistSize =
persistString.Find("width") >= 0 || persistString.Find("height") >= 0
? true
: false;
if (aPersistSizeMode)
*aPersistSizeMode = persistString.Find("sizemode") >= 0 ? true : false;
persistString.Find(u"width") >= 0 || persistString.Find(u"height") >= 0;
}
if (aPersistSizeMode) {
*aPersistSizeMode = persistString.Find(u"sizemode") >= 0;
}
return NS_OK;
}