本文整理汇总了C++中nsAString::Replace方法的典型用法代码示例。如果您正苦于以下问题:C++ nsAString::Replace方法的具体用法?C++ nsAString::Replace怎么用?C++ nsAString::Replace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsAString
的用法示例。
在下文中一共展示了nsAString::Replace方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nsDependentString
NS_StringSetDataRange(nsAString& aStr,
uint32_t aCutOffset, uint32_t aCutLength,
const char16_t* aData, uint32_t aDataLength)
{
if (aCutOffset == UINT32_MAX) {
// append case
if (aData) {
aStr.Append(aData, aDataLength);
}
return NS_OK; // XXX report errors
}
if (aCutLength == UINT32_MAX) {
aCutLength = aStr.Length() - aCutOffset;
}
if (aData) {
if (aDataLength == UINT32_MAX) {
aStr.Replace(aCutOffset, aCutLength, nsDependentString(aData));
} else {
aStr.Replace(aCutOffset, aCutLength, Substring(aData, aDataLength));
}
} else {
aStr.Cut(aCutOffset, aCutLength);
}
return NS_OK; // XXX report errors
}
示例2: nsDependentString
NS_StringSetDataRange(nsAString &aStr,
PRUint32 aCutOffset, PRUint32 aCutLength,
const PRUnichar *aData, PRUint32 aDataLength)
{
if (aCutOffset == PR_UINT32_MAX)
{
// append case
if (aData)
aStr.Append(aData, aDataLength);
return NS_OK; // XXX report errors
}
if (aCutLength == PR_UINT32_MAX)
aCutLength = aStr.Length() - aCutOffset;
if (aData)
{
if (aDataLength == PR_UINT32_MAX)
aStr.Replace(aCutOffset, aCutLength, nsDependentString(aData));
else
aStr.Replace(aCutOffset, aCutLength, Substring(aData, aDataLength));
}
else
aStr.Cut(aCutOffset, aCutLength);
return NS_OK; // XXX report errors
}
示例3: ConvertTexttoAsterisks
void ConvertTexttoAsterisks(nsAccessibleWrap* accWrap, nsAString& aString)
{
// convert each char to "*" when it's "password text"
PRUint32 atkRole = atkRoleMap[accWrap->NativeRole()];
if (atkRole == ATK_ROLE_PASSWORD_TEXT) {
for (PRUint32 i = 0; i < aString.Length(); i++)
aString.Replace(i, 1, NS_LITERAL_STRING("*"));
}
}
示例4: while
static void
__ReplaceChar (nsAString &string, const PRUnichar replace, const PRUnichar with)
{
PRInt32 i = string.FindChar (replace);
while (i >= 0) {
string.Replace (i, 1, &with, 1);
i = string.FindChar (replace);
}
}
示例5:
static void
ConvertTexttoAsterisks(AccessibleWrap* accWrap, nsAString& aString)
{
// convert each char to "*" when it's "password text"
if (accWrap->NativeRole() == roles::PASSWORD_TEXT) {
for (uint32_t i = 0; i < aString.Length(); i++)
aString.Replace(i, 1, NS_LITERAL_STRING("*"));
}
}
示例6:
bool
GetIDFromMinidump(nsILocalFile* minidump, nsAString& id)
{
if (NS_SUCCEEDED(minidump->GetLeafName(id))) {
id.Replace(id.Length() - 4, 4, NS_LITERAL_STRING(""));
return true;
}
return false;
}
示例7: langTokenizer
/**
* JS property navigator.language, exposed to web content.
* Take first value from Accept-Languages (HTTP header), which is
* the "content language" freely set by the user in the Pref window.
*
* Do not use UI language (chosen app locale) here.
* See RFC 2616, Section 15.1.4 "Privacy Issues Connected to Accept Headers"
*
* "en", "en-US" and "i-cherokee" and "" are valid.
* Fallback in case of invalid pref should be "" (empty string), to
* let site do fallback, e.g. to site's local language.
*/
NS_IMETHODIMP
Navigator::GetLanguage(nsAString& aLanguage)
{
// E.g. "de-de, en-us,en".
const nsAdoptingString& acceptLang =
Preferences::GetLocalizedString("intl.accept_languages");
// Take everything before the first "," or ";", without trailing space.
nsCharSeparatedTokenizer langTokenizer(acceptLang, ',');
const nsSubstring &firstLangPart = langTokenizer.nextToken();
nsCharSeparatedTokenizer qTokenizer(firstLangPart, ';');
aLanguage.Assign(qTokenizer.nextToken());
// Checks and fixups:
// replace "_" with "-" to avoid POSIX/Windows "en_US" notation.
if (aLanguage.Length() > 2 && aLanguage[2] == PRUnichar('_')) {
aLanguage.Replace(2, 1, PRUnichar('-')); // TODO replace all
}
// Use uppercase for country part, e.g. "en-US", not "en-us", see BCP47
// only uppercase 2-letter country codes, not "zh-Hant", "de-DE-x-goethe".
if (aLanguage.Length() <= 2) {
return NS_OK;
}
nsCharSeparatedTokenizer localeTokenizer(aLanguage, '-');
int32_t pos = 0;
bool first = true;
while (localeTokenizer.hasMoreTokens()) {
const nsSubstring& code = localeTokenizer.nextToken();
if (code.Length() == 2 && !first) {
nsAutoString upper(code);
ToUpperCase(upper);
aLanguage.Replace(pos, code.Length(), upper);
}
pos += code.Length() + 1; // 1 is the separator
first = false;
}
return NS_OK;
}
示例8: normalizeFullStops
void nsIDNService::normalizeFullStops(nsAString& s)
{
nsAString::const_iterator start, end;
s.BeginReading(start);
s.EndReading(end);
int32_t index = 0;
while (start != end) {
switch (*start) {
case 0x3002:
case 0xFF0E:
case 0xFF61:
s.Replace(index, 1, NS_LITERAL_STRING("."));
break;
default:
break;
}
start++;
index++;
}
}
示例9: nsDependentString
/** ---------------------------------------------------
* Helper function - Returns either the name or sets the length to zero
*/
static nsresult
GetAdjustedPrinterName(nsIPrintSettings* aPS, bool aUsePNP,
nsAString& aPrinterName)
{
NS_ENSURE_ARG_POINTER(aPS);
aPrinterName.Truncate();
if (!aUsePNP)
return NS_OK;
// Get the Printer Name from the PrintSettings
// to use as a prefix for Pref Names
char16_t* prtName = nullptr;
nsresult rv = aPS->GetPrinterName(&prtName);
NS_ENSURE_SUCCESS(rv, rv);
aPrinterName = nsDependentString(prtName);
// Convert any whitespaces, carriage returns or newlines to _
// The below algorithm is supposedly faster than using iterators
NS_NAMED_LITERAL_STRING(replSubstr, "_");
const char* replaceStr = " \n\r";
int32_t x;
for (x=0; x < (int32_t)strlen(replaceStr); x++) {
char16_t uChar = replaceStr[x];
int32_t i = 0;
while ((i = aPrinterName.FindChar(uChar, i)) != kNotFound) {
aPrinterName.Replace(i, 1, replSubstr);
i++;
}
}
return NS_OK;
}
示例10: GetCurrentDirectoryW
static bool
GetCurrentWorkingDirectory(nsAString& workingDirectory)
{
#if !defined(XP_WIN) && !defined(XP_UNIX)
//XXX: your platform should really implement this
return false;
#elif XP_WIN
DWORD requiredLength = GetCurrentDirectoryW(0, nullptr);
workingDirectory.SetLength(requiredLength);
GetCurrentDirectoryW(workingDirectory.Length(),
(LPWSTR)workingDirectory.BeginWriting());
// we got a trailing null there
workingDirectory.SetLength(requiredLength);
workingDirectory.Replace(workingDirectory.Length() - 1, 1, L'\\');
#elif defined(XP_UNIX)
nsAutoCString cwd;
// 1024 is just a guess at a sane starting value
size_t bufsize = 1024;
char* result = nullptr;
while (result == nullptr) {
cwd.SetLength(bufsize);
result = getcwd(cwd.BeginWriting(), cwd.Length());
if (!result) {
if (errno != ERANGE)
return false;
// need to make the buffer bigger
bufsize *= 2;
}
}
// size back down to the actual string length
cwd.SetLength(strlen(result) + 1);
cwd.Replace(cwd.Length() - 1, 1, '/');
workingDirectory = NS_ConvertUTF8toUTF16(cwd);
#endif
return true;
}
示例11: if
//.........这里部分代码省略.........
// has a ":" that can't be escaped and (b) all pseudo-elements at
// this point are known, and therefore we know they don't need
// escaping.
aString.Append(tag);
} else {
nsStyleUtil::AppendEscapedCSSIdent(tag, aString);
}
}
// Append the id, if there is one
if (mIDList) {
nsAtomList* list = mIDList;
while (list != nsnull) {
list->mAtom->ToString(temp);
aString.Append(PRUnichar('#'));
nsStyleUtil::AppendEscapedCSSIdent(temp, aString);
list = list->mNext;
}
}
// Append each class in the linked list
if (mClassList) {
if (isPseudoElement) {
#ifdef MOZ_XUL
NS_ABORT_IF_FALSE(nsCSSAnonBoxes::IsTreePseudoElement(mLowercaseTag),
"must be tree pseudo-element");
aString.Append(PRUnichar('('));
for (nsAtomList* list = mClassList; list; list = list->mNext) {
nsStyleUtil::AppendEscapedCSSIdent(nsDependentAtomString(list->mAtom), aString);
aString.Append(PRUnichar(','));
}
// replace the final comma with a close-paren
aString.Replace(aString.Length() - 1, 1, PRUnichar(')'));
#else
NS_ERROR("Can't happen");
#endif
} else {
nsAtomList* list = mClassList;
while (list != nsnull) {
list->mAtom->ToString(temp);
aString.Append(PRUnichar('.'));
nsStyleUtil::AppendEscapedCSSIdent(temp, aString);
list = list->mNext;
}
}
}
// Append each attribute selector in the linked list
if (mAttrList) {
nsAttrSelector* list = mAttrList;
while (list != nsnull) {
aString.Append(PRUnichar('['));
// Append the namespace prefix
if (list->mNameSpace == kNameSpaceID_Unknown) {
aString.Append(PRUnichar('*'));
aString.Append(PRUnichar('|'));
} else if (list->mNameSpace != kNameSpaceID_None) {
if (aSheet) {
nsXMLNameSpaceMap *sheetNS = aSheet->GetNameSpaceMap();
nsIAtom *prefixAtom = sheetNS->FindPrefix(list->mNameSpace);
// Default namespaces don't apply to attribute selectors, so
// we must have a useful prefix.
NS_ASSERTION(prefixAtom,
"How did we end up with a namespace if the prefix "
"is unknown?");
示例12: GetWindowsLocaleFor
/**
* Windows API includes regional preferences from the user only
* if we pass empty locale string or if the locale string matches
* the current locale.
*
* Since Windows API only allows us to retrieve two options - short/long
* we map it to our four options as:
*
* short -> short
* medium -> short
* long -> long
* full -> long
*
* In order to produce a single date/time format, we use CLDR pattern
* for combined date/time string, since Windows API does not provide an
* option for this.
*/
bool
OSPreferences::ReadDateTimePattern(DateTimeFormatStyle aDateStyle,
DateTimeFormatStyle aTimeStyle,
const nsACString& aLocale, nsAString& aRetVal)
{
WCHAR buffer[LOCALE_NAME_MAX_LENGTH];
LPWSTR localeName = GetWindowsLocaleFor(aLocale, buffer);
bool isDate = aDateStyle != DateTimeFormatStyle::None &&
aDateStyle != DateTimeFormatStyle::Invalid;
bool isTime = aTimeStyle != DateTimeFormatStyle::None &&
aTimeStyle != DateTimeFormatStyle::Invalid;
// If both date and time are wanted, we'll initially read them into a
// local string, and then insert them into the overall date+time pattern;
// but if only one is needed we'll work directly with the return value.
// Set 'str' to point to the string we will use to retrieve patterns
// from Windows.
nsAutoString tmpStr;
nsAString* str;
if (isDate && isTime) {
if (!GetDateTimeConnectorPattern(NS_ConvertUTF16toUTF8(localeName), aRetVal)) {
NS_WARNING("failed to get date/time connector");
aRetVal.AssignLiteral(u"{1} {0}");
}
str = &tmpStr;
} else if (isDate || isTime) {
str = &aRetVal;
} else {
aRetVal.Truncate(0);
return true;
}
if (isDate) {
LCTYPE lcType = ToDateLCType(aDateStyle);
size_t len = GetLocaleInfoEx(localeName, lcType, nullptr, 0);
if (len == 0) {
return false;
}
// We're doing it to ensure the terminator will fit when Windows writes the data
// to its output buffer. See bug 1358159 for details.
str->SetLength(len);
GetLocaleInfoEx(localeName, lcType, (WCHAR*)str->BeginWriting(), len);
str->SetLength(len - 1); // -1 because len counts the null terminator
// Windows uses "ddd" and "dddd" for abbreviated and full day names respectively,
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd317787(v=vs.85).aspx
// but in a CLDR/ICU-style pattern these should be "EEE" and "EEEE".
// http://userguide.icu-project.org/formatparse/datetime
// So we fix that up here.
nsAString::const_iterator start, pos, end;
start = str->BeginReading(pos);
str->EndReading(end);
if (FindInReadable(NS_LITERAL_STRING("dddd"), pos, end)) {
str->Replace(pos - start, 4, NS_LITERAL_STRING("EEEE"));
} else if (FindInReadable(NS_LITERAL_STRING("ddd"), pos, end)) {
str->Replace(pos - start, 3, NS_LITERAL_STRING("EEE"));
}
// Also, Windows uses lowercase "g" or "gg" for era, but ICU wants uppercase "G"
// (it would interpret "g" as "modified Julian day"!). So fix that.
int32_t index = str->FindChar('g');
if (index >= 0) {
str->Replace(index, 1, 'G');
// If it was a double "gg", just drop the second one.
index++;
if (str->CharAt(index) == 'g') {
str->Cut(index, 1);
}
}
// If time was also requested, we need to substitute the date pattern from Windows
// into the date+time format that we have in aRetVal.
if (isTime) {
nsAString::const_iterator start, pos, end;
start = aRetVal.BeginReading(pos);
aRetVal.EndReading(end);
if (FindInReadable(NS_LITERAL_STRING("{1}"), pos, end)) {
aRetVal.Replace(pos - start, 3, tmpStr);
}
}
//.........这里部分代码省略.........