本文整理汇总了C++中nsACString::FindChar方法的典型用法代码示例。如果您正苦于以下问题:C++ nsACString::FindChar方法的具体用法?C++ nsACString::FindChar怎么用?C++ nsACString::FindChar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsACString
的用法示例。
在下文中一共展示了nsACString::FindChar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
static void
__ReplaceCChar (nsACString &string, const char replace, const char with)
{
PRInt32 i = string.FindChar (replace);
while (i >= 0 ) {
string.Replace (i, 1, (const char*) &with, 1);
i = string.FindChar (replace);
}
}
示例2: KeywordURIFixup
nsresult nsDefaultURIFixup::KeywordURIFixup(const nsACString & aURIString,
nsIURI** aURI)
{
// These are keyword formatted strings
// "what is mozilla"
// "what is mozilla?"
// "docshell site:mozilla.org" - has no dot/colon in the first space-separated substring
// "?mozilla" - anything that begins with a question mark
// "?site:mozilla.org docshell"
// Things that have a quote before the first dot/colon
// These are not keyword formatted strings
// "www.blah.com" - first space-separated substring contains a dot, doesn't start with "?"
// "www.blah.com stuff"
// "nonQualifiedHost:80" - first space-separated substring contains a colon, doesn't start with "?"
// "nonQualifiedHost:80 args"
// "nonQualifiedHost?"
// "nonQualifiedHost?args"
// "nonQualifiedHost?some args"
// Note: uint32_t(kNotFound) is greater than any actual location
// in practice. So if we cast all locations to uint32_t, then a <
// b guarantees that either b is kNotFound and a is found, or both
// are found and a found before b.
uint32_t dotLoc = uint32_t(aURIString.FindChar('.'));
uint32_t colonLoc = uint32_t(aURIString.FindChar(':'));
uint32_t spaceLoc = uint32_t(aURIString.FindChar(' '));
if (spaceLoc == 0) {
// Treat this as not found
spaceLoc = uint32_t(kNotFound);
}
uint32_t qMarkLoc = uint32_t(aURIString.FindChar('?'));
uint32_t quoteLoc = NS_MIN(uint32_t(aURIString.FindChar('"')),
uint32_t(aURIString.FindChar('\'')));
if (((spaceLoc < dotLoc || quoteLoc < dotLoc) &&
(spaceLoc < colonLoc || quoteLoc < colonLoc) &&
(spaceLoc < qMarkLoc || quoteLoc < qMarkLoc)) ||
qMarkLoc == 0 ||
(dotLoc == uint32_t(kNotFound) &&
colonLoc == uint32_t(kNotFound) &&
qMarkLoc == uint32_t(kNotFound) ) )
{
KeywordToURI(aURIString, aURI);
}
if(*aURI)
return NS_OK;
return NS_ERROR_FAILURE;
}
示例3:
PRBool
ParseString(const nsACString& aSource, char aDelimiter,
nsTArray<nsCString>& aArray)
{
PRInt32 start = 0;
PRInt32 end = aSource.Length();
PRUint32 oldLength = aArray.Length();
for (;;) {
PRInt32 delimiter = aSource.FindChar(aDelimiter, start);
if (delimiter < 0) {
delimiter = end;
}
if (delimiter != start) {
if (!aArray.AppendElement(Substring(aSource, start, delimiter - start))) {
aArray.RemoveElementsAt(oldLength, aArray.Length() - oldLength);
return PR_FALSE;
}
}
if (delimiter == end)
break;
start = ++delimiter;
if (start == end)
break;
}
return PR_TRUE;
}
示例4: if
NS_IMETHODIMP
nsNNTPNewsgroupList::ProcessHEADLine(const nsACString &line)
{
int32_t colon = line.FindChar(':');
nsCString header = PromiseFlatCString(line), value;
if (colon != -1)
{
value = Substring(line, colon+1);
header.SetLength((uint32_t)colon);
}
else if (line.CharAt(0) == ' ' || line.CharAt(0) == '\t') // We are continuing the header
{
m_thisLine += header; // Preserve whitespace (should we?)
return NS_OK;
}
else
{
return NS_OK; // We are malformed. Just ignore and hope for the best...
}
nsresult rv;
if (!m_lastHeader.IsEmpty())
{
rv = AddHeader(m_lastHeader.get(), m_thisLine.get());
NS_ENSURE_SUCCESS(rv,rv);
}
value.Trim(" ");
ToLowerCase(header, m_lastHeader);
m_thisLine.Assign(value);
return NS_OK;
}
示例5: if
// static
PRBool
nsDOMStorageList::ConvertDomainToArray(const nsACString& aDomain,
nsTArray<nsCString> *aArray)
{
PRInt32 length = aDomain.Length();
PRInt32 n = 0;
while (n < length) {
PRInt32 dotpos = aDomain.FindChar('.', n);
nsCAutoString domain;
if (dotpos == -1) // no more dots
domain.Assign(Substring(aDomain, n));
else if (dotpos - n == 0) // no point continuing in this case
return false;
else if (dotpos >= 0)
domain.Assign(Substring(aDomain, n, dotpos - n));
ToLowerCase(domain);
aArray->AppendElement(domain);
if (dotpos == -1)
break;
n = dotpos + 1;
}
// if n equals the length, there is a dot at the end, so treat it as invalid
return (n != length);
}
示例6:
bool
ParseString(const nsACString& aSource, char aDelimiter,
nsTArray<nsCString>& aArray)
{
int32_t start = 0;
int32_t end = aSource.Length();
uint32_t oldLength = aArray.Length();
for (;;) {
int32_t delimiter = aSource.FindChar(aDelimiter, start);
if (delimiter < 0) {
delimiter = end;
}
if (delimiter != start) {
if (!aArray.AppendElement(Substring(aSource, start, delimiter - start))) {
aArray.RemoveElementsAt(oldLength, aArray.Length() - oldLength);
return false;
}
}
if (delimiter == end)
break;
start = ++delimiter;
if (start == end)
break;
}
return true;
}
示例7: if
// Works out the screen name to put on the card for some well-known addresses
void
nsAbAddressCollector::AutoCollectScreenName(nsIAbCard *aCard,
const nsACString &aEmail)
{
if (!aCard)
return;
int32_t atPos = aEmail.FindChar('@');
if (atPos == -1)
return;
const nsACString& domain = Substring(aEmail, atPos + 1);
if (domain.IsEmpty())
return;
// username in
// [email protected] (America Online)
// [email protected] (Compuserve)
// [email protected] (Netscape webmail)
// are all AIM screennames. autocollect that info.
if (domain.Equals("aol.com") || domain.Equals("cs.com") ||
domain.Equals("netscape.net"))
aCard->SetPropertyAsAUTF8String(kScreenNameProperty, Substring(aEmail, 0, atPos));
else if (domain.Equals("gmail.com") || domain.Equals("googlemail.com"))
aCard->SetPropertyAsAUTF8String(kGtalkProperty, Substring(aEmail, 0, atPos));
}
示例8: mAlgorithmType
SRIMetadata::SRIMetadata(const nsACString& aToken)
: mAlgorithmType(SRIMetadata::UNKNOWN_ALGORITHM), mEmpty(false)
{
MOZ_ASSERT(!aToken.IsEmpty()); // callers should check this first
SRIMETADATALOG(("SRIMetadata::SRIMetadata, aToken='%s'",
PromiseFlatCString(aToken).get()));
int32_t hyphen = aToken.FindChar('-');
if (hyphen == -1) {
SRIMETADATAERROR(("SRIMetadata::SRIMetadata, invalid (no hyphen)"));
return; // invalid metadata
}
// split the token into its components
mAlgorithm = Substring(aToken, 0, hyphen);
uint32_t hashStart = hyphen + 1;
if (hashStart >= aToken.Length()) {
SRIMETADATAERROR(("SRIMetadata::SRIMetadata, invalid (missing digest)"));
return; // invalid metadata
}
int32_t question = aToken.FindChar('?');
if (question == -1) {
mHashes.AppendElement(Substring(aToken, hashStart,
aToken.Length() - hashStart));
} else {
MOZ_ASSERT(question > 0);
if (static_cast<uint32_t>(question) <= hashStart) {
SRIMETADATAERROR(("SRIMetadata::SRIMetadata, invalid (options w/o digest)"));
return; // invalid metadata
}
mHashes.AppendElement(Substring(aToken, hashStart,
question - hashStart));
}
if (mAlgorithm.EqualsLiteral("sha256")) {
mAlgorithmType = nsICryptoHash::SHA256;
} else if (mAlgorithm.EqualsLiteral("sha384")) {
mAlgorithmType = nsICryptoHash::SHA384;
} else if (mAlgorithm.EqualsLiteral("sha512")) {
mAlgorithmType = nsICryptoHash::SHA512;
}
SRIMETADATALOG(("SRIMetadata::SRIMetadata, hash='%s'; alg='%s'",
mHashes[0].get(), mAlgorithm.get()));
}
示例9: LOG
/*static*/ nsresult
nsHttpHeaderArray::ParseHeaderLine(const nsACString& line,
nsHttpAtom *hdr,
nsACString *headerName,
nsACString *val)
{
//
// BNF from section 4.2 of RFC 2616:
//
// message-header = field-name ":" [ field-value ]
// field-name = token
// field-value = *( field-content | LWS )
// field-content = <the OCTETs making up the field-value
// and consisting of either *TEXT or combinations
// of token, separators, and quoted-string>
//
// We skip over mal-formed headers in the hope that we'll still be able to
// do something useful with the response.
int32_t split = line.FindChar(':');
if (split == kNotFound) {
LOG(("malformed header [%s]: no colon\n",
PromiseFlatCString(line).get()));
return NS_ERROR_FAILURE;
}
const nsACString& sub = Substring(line, 0, split);
const nsACString& sub2 = Substring(
line, split + 1, line.Length() - split - 1);
// make sure we have a valid token for the field-name
if (!nsHttp::IsValidToken(sub)) {
LOG(("malformed header [%s]: field-name not a token\n",
PromiseFlatCString(line).get()));
return NS_ERROR_FAILURE;
}
nsHttpAtom atom = nsHttp::ResolveAtom(sub);
if (!atom) {
LOG(("failed to resolve atom [%s]\n", PromiseFlatCString(line).get()));
return NS_ERROR_FAILURE;
}
// skip over whitespace
char *p = net_FindCharNotInSet(
sub2.BeginReading(), sub2.EndReading(), HTTP_LWS);
// trim trailing whitespace - bug 86608
char *p2 = net_RFindCharNotInSet(p, sub2.EndReading(), HTTP_LWS);
// assign return values
if (hdr) *hdr = atom;
if (val) val->Assign(p, p2 - p + 1);
if (headerName) headerName->Assign(sub);
return NS_OK;
}
示例10: GetDirectory
NS_IMETHODIMP nsAbManager::GetDirectory(const nsACString &aURI,
nsIAbDirectory **aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
nsresult rv;
nsCOMPtr<nsIAbDirectory> directory;
// Was the directory root requested?
if (aURI.EqualsLiteral(kAllDirectoryRoot))
{
rv = GetRootDirectory(getter_AddRefs(directory));
NS_ENSURE_SUCCESS(rv, rv);
NS_IF_ADDREF(*aResult = directory);
return NS_OK;
}
// Do we have a copy of this directory already within our look-up table?
if (!mAbStore.Get(aURI, getter_AddRefs(directory)))
{
// The directory wasn't in our look-up table, so we need to instantiate
// it. First, extract the scheme from the URI...
nsCAutoString scheme;
PRInt32 colon = aURI.FindChar(':');
if (colon <= 0)
return NS_ERROR_MALFORMED_URI;
scheme = Substring(aURI, 0, colon);
// Construct the appropriate nsIAbDirectory...
nsCAutoString contractID;
contractID.AssignLiteral(NS_AB_DIRECTORY_TYPE_CONTRACTID_PREFIX);
contractID.Append(scheme);
directory = do_CreateInstance(contractID.get(), &rv);
NS_ENSURE_SUCCESS(rv, rv);
// Init it with the URI
rv = directory->Init(PromiseFlatCString(aURI).get());
NS_ENSURE_SUCCESS(rv, rv);
// Check if this directory was initiated with a search query. If so,
// we don't cache it.
bool isQuery = false;
rv = directory->GetIsQuery(&isQuery);
NS_ENSURE_SUCCESS(rv, rv);
if (!isQuery)
mAbStore.Put(aURI, directory);
}
NS_IF_ADDREF(*aResult = directory);
return NS_OK;
}
示例11: GetSpec
NS_IMETHODIMP
RustURL::GetSpecIgnoringRef(nsACString & aSpecIgnoringRef)
{
nsresult rv = GetSpec(aSpecIgnoringRef);
if (NS_FAILED(rv)) {
return rv;
}
int32_t pos = aSpecIgnoringRef.FindChar('#');
if (pos == kNotFound) {
return NS_OK;
}
aSpecIgnoringRef.Truncate(pos);
return NS_OK;
}
示例12: Substring
NS_IMETHODIMP
nsViewSourceHandler::NewURI(const nsACString &aSpec,
const char *aCharset,
nsIURI *aBaseURI,
nsIURI **aResult)
{
*aResult = nsnull;
// Extract inner URL and normalize to ASCII. This is done to properly
// support IDN in cases like "view-source:http://www.szalagavató.hu/"
PRInt32 colon = aSpec.FindChar(':');
if (colon == kNotFound)
return NS_ERROR_MALFORMED_URI;
nsCOMPtr<nsIURI> innerURI;
nsresult rv = NS_NewURI(getter_AddRefs(innerURI),
Substring(aSpec, colon + 1), aCharset, aBaseURI);
if (NS_FAILED(rv))
return rv;
nsCAutoString asciiSpec;
rv = innerURI->GetAsciiSpec(asciiSpec);
if (NS_FAILED(rv))
return rv;
// put back our scheme and construct a simple-uri wrapper
asciiSpec.Insert(VIEW_SOURCE ":", 0);
// We can't swap() from an nsRefPtr<nsSimpleNestedURI> to an nsIURI**,
// sadly.
nsSimpleNestedURI* ourURI = new nsSimpleNestedURI(innerURI);
nsCOMPtr<nsIURI> uri = ourURI;
if (!uri)
return NS_ERROR_OUT_OF_MEMORY;
rv = ourURI->SetSpec(asciiSpec);
if (NS_FAILED(rv))
return rv;
// Make the URI immutable so it's impossible to get it out of sync
// with its inner URI.
ourURI->SetMutable(PR_FALSE);
uri.swap(*aResult);
return rv;
}
示例13: SetRef
NS_IMETHODIMP
nsSimpleURI::SetPath(const nsACString &path)
{
NS_ENSURE_STATE(mMutable);
int32_t hashPos = path.FindChar('#');
if (hashPos < 0) {
mIsRefValid = false;
mRef.Truncate(); // invariant: mRef should be empty when it's not valid
mPath = path;
return NS_OK;
}
mPath = StringHead(path, hashPos);
return SetRef(Substring(path, uint32_t(hashPos)));
}
示例14: Substring
NS_IMETHODIMP
RustURL::SetUserPass(const nsACString & aUserPass)
{
ENSURE_MUTABLE();
int32_t colonPos = aUserPass.FindChar(':');
nsAutoCString user;
nsAutoCString pass;
if (colonPos == kNotFound) {
user = aUserPass;
} else {
user = Substring(aUserPass, 0, colonPos);
pass = Substring(aUserPass, colonPos + 1, aUserPass.Length());
}
if (rusturl_set_username(mURL.get(), &user) != 0) {
return NS_ERROR_FAILURE;
}
return static_cast<nsresult>(rusturl_set_password(mURL.get(), &pass));
}
示例15: flags
static nsMsgSearchOpValue
ConvertSearchFlagsToOperator(const nsACString &aFlags)
{
nsCString flags(aFlags);
int32_t lastTabPosition = flags.RFindChar('\t');
if ((lastTabPosition == -1) ||
((int32_t)aFlags.Length() == lastTabPosition - 1)) {
return -1;
}
switch (aFlags.CharAt(0)) {
case 'X':
return nsMsgSearchOp::DoesntContain;
case 'O':
if (aFlags.FindChar('T', lastTabPosition + 1) >= 0)
return nsMsgSearchOp::BeginsWith;
return nsMsgSearchOp::Contains;
default:
return -1;
}
}