本文整理汇总了C++中nsAString::First方法的典型用法代码示例。如果您正苦于以下问题:C++ nsAString::First方法的具体用法?C++ nsAString::First怎么用?C++ nsAString::First使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsAString
的用法示例。
在下文中一共展示了nsAString::First方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: uri
nsresult
nsXULContentUtils::GetResource(int32_t aNameSpaceID, const nsAString& aAttribute, nsIRDFResource** aResult)
{
// construct a fully-qualified URI from the namespace/tag pair.
// XXX should we allow nodes with no namespace???
//NS_PRECONDITION(aNameSpaceID != kNameSpaceID_Unknown, "no namespace");
//if (aNameSpaceID == kNameSpaceID_Unknown)
// return NS_ERROR_UNEXPECTED;
nsresult rv;
char16_t buf[256];
nsFixedString uri(buf, ArrayLength(buf), 0);
if (aNameSpaceID != kNameSpaceID_Unknown && aNameSpaceID != kNameSpaceID_None) {
rv = nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNameSpaceID, uri);
// XXX ignore failure; treat as "no namespace"
}
// XXX check to see if we need to insert a '/' or a '#'. Oy.
if (!uri.IsEmpty() && uri.Last() != '#' && uri.Last() != '/' && aAttribute.First() != '#')
uri.Append(char16_t('#'));
uri.Append(aAttribute);
rv = gRDF->GetUnicodeResource(uri, aResult);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
示例2: StringEndsWith
bool
nsMsgLocalStoreUtils::nsShouldIgnoreFile(nsAString& name)
{
PRUnichar firstChar = name.First();
if (firstChar == '.' || firstChar == '#' ||
name.CharAt(name.Length() - 1) == '~')
return true;
if (name.LowerCaseEqualsLiteral("msgfilterrules.dat") ||
name.LowerCaseEqualsLiteral("rules.dat") ||
name.LowerCaseEqualsLiteral("filterlog.html") ||
name.LowerCaseEqualsLiteral("junklog.html") ||
name.LowerCaseEqualsLiteral("rulesbackup.dat"))
return true;
// don't add summary files to the list of folders;
// don't add popstate files to the list either, or rules (sort.dat).
if (StringEndsWith(name, NS_LITERAL_STRING(".snm")) ||
name.LowerCaseEqualsLiteral("popstate.dat") ||
name.LowerCaseEqualsLiteral("sort.dat") ||
name.LowerCaseEqualsLiteral("mailfilt.log") ||
name.LowerCaseEqualsLiteral("filters.js") ||
StringEndsWith(name, NS_LITERAL_STRING(".toc")))
return true;
// ignore RSS data source files
if (name.LowerCaseEqualsLiteral("feeds.rdf") ||
name.LowerCaseEqualsLiteral("feeditems.rdf"))
return true;
// The .mozmsgs dir is for spotlight support
return (StringEndsWith(name, NS_LITERAL_STRING(".mozmsgs")) ||
StringEndsWith(name, NS_LITERAL_STRING(".sbd")) ||
StringEndsWith(name, NS_LITERAL_STRING(SUMMARY_SUFFIX)));
}
示例3: HostIsAllowed
bool HostIsAllowed(nsAString& host)
{
if (host.First() == '*') {
if (host.EqualsLiteral("*") || host[1] != '.') {
return false;
}
host.Cut(0, 2);
nsCOMPtr<nsIEffectiveTLDService> tldService =
do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID);
if (!tldService) {
return false;
}
NS_ConvertUTF16toUTF8 cHost(host);
nsAutoCString publicSuffix;
nsresult rv = tldService->GetPublicSuffixFromHost(cHost, publicSuffix);
return NS_SUCCEEDED(rv) && !cHost.Equals(publicSuffix);
}
return true;
};
示例4: tokenizer
/* static */ bool
FileSystemUtils::IsValidRelativeDOMPath(const nsAString& aPath,
nsTArray<nsString>& aParts)
{
// We don't allow empty relative path to access the root.
if (aPath.IsEmpty()) {
return false;
}
// Leading and trailing "/" are not allowed.
if (aPath.First() == FILESYSTEM_DOM_PATH_SEPARATOR_CHAR ||
aPath.Last() == FILESYSTEM_DOM_PATH_SEPARATOR_CHAR) {
return false;
}
NS_NAMED_LITERAL_STRING(kCurrentDir, ".");
NS_NAMED_LITERAL_STRING(kParentDir, "..");
// Split path and check each path component.
nsCharSeparatedTokenizerTemplate<TokenizerIgnoreNothing>
tokenizer(aPath, FILESYSTEM_DOM_PATH_SEPARATOR_CHAR);
while (tokenizer.hasMoreTokens()) {
nsDependentSubstring pathComponent = tokenizer.nextToken();
// The path containing empty components, such as "foo//bar", is invalid.
// We don't allow paths, such as "../foo", "foo/./bar" and "foo/../bar",
// to walk up the directory.
if (pathComponent.IsEmpty() ||
pathComponent.Equals(kCurrentDir) ||
pathComponent.Equals(kParentDir)) {
return false;
}
aParts.AppendElement(pathComponent);
}
return true;
}
示例5: uri
NS_IMETHODIMP
nsHTMLURIRefObject::GetNextURI(nsAString & aURI)
{
NS_ENSURE_TRUE(mNode, NS_ERROR_NOT_INITIALIZED);
nsAutoString tagName;
nsresult rv = mNode->GetNodeName(tagName);
NS_ENSURE_SUCCESS(rv, rv);
// Loop over attribute list:
if (!mAttributes)
{
nsCOMPtr<nsIDOMElement> element (do_QueryInterface(mNode));
NS_ENSURE_TRUE(element, NS_ERROR_INVALID_ARG);
mCurAttrIndex = 0;
element->GetAttributes(getter_AddRefs(mAttributes));
NS_ENSURE_TRUE(mAttributes, NS_ERROR_NOT_INITIALIZED);
rv = mAttributes->GetLength(&mAttributeCnt);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(mAttributeCnt, NS_ERROR_FAILURE);
mCurAttrIndex = 0;
}
while (mCurAttrIndex < mAttributeCnt)
{
nsCOMPtr<nsIDOMAttr> attrNode;
rv = mAttributes->Item(mCurAttrIndex++, getter_AddRefs(attrNode));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_ARG_POINTER(attrNode);
nsString curAttr;
rv = attrNode->GetName(curAttr);
NS_ENSURE_SUCCESS(rv, rv);
// href >> A, AREA, BASE, LINK
if (MATCHES(curAttr, "href"))
{
if (!MATCHES(tagName, "a") && !MATCHES(tagName, "area")
&& !MATCHES(tagName, "base") && !MATCHES(tagName, "link"))
continue;
rv = attrNode->GetValue(aURI);
NS_ENSURE_SUCCESS(rv, rv);
nsString uri (aURI);
// href pointing to a named anchor doesn't count
if (aURI.First() != char16_t('#'))
return NS_OK;
aURI.Truncate();
return NS_ERROR_INVALID_ARG;
}
// src >> FRAME, IFRAME, IMG, INPUT, SCRIPT
else if (MATCHES(curAttr, "src"))
{
if (!MATCHES(tagName, "img")
&& !MATCHES(tagName, "frame") && !MATCHES(tagName, "iframe")
&& !MATCHES(tagName, "input") && !MATCHES(tagName, "script"))
continue;
return attrNode->GetValue(aURI);
}
//<META http-equiv="refresh" content="3,http://www.acme.com/intro.html">
else if (MATCHES(curAttr, "content"))
{
if (!MATCHES(tagName, "meta"))
continue;
}
// longdesc >> FRAME, IFRAME, IMG
else if (MATCHES(curAttr, "longdesc"))
{
if (!MATCHES(tagName, "img")
&& !MATCHES(tagName, "frame") && !MATCHES(tagName, "iframe"))
continue;
}
// usemap >> IMG, INPUT, OBJECT
else if (MATCHES(curAttr, "usemap"))
{
if (!MATCHES(tagName, "img")
&& !MATCHES(tagName, "input") && !MATCHES(tagName, "object"))
continue;
}
// action >> FORM
else if (MATCHES(curAttr, "action"))
{
if (!MATCHES(tagName, "form"))
continue;
}
// background >> BODY
else if (MATCHES(curAttr, "background"))
{
if (!MATCHES(tagName, "body"))
continue;
}
// codebase >> OBJECT, APPLET
else if (MATCHES(curAttr, "codebase"))
{
if (!MATCHES(tagName, "meta"))
continue;
}
// classid >> OBJECT
else if (MATCHES(curAttr, "classid"))
{
//.........这里部分代码省略.........
示例6: defined
NS_IMETHODIMP
nsCommandLine::ResolveFile(const nsAString& aArgument, nsIFile* *aResult)
{
NS_ENSURE_TRUE(mWorkingDir, NS_ERROR_NOT_INITIALIZED);
// This is some seriously screwed-up code. nsIFile.appendRelativeNativePath
// explicitly does not accept .. or . path parts, but that is exactly what we
// need here. So we hack around it.
nsresult rv;
#if defined(MOZ_WIDGET_COCOA)
nsCOMPtr<nsILocalFileMac> lfm (do_QueryInterface(mWorkingDir));
NS_ENSURE_TRUE(lfm, NS_ERROR_NO_INTERFACE);
nsCOMPtr<nsILocalFileMac> newfile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
NS_ENSURE_TRUE(newfile, NS_ERROR_OUT_OF_MEMORY);
CFURLRef baseurl;
rv = lfm->GetCFURL(&baseurl);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString path;
NS_CopyUnicodeToNative(aArgument, path);
CFURLRef newurl =
CFURLCreateFromFileSystemRepresentationRelativeToBase(nullptr, (const UInt8*) path.get(),
path.Length(),
true, baseurl);
CFRelease(baseurl);
rv = newfile->InitWithCFURL(newurl);
CFRelease(newurl);
if (NS_FAILED(rv)) return rv;
newfile.forget(aResult);
return NS_OK;
#elif defined(XP_UNIX)
nsCOMPtr<nsIFile> lf (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
NS_ENSURE_TRUE(lf, NS_ERROR_OUT_OF_MEMORY);
if (aArgument.First() == '/') {
// absolute path
rv = lf->InitWithPath(aArgument);
if (NS_FAILED(rv)) return rv;
NS_ADDREF(*aResult = lf);
return NS_OK;
}
nsAutoCString nativeArg;
NS_CopyUnicodeToNative(aArgument, nativeArg);
nsAutoCString newpath;
mWorkingDir->GetNativePath(newpath);
newpath.Append('/');
newpath.Append(nativeArg);
rv = lf->InitWithNativePath(newpath);
if (NS_FAILED(rv)) return rv;
rv = lf->Normalize();
if (NS_FAILED(rv)) return rv;
lf.forget(aResult);
return NS_OK;
#elif defined(XP_WIN32)
nsCOMPtr<nsIFile> lf (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
NS_ENSURE_TRUE(lf, NS_ERROR_OUT_OF_MEMORY);
rv = lf->InitWithPath(aArgument);
if (NS_FAILED(rv)) {
// If it's a relative path, the Init is *going* to fail. We use string magic and
// win32 _fullpath. Note that paths of the form "\Relative\To\CurDrive" are
// going to fail, and I haven't figured out a way to work around this without
// the PathCombine() function, which is not available in plain win95/nt4
nsAutoString fullPath;
mWorkingDir->GetPath(fullPath);
fullPath.Append('\\');
fullPath.Append(aArgument);
WCHAR pathBuf[MAX_PATH];
if (!_wfullpath(pathBuf, fullPath.get(), MAX_PATH))
return NS_ERROR_FAILURE;
rv = lf->InitWithPath(nsDependentString(pathBuf));
if (NS_FAILED(rv)) return rv;
}
lf.forget(aResult);
return NS_OK;
#else
#error Need platform-specific logic here.
#endif
//.........这里部分代码省略.........
示例7: uri
NS_IMETHODIMP
nsHTMLURIRefObject::GetNextURI(nsAString & aURI)
{
if (!mNode)
return NS_ERROR_NOT_INITIALIZED;
nsAutoString tagName;
nsresult rv = mNode->GetNodeName(tagName);
if (NS_FAILED(rv))
return rv;
// Loop over attribute list:
if (!mAttributes)
{
nsCOMPtr<nsIDOMElement> element (do_QueryInterface(mNode));
if (!element)
return NS_ERROR_INVALID_ARG;
mCurAttrIndex = 0;
mNode->GetAttributes(getter_AddRefs(mAttributes));
if (!mAttributes)
return NS_ERROR_NOT_INITIALIZED;
rv = mAttributes->GetLength(&mAttributeCnt);
NS_ENSURE_SUCCESS(rv, rv);
if (!mAttributeCnt) return NS_ERROR_FAILURE;
mCurAttrIndex = 0;
}
#ifdef DEBUG_akkana
printf("Looking at tag '%s'\n",
NS_LossyConvertUCS2toASCII(tagName).get());
#endif
while (mCurAttrIndex < mAttributeCnt)
{
nsCOMPtr<nsIDOMNode> attrNode;
rv = mAttributes->Item(mCurAttrIndex++, getter_AddRefs(attrNode));
// XXX Does Item() addref, or not?
// The comparable code in nsEditor assumes it doesn't.
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_ARG_POINTER(attrNode);
nsCOMPtr<nsIDOMAttr> curAttrNode (do_QueryInterface(attrNode));
NS_ENSURE_ARG_POINTER(curAttrNode);
nsString curAttr;
rv = curAttrNode->GetName(curAttr);
NS_ENSURE_SUCCESS(rv, rv);
// href >> A, AREA, BASE, LINK
#ifdef DEBUG_akkana
printf("Trying to match attribute '%s'\n",
NS_LossyConvertUCS2toASCII(curAttr).get());
#endif
if (MATCHES(curAttr, "href"))
{
if (!MATCHES(tagName, "a") && !MATCHES(tagName, "area")
&& !MATCHES(tagName, "base") && !MATCHES(tagName, "link"))
continue;
rv = curAttrNode->GetValue(aURI);
NS_ENSURE_SUCCESS(rv, rv);
nsString uri (aURI);
// href pointing to a named anchor doesn't count
if (aURI.First() != PRUnichar('#'))
return NS_OK;
aURI.Truncate();
return NS_ERROR_INVALID_ARG;
}
// src >> FRAME, IFRAME, IMG, INPUT, SCRIPT
else if (MATCHES(curAttr, "src"))
{
if (!MATCHES(tagName, "img")
&& !MATCHES(tagName, "frame") && !MATCHES(tagName, "iframe")
&& !MATCHES(tagName, "input") && !MATCHES(tagName, "script"))
continue;
return curAttrNode->GetValue(aURI);
}
//<META http-equiv="refresh" content="3,http://www.acme.com/intro.html">
else if (MATCHES(curAttr, "content"))
{
if (!MATCHES(tagName, "meta"))
continue;
}
// longdesc >> FRAME, IFRAME, IMG
else if (MATCHES(curAttr, "longdesc"))
{
if (!MATCHES(tagName, "img")
&& !MATCHES(tagName, "frame") && !MATCHES(tagName, "iframe"))
continue;
}
// usemap >> IMG, INPUT, OBJECT
else if (MATCHES(curAttr, "usemap"))
{
if (!MATCHES(tagName, "img")
&& !MATCHES(tagName, "input") && !MATCHES(tagName, "object"))
continue;
}
// action >> FORM
else if (MATCHES(curAttr, "action"))
{
if (!MATCHES(tagName, "form"))
continue;
}
//.........这里部分代码省略.........