本文整理汇总了C++中nsACString::Last方法的典型用法代码示例。如果您正苦于以下问题:C++ nsACString::Last方法的具体用法?C++ nsACString::Last怎么用?C++ nsACString::Last使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsACString
的用法示例。
在下文中一共展示了nsACString::Last方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
// Get the base domain for aHostURI; e.g. for "www.bbc.co.uk", this would be
// "bbc.co.uk". Only properly-formed URI's are tolerated, though a trailing
// dot may be present. If aHostURI is an IP address, an alias such as
// 'localhost', an eTLD such as 'co.uk', or the empty string, aBaseDomain will
// be the exact host. The result of this function should only be used in exact
// string comparisons, since substring comparisons will not be valid for the
// special cases elided above.
NS_IMETHODIMP
ThirdPartyUtil::GetBaseDomain(nsIURI* aHostURI,
nsACString& aBaseDomain)
{
// Get the base domain. this will fail if the host contains a leading dot,
// more than one trailing dot, or is otherwise malformed.
nsresult rv = mTLDService->GetBaseDomain(aHostURI, 0, aBaseDomain);
if (rv == NS_ERROR_HOST_IS_IP_ADDRESS ||
rv == NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS) {
// aHostURI is either an IP address, an alias such as 'localhost', an eTLD
// such as 'co.uk', or the empty string. Uses the normalized host in such
// cases.
rv = aHostURI->GetAsciiHost(aBaseDomain);
}
NS_ENSURE_SUCCESS(rv, rv);
// aHostURI (and thus aBaseDomain) may be the string '.'. If so, fail.
if (aBaseDomain.Length() == 1 && aBaseDomain.Last() == '.')
return NS_ERROR_INVALID_ARG;
// Reject any URIs without a host that aren't file:// URIs. This makes it the
// only way we can get a base domain consisting of the empty string, which
// means we can safely perform foreign tests on such URIs where "not foreign"
// means "the involved URIs are all file://".
if (aBaseDomain.IsEmpty()) {
bool isFileURI = false;
aHostURI->SchemeIs("file", &isFileURI);
NS_ENSURE_TRUE(isFileURI, NS_ERROR_INVALID_ARG);
}
return NS_OK;
}
示例2: InternalAddEntryDirectory
nsresult nsZipWriter::InternalAddEntryDirectory(const nsACString & aZipEntry,
PRTime aModTime,
uint32_t aPermissions)
{
nsRefPtr<nsZipHeader> header = new nsZipHeader();
NS_ENSURE_TRUE(header, NS_ERROR_OUT_OF_MEMORY);
uint32_t zipAttributes = ZIP_ATTRS(aPermissions, ZIP_ATTRS_DIRECTORY);
if (aZipEntry.Last() != '/') {
nsCString dirPath;
dirPath.Assign(aZipEntry + NS_LITERAL_CSTRING("/"));
header->Init(dirPath, aModTime, zipAttributes, mCDSOffset);
}
else
header->Init(aZipEntry, aModTime, zipAttributes, mCDSOffset);
if (mEntryHash.Get(header->mName, nullptr))
return NS_ERROR_FILE_ALREADY_EXISTS;
nsresult rv = header->WriteFileHeader(mStream);
if (NS_FAILED(rv)) {
Cleanup();
return rv;
}
mCDSDirty = true;
mCDSOffset += header->GetFileHeaderLength();
mEntryHash.Put(header->mName, mHeaders.Count());
if (!mHeaders.AppendObject(header)) {
Cleanup();
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
示例3: ConvertFileToStringURI
nsresult nsDefaultURIFixup::ConvertFileToStringURI(const nsACString& aIn,
nsCString& aOut)
{
bool attemptFixup = false;
#if defined(XP_WIN)
// Check for \ in the url-string or just a drive (PC)
if(kNotFound != aIn.FindChar('\\') ||
(aIn.Length() == 2 && (aIn.Last() == ':' || aIn.Last() == '|')))
{
attemptFixup = true;
}
#elif defined(XP_UNIX)
// Check if it starts with / (UNIX)
if(aIn.First() == '/')
{
attemptFixup = true;
}
#else
// Do nothing (All others for now)
#endif
if (attemptFixup)
{
// Test if this is a valid path by trying to create a local file
// object. The URL of that is returned if successful.
// NOTE: Please be sure to check that the call to NS_NewLocalFile
// rejects bad file paths when using this code on a new
// platform.
nsCOMPtr<nsIFile> filePath;
nsresult rv;
// this is not the real fix but a temporary fix
// in order to really fix the problem, we need to change the
// nsICmdLineService interface to use wstring to pass paramenters
// instead of string since path name and other argument could be
// in non ascii.(see bug 87127) Since it is too risky to make interface change right
// now, we decide not to do so now.
// Therefore, the aIn we receive here maybe already in damage form
// (e.g. treat every bytes as ISO-8859-1 and cast up to char16_t
// while the real data could be in file system charset )
// we choice the following logic which will work for most of the case.
// Case will still failed only if it meet ALL the following condiction:
// 1. running on CJK, Russian, or Greek system, and
// 2. user type it from URL bar
// 3. the file name contains character in the range of
// U+00A1-U+00FF but encode as different code point in file
// system charset (e.g. ACP on window)- this is very rare case
// We should remove this logic and convert to File system charset here
// once we change nsICmdLineService to use wstring and ensure
// all the Unicode data come in is correctly converted.
// XXXbz nsICmdLineService doesn't hand back unicode, so in some cases
// what we have is actually a "utf8" version of a "utf16" string that's
// actually byte-expanded native-encoding data. Someone upstream needs
// to stop using AssignWithConversion and do things correctly. See bug
// 58866 for what happens if we remove this
// PossiblyByteExpandedFileName check.
NS_ConvertUTF8toUTF16 in(aIn);
if (PossiblyByteExpandedFileName(in)) {
// removes high byte
rv = NS_NewNativeLocalFile(NS_LossyConvertUTF16toASCII(in), false, getter_AddRefs(filePath));
}
else {
// input is unicode
rv = NS_NewLocalFile(in, false, getter_AddRefs(filePath));
}
if (NS_SUCCEEDED(rv))
{
NS_GetURLSpecFromFile(filePath, aOut);
return NS_OK;
}
}
return NS_ERROR_FAILURE;
}