本文整理汇总了C++中nsString::Find方法的典型用法代码示例。如果您正苦于以下问题:C++ nsString::Find方法的具体用法?C++ nsString::Find怎么用?C++ nsString::Find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsString
的用法示例。
在下文中一共展示了nsString::Find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CleanupHandlerPath
// Strip a handler command string of its quotes and parameters.
static void CleanupHandlerPath(nsString& aPath)
{
// Example command strings passed into this routine:
// 1) C:\Program Files\Company\some.exe -foo -bar
// 2) C:\Program Files\Company\some.dll
// 3) C:\Windows\some.dll,-foo -bar
// 4) C:\Windows\some.cpl,-foo -bar
int32_t lastCommaPos = aPath.RFindChar(',');
if (lastCommaPos != kNotFound)
aPath.Truncate(lastCommaPos);
aPath.Append(' ');
// case insensitive
uint32_t index = aPath.Find(".exe ", true);
if (index == kNotFound)
index = aPath.Find(".dll ", true);
if (index == kNotFound)
index = aPath.Find(".cpl ", true);
if (index != kNotFound)
aPath.Truncate(index + 4);
aPath.Trim(" ", true, true);
}
示例2: if
static void
ParseAlignAttribute(nsString& aValue, eAlign& aAlign, PRInt32& aRowIndex)
{
// by default, the table is centered about the axis
aRowIndex = 0;
aAlign = eAlign_axis;
PRInt32 len = 0;
if (0 == aValue.Find("top")) {
len = 3; // 3 is the length of 'top'
aAlign = eAlign_top;
}
else if (0 == aValue.Find("bottom")) {
len = 6; // 6 is the length of 'bottom'
aAlign = eAlign_bottom;
}
else if (0 == aValue.Find("center")) {
len = 6; // 6 is the length of 'center'
aAlign = eAlign_center;
}
else if (0 == aValue.Find("baseline")) {
len = 8; // 8 is the length of 'baseline'
aAlign = eAlign_baseline;
}
else if (0 == aValue.Find("axis")) {
len = 4; // 4 is the length of 'axis'
aAlign = eAlign_axis;
}
if (len) {
PRInt32 error;
aValue.Cut(0, len); // aValue is not a const here
aRowIndex = aValue.ToInteger(&error);
if (error)
aRowIndex = 0;
}
}
示例3: normalizeDriverId
// The driver ID is a string like PCI\VEN_15AD&DEV_0405&SUBSYS_040515AD, possibly
// followed by &REV_XXXX. We uppercase the string, and strip the &REV_ part
// from it, if found.
static void normalizeDriverId(nsString& driverid) {
ToUpperCase(driverid);
PRInt32 rev = driverid.Find(NS_LITERAL_CSTRING("&REV_"));
if (rev != -1) {
driverid.Cut(rev, driverid.Length());
}
}
示例4: also
/**
Ensures basic sanity of attribute value.
This function also (tries to :-( ) makes sure, that no
unwanted / dangerous URLs appear in the document
(like javascript: and data:).
Pass the value as |aValue| arg. It will be modified in-place.
If the value is not allowed at all, we return with NS_ERROR_ILLEGAL_VALUE.
In that case, do not use the |aValue|, but output nothing.
*/
nsresult
mozSanitizingHTMLSerializer::SanitizeAttrValue(nsHTMLTag aTag,
const nsAString& anAttrName,
nsString& aValue /*inout*/)
{
/* First, cut the attribute to 1000 chars.
Attributes with values longer than 1000 chars seem bogus,
considering that we don't support any JS. The longest attributes
I can think of are URLs, and URLs with 1000 chars are likely to be
bogus, too. */
aValue = Substring(aValue, 0, 1000);
//aValue.Truncate(1000); //-- this cuts half of the document !!?!!
aValue.Adopt(escape(aValue));
/* Check some known bad stuff. Add more!
I don't care too much, if it happens to trigger in some innocent cases
(like <img alt="Statistical data: Mortage rates and newspapers">) -
security first. */
if (aValue.Find("javascript:") != kNotFound ||
aValue.Find("data:") != kNotFound ||
aValue.Find("base64") != kNotFound)
return NS_ERROR_ILLEGAL_VALUE;
// Check img src scheme
if (aTag == eHTMLTag_img &&
anAttrName.LowerCaseEqualsLiteral("src"))
{
nsresult rv;
nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString scheme;
rv = ioService->ExtractScheme(NS_LossyConvertUTF16toASCII(aValue), scheme);
NS_ENSURE_SUCCESS(rv, rv);
if (!scheme.Equals("cid", nsCaseInsensitiveCStringComparator()))
return NS_ERROR_ILLEGAL_VALUE;
}
#ifdef DEBUG_BenB
printf("attribute value for %s: -%s-\n",
NS_LossyConvertUTF16toASCII(anAttrName).get(),
NS_LossyConvertUTF16toASCII(aValue).get());
#endif
return NS_OK;
}
示例5: defined
void
MediaEngineCameraVideoSource::SetName(nsString aName)
{
mDeviceName = aName;
bool hasFacingMode = false;
VideoFacingModeEnum facingMode = VideoFacingModeEnum::User;
// Set facing mode based on device name.
#if defined(MOZ_B2G_CAMERA) && defined(MOZ_WIDGET_GONK)
if (aName.EqualsLiteral("back")) {
hasFacingMode = true;
facingMode = VideoFacingModeEnum::Environment;
} else if (aName.EqualsLiteral("front")) {
hasFacingMode = true;
facingMode = VideoFacingModeEnum::User;
}
#endif // MOZ_B2G_CAMERA
#if defined(ANDROID) && !defined(MOZ_WIDGET_GONK)
// Names are generated. Example: "Camera 0, Facing back, Orientation 90"
//
// See media/webrtc/trunk/webrtc/modules/video_capture/android/java/src/org/
// webrtc/videoengine/VideoCaptureDeviceInfoAndroid.java
if (aName.Find(NS_LITERAL_STRING("Facing back")) != kNotFound) {
hasFacingMode = true;
facingMode = VideoFacingModeEnum::Environment;
} else if (aName.Find(NS_LITERAL_STRING("Facing front")) != kNotFound) {
hasFacingMode = true;
facingMode = VideoFacingModeEnum::User;
}
#endif // ANDROID
#ifdef XP_MACOSX
// Kludge to test user-facing cameras on OSX.
if (aName.Find(NS_LITERAL_STRING("Face")) != -1) {
hasFacingMode = true;
facingMode = VideoFacingModeEnum::User;
}
#endif
if (hasFacingMode) {
mFacingMode.Assign(NS_ConvertUTF8toUTF16(
VideoFacingModeEnumValues::strings[uint32_t(facingMode)].value));
} else {
mFacingMode.Truncate();
}
}
示例6: IsAddressBookNameUnique
bool nsOutlookMail::IsAddressBookNameUnique(nsString& name, nsString& list)
{
nsString usedName;
usedName.AppendLiteral("[");
usedName.Append(name);
usedName.AppendLiteral("],");
return list.Find(usedName) == -1;
}
示例7: DoAsyncPrompt
void
EmbedAuthPromptService::DoResponseAsyncPrompt(EmbedAsyncAuthPrompt* prompt,
const bool& confirmed,
const nsString& username,
const nsString& password)
{
nsresult rv;
asyncPrompts.erase(prompt->mHashKey.get());
prompt->mInProgress = false;
if (prompt->mWin) {
asyncPromptInProgress.erase(prompt->mWin);
}
// Fill authentication information with username and password provided
// by user.
uint32_t flags;
rv = prompt->mAuthInfo->GetFlags(&flags);
NS_ENSURE_SUCCESS(rv, );
if (!username.IsEmpty()) {
if (flags & nsIAuthInformation::NEED_DOMAIN) {
// Domain is separated from username by a backslash
int idx = username.Find("\\");
if (idx == -1) {
prompt->mAuthInfo->SetUsername(username);
} else {
prompt->mAuthInfo->SetDomain(nsDependentSubstring(username, 0, idx));
prompt->mAuthInfo->SetUsername(nsDependentSubstring(username, idx + 1));
}
} else {
prompt->mAuthInfo->SetUsername(username);
}
}
if (!password.IsEmpty()) {
prompt->mAuthInfo->SetPassword(password);
}
for (unsigned int i = 0; i < prompt->consumers.Length(); i++) {
nsRefPtr<nsAuthCancelableConsumer> consumer = static_cast<nsAuthCancelableConsumer*>(prompt->consumers[i].get());
if (!consumer->mCallback) {
// Not having a callback means that consumer didn't provide it
// or canceled the notification.
continue;
}
if (confirmed) {
// printf("Ok, calling onAuthAvailable to finish auth.\n");
consumer->mCallback->OnAuthAvailable(consumer->mContext, prompt->mAuthInfo);
} else {
// printf("Cancelled, calling onAuthCancelled to finish auth.\n");
consumer->mCallback->OnAuthCancelled(consumer->mContext, true);
}
}
// Process the next prompt, if one is pending.
DoAsyncPrompt();
}
示例8: if
static void
ParseAlignAttribute(nsString& aValue, eAlign& aAlign, int32_t& aRowIndex)
{
// by default, the table is centered about the axis
aRowIndex = 0;
aAlign = eAlign_axis;
int32_t len = 0;
// we only have to remove the leading spaces because
// ToInteger ignores the whitespaces around the number
aValue.CompressWhitespace(true, false);
if (0 == aValue.Find("top")) {
len = 3; // 3 is the length of 'top'
aAlign = eAlign_top;
}
else if (0 == aValue.Find("bottom")) {
len = 6; // 6 is the length of 'bottom'
aAlign = eAlign_bottom;
}
else if (0 == aValue.Find("center")) {
len = 6; // 6 is the length of 'center'
aAlign = eAlign_center;
}
else if (0 == aValue.Find("baseline")) {
len = 8; // 8 is the length of 'baseline'
aAlign = eAlign_baseline;
}
else if (0 == aValue.Find("axis")) {
len = 4; // 4 is the length of 'axis'
aAlign = eAlign_axis;
}
if (len) {
nsresult error;
aValue.Cut(0, len); // aValue is not a const here
aRowIndex = aValue.ToInteger(&error);
if (NS_FAILED(error))
aRowIndex = 0;
}
}
示例9:
// Strip the windows host process bootstrap executable rundll32.exe
// from a handler's command string if it exists.
static void StripRundll32(nsString& aCommandString)
{
// Example rundll formats:
// C:\Windows\System32\rundll32.exe "path to dll"
// rundll32.exe "path to dll"
// C:\Windows\System32\rundll32.exe "path to dll", var var
// rundll32.exe "path to dll", var var
NS_NAMED_LITERAL_STRING(rundllSegment, "rundll32.exe ");
NS_NAMED_LITERAL_STRING(rundllSegmentShort, "rundll32 ");
// case insensitive
int32_t strLen = rundllSegment.Length();
int32_t index = aCommandString.Find(rundllSegment, true);
if (index == kNotFound) {
strLen = rundllSegmentShort.Length();
index = aCommandString.Find(rundllSegmentShort, true);
}
if (index != kNotFound) {
uint32_t rundllSegmentLength = index + strLen;
aCommandString.Cut(0, rundllSegmentLength);
}
}
示例10: ExtractCharset
void nsEudoraCompose::ExtractCharset( nsString& str)
{
nsString tStr;
PRInt32 idx = str.Find( "charset=", PR_TRUE);
if (idx != -1) {
idx += 8;
str.Right( tStr, str.Length() - idx);
idx = tStr.FindChar( ';');
if (idx != -1)
tStr.Left( str, idx);
else
str = tStr;
str.Trim( kWhitespace);
if ((str.CharAt( 0) == '"') && (str.Length() > 2)) {
str.Mid( tStr, 1, str.Length() - 2);
str = tStr;
str.Trim( kWhitespace);
}
}
else
str.Truncate();
}
示例11: if
nsresult
nsRDFParserUtils::GetQuotedAttributeValue(const nsString& aSource,
const nsString& aAttribute,
nsString& aValue)
{
static const char kQuote = '\"';
static const char kApostrophe = '\'';
PRInt32 offset;
PRInt32 endOffset = -1;
nsresult result = NS_OK;
offset = aSource.Find(aAttribute, 0);
if (-1 != offset) {
offset = aSource.FindChar('=', offset);
PRUnichar next = aSource.CharAt(++offset);
if (kQuote == next) {
endOffset = aSource.FindChar(kQuote, ++offset);
}
else if (kApostrophe == next) {
endOffset = aSource.FindChar(kApostrophe, ++offset);
}
if (-1 != endOffset) {
aSource.Mid(aValue, offset, endOffset-offset);
}
else {
// Mismatched quotes - return an error
result = NS_ERROR_FAILURE;
}
}
else {
aValue.Truncate();
}
return result;
}
示例12: rest
void
mozTXTToHTMLConv::ScanHTML(nsString& aInString, PRUint32 whattodo, nsString &aOutString)
{
// some common variables we were recalculating
// every time inside the for loop...
PRInt32 lengthOfInString = aInString.Length();
const PRUnichar * uniBuffer = aInString.get();
#ifdef DEBUG_BenB_Perf
PRTime parsing_start = PR_IntervalNow();
#endif
// Look for simple entities not included in a tags and scan them.
/* Skip all tags ("<[...]>") and content in an a tag ("<a[...]</a>")
or in a tag ("<!--[...]-->").
Unescape the rest (text between tags) and pass it to ScanTXT. */
for (PRInt32 i = 0; i < lengthOfInString;)
{
if (aInString[i] == '<') // html tag
{
PRUint32 start = PRUint32(i);
if (nsCRT::ToLower((char)aInString[PRUint32(i) + 1]) == 'a')
// if a tag, skip until </a>
{
i = aInString.Find("</a>", true, i);
if (i == kNotFound)
i = lengthOfInString;
else
i += 4;
}
else if (aInString[PRUint32(i) + 1] == '!' && aInString[PRUint32(i) + 2] == '-' &&
aInString[PRUint32(i) + 3] == '-')
//if out-commended code, skip until -->
{
i = aInString.Find("-->", false, i);
if (i == kNotFound)
i = lengthOfInString;
else
i += 3;
}
else // just skip tag (attributes etc.)
{
i = aInString.FindChar('>', i);
if (i == kNotFound)
i = lengthOfInString;
else
i++;
}
aOutString.Append(&uniBuffer[start], PRUint32(i) - start);
}
else
{
PRUint32 start = PRUint32(i);
i = aInString.FindChar('<', i);
if (i == kNotFound)
i = lengthOfInString;
nsString tempString;
tempString.SetCapacity(PRUint32((PRUint32(i) - start) * growthRate));
UnescapeStr(uniBuffer, start, PRUint32(i) - start, tempString);
ScanTXT(tempString.get(), tempString.Length(), whattodo, aOutString);
}
}
#ifdef DEBUG_BenB_Perf
printf("ScanHTML time: %d ms\n", PR_IntervalToMilliseconds(PR_IntervalNow() - parsing_start));
#endif
}
示例13: if
void
mozTXTToHTMLConv::ScanHTML(nsString& aInString, uint32_t whattodo, nsString &aOutString)
{
// some common variables we were recalculating
// every time inside the for loop...
int32_t lengthOfInString = aInString.Length();
const char16_t * uniBuffer = aInString.get();
#ifdef DEBUG_BenB_Perf
PRTime parsing_start = PR_IntervalNow();
#endif
// Look for simple entities not included in a tags and scan them.
// Skip all tags ("<[...]>") and content in an a link tag ("<a [...]</a>"),
// comment tag ("<!--[...]-->"), style tag, script tag or head tag.
// Unescape the rest (text between tags) and pass it to ScanTXT.
for (int32_t i = 0; i < lengthOfInString;)
{
if (aInString[i] == '<') // html tag
{
int32_t start = i;
if (Substring(aInString, i + 1, 2).LowerCaseEqualsASCII("a "))
// if a tag, skip until </a>.
// Make sure there's a space after, not to match "abbr".
{
i = aInString.Find("</a>", true, i);
if (i == kNotFound)
i = lengthOfInString;
else
i += 4;
}
else if (Substring(aInString, i + 1, 3).LowerCaseEqualsASCII("!--"))
// if out-commended code, skip until -->
{
i = aInString.Find("-->", false, i);
if (i == kNotFound)
i = lengthOfInString;
else
i += 3;
}
else if (Substring(aInString, i + 1, 5).LowerCaseEqualsASCII("style") &&
(aInString.CharAt(i + 6) == ' ' || aInString.CharAt(i + 6) == '>'))
// if style tag, skip until </style>
{
i = aInString.Find("</style>", true, i);
if (i == kNotFound)
i = lengthOfInString;
else
i += 8;
}
else if (Substring(aInString, i + 1, 6).LowerCaseEqualsASCII("script") &&
(aInString.CharAt(i + 7) == ' ' || aInString.CharAt(i + 7) == '>'))
// if script tag, skip until </script>
{
i = aInString.Find("</script>", true, i);
if (i == kNotFound)
i = lengthOfInString;
else
i += 9;
}
else if (Substring(aInString, i + 1, 4).LowerCaseEqualsASCII("head") &&
(aInString.CharAt(i + 5) == ' ' || aInString.CharAt(i + 5) == '>'))
// if head tag, skip until </head>
// Make sure not to match <header>.
{
i = aInString.Find("</head>", true, i);
if (i == kNotFound)
i = lengthOfInString;
else
i += 7;
}
else // just skip tag (attributes etc.)
{
i = aInString.FindChar('>', i);
if (i == kNotFound)
i = lengthOfInString;
else
i++;
}
aOutString.Append(&uniBuffer[start], i - start);
}
else
{
uint32_t start = uint32_t(i);
i = aInString.FindChar('<', i);
if (i == kNotFound)
i = lengthOfInString;
nsString tempString;
tempString.SetCapacity(uint32_t((uint32_t(i) - start) * growthRate));
UnescapeStr(uniBuffer, start, uint32_t(i) - start, tempString);
ScanTXT(tempString.get(), tempString.Length(), whattodo, aOutString);
}
}
#ifdef DEBUG_BenB_Perf
printf("ScanHTML time: %d ms\n", PR_IntervalToMilliseconds(PR_IntervalNow() - parsing_start));
#endif
}
示例14: EmptyString
void
nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
{
aNewStr = aStr;
// Search to see if the &D code is in the string
// then subst in the current date/time
NS_NAMED_LITERAL_STRING(kDate, "&D");
if (aStr.Find(kDate) != kNotFound) {
if (mPD->mDateTimeStr != nsnull) {
aNewStr.ReplaceSubstring(kDate.get(), mPD->mDateTimeStr);
} else {
aNewStr.ReplaceSubstring(kDate.get(), EmptyString().get());
}
}
// NOTE: Must search for &PT before searching for &P
//
// Search to see if the "page number and page" total code are in the string
// and replace the page number and page total code with the actual
// values
NS_NAMED_LITERAL_STRING(kPageAndTotal, "&PT");
if (aStr.Find(kPageAndTotal) != kNotFound) {
PRUnichar * uStr = nsTextFormatter::smprintf(mPD->mPageNumAndTotalsFormat, mPageNum, mTotNumPages);
aNewStr.ReplaceSubstring(kPageAndTotal.get(), uStr);
nsMemory::Free(uStr);
}
// Search to see if the page number code is in the string
// and replace the page number code with the actual value
NS_NAMED_LITERAL_STRING(kPage, "&P");
if (aStr.Find(kPage) != kNotFound) {
PRUnichar * uStr = nsTextFormatter::smprintf(mPD->mPageNumFormat, mPageNum);
aNewStr.ReplaceSubstring(kPage.get(), uStr);
nsMemory::Free(uStr);
}
NS_NAMED_LITERAL_STRING(kTitle, "&T");
if (aStr.Find(kTitle) != kNotFound) {
if (mPD->mDocTitle != nsnull) {
aNewStr.ReplaceSubstring(kTitle.get(), mPD->mDocTitle);
} else {
aNewStr.ReplaceSubstring(kTitle.get(), EmptyString().get());
}
}
NS_NAMED_LITERAL_STRING(kDocURL, "&U");
if (aStr.Find(kDocURL) != kNotFound) {
if (mPD->mDocURL != nsnull) {
aNewStr.ReplaceSubstring(kDocURL.get(), mPD->mDocURL);
} else {
aNewStr.ReplaceSubstring(kDocURL.get(), EmptyString().get());
}
}
NS_NAMED_LITERAL_STRING(kPageTotal, "&L");
if (aStr.Find(kPageTotal) != kNotFound) {
PRUnichar * uStr = nsTextFormatter::smprintf(mPD->mPageNumFormat, mTotNumPages);
aNewStr.ReplaceSubstring(kPageTotal.get(), uStr);
nsMemory::Free(uStr);
}
}
示例15: GetField
bool nsTextAddress::GetField(const nsAString &aLine, int32_t index,
nsString &field, char16_t delim) {
bool result = false;
int32_t pos = 0;
int32_t maxLen = aLine.Length();
char16_t tab = char16_t('\t');
char16_t doubleQuote = char16_t('"');
field.Truncate();
if (delim == tab) tab = 0;
while (index && (pos < maxLen)) {
while (((aLine[pos] == char16_t(' ')) || (aLine[pos] == tab)) &&
(pos < maxLen)) {
pos++;
}
if (pos >= maxLen) break;
if (aLine[pos] == doubleQuote) {
do {
pos++;
if (((pos + 1) < maxLen) && (aLine[pos] == doubleQuote) &&
(aLine[pos + 1] == doubleQuote)) {
pos += 2;
}
} while ((pos < maxLen) && (aLine[pos] != doubleQuote));
if (pos < maxLen) pos++;
}
if (pos >= maxLen) break;
while ((pos < maxLen) && (aLine[pos] != delim)) pos++;
if (pos >= maxLen) break;
index--;
pos++;
}
if (pos >= maxLen) return result;
result = true;
while ((pos < maxLen) && ((aLine[pos] == ' ') || (aLine[pos] == tab))) pos++;
int32_t fLen = 0;
int32_t startPos = pos;
bool quoted = false;
if (aLine[pos] == '"') {
startPos++;
fLen = -1;
do {
pos++;
fLen++;
if (((pos + 1) < maxLen) && (aLine[pos] == doubleQuote) &&
(aLine[pos + 1] == doubleQuote)) {
quoted = true;
pos += 2;
fLen += 2;
}
} while ((pos < maxLen) && (aLine[pos] != doubleQuote));
} else {
while ((pos < maxLen) && (aLine[pos] != delim)) {
pos++;
fLen++;
}
}
if (!fLen) {
return result;
}
field.Append(nsDependentSubstring(aLine, startPos, fLen));
field.Trim(kWhitespace);
if (quoted) {
int32_t offset = field.Find("\"\"");
while (offset != -1) {
field.Cut(offset, 1);
offset = MsgFind(field, "\"\"", false, offset + 1);
}
}
return result;
}