本文整理汇总了C++中NS_UnescapeURL函数的典型用法代码示例。如果您正苦于以下问题:C++ NS_UnescapeURL函数的具体用法?C++ NS_UnescapeURL怎么用?C++ NS_UnescapeURL使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NS_UnescapeURL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tokenizer
void nsMediaFragmentURIParser::Parse(nsACString& aRef)
{
// Create an array of possibly-invalid media fragments.
nsTArray< std::pair<nsCString, nsCString> > fragments;
nsCCharSeparatedTokenizer tokenizer(aRef, '&');
while (tokenizer.hasMoreTokens()) {
const nsCSubstring& nv = tokenizer.nextToken();
int32_t index = nv.FindChar('=');
if (index >= 0) {
nsAutoCString name;
nsAutoCString value;
NS_UnescapeURL(StringHead(nv, index), esc_Ref | esc_AlwaysCopy, name);
NS_UnescapeURL(Substring(nv, index + 1, nv.Length()),
esc_Ref | esc_AlwaysCopy, value);
fragments.AppendElement(make_pair(name, value));
}
}
// Parse the media fragment values.
bool gotTemporal = false, gotSpatial = false;
for (int i = fragments.Length() - 1 ; i >= 0 ; --i) {
if (gotTemporal && gotSpatial) {
// We've got one of each possible type. No need to look at the rest.
break;
} else if (!gotTemporal && fragments[i].first.EqualsLiteral("t")) {
nsAutoString value = NS_ConvertUTF8toUTF16(fragments[i].second);
gotTemporal = ParseNPT(nsDependentSubstring(value, 0));
} else if (!gotSpatial && fragments[i].first.EqualsLiteral("xywh")) {
nsAutoString value = NS_ConvertUTF8toUTF16(fragments[i].second);
gotSpatial = ParseXYWH(nsDependentSubstring(value, 0));
}
}
}
示例2: LOG
void
nsHttpChannelAuthProvider::GetIdentityFromURI(uint32_t authFlags,
nsHttpAuthIdentity &ident)
{
LOG(("nsHttpChannelAuthProvider::GetIdentityFromURI [this=%p channel=%p]\n",
this, mAuthChannel));
nsAutoString userBuf;
nsAutoString passBuf;
// XXX i18n
nsCAutoString buf;
mURI->GetUsername(buf);
if (!buf.IsEmpty()) {
NS_UnescapeURL(buf);
CopyASCIItoUTF16(buf, userBuf);
mURI->GetPassword(buf);
if (!buf.IsEmpty()) {
NS_UnescapeURL(buf);
CopyASCIItoUTF16(buf, passBuf);
}
}
if (!userBuf.IsEmpty()) {
SetIdent(ident, authFlags, (PRUnichar *) userBuf.get(),
(PRUnichar *) passBuf.get());
}
}
示例3: spec
NS_IMETHODIMP
nsFtpProtocolHandler::NewURI(const nsACString &aSpec,
const char *aCharset,
nsIURI *aBaseURI,
nsIURI **result)
{
nsCAutoString spec(aSpec);
char *fwdPtr = spec.BeginWriting();
// now unescape it... %xx reduced inline to resulting character
PRInt32 len = NS_UnescapeURL(fwdPtr);
// NS_UnescapeURL() modified spec's buffer, truncate to ensure
// spec knows its new length.
spec.Truncate(len);
// return an error if we find a NUL, CR, or LF in the path
if (spec.FindCharInSet(CRLF) >= 0 || spec.FindChar('\0') >= 0)
return NS_ERROR_MALFORMED_URI;
nsresult rv;
nsCOMPtr<nsIStandardURL> url = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
rv = url->Init(nsIStandardURL::URLTYPE_AUTHORITY, 21, aSpec, aCharset, aBaseURI);
if (NS_FAILED(rv)) return rv;
return CallQueryInterface(url, result);
}
示例4: NS_UnescapeURL
NS_IMETHODIMP
nsUTF8ConverterService::ConvertURISpecToUTF8(const nsACString &aSpec,
const char *aCharset,
nsACString &aUTF8Spec)
{
// assume UTF-8 if the spec contains unescaped non-ASCII characters.
// No valid spec in Mozilla would break this assumption.
if (!IsASCII(aSpec)) {
aUTF8Spec = aSpec;
return NS_OK;
}
aUTF8Spec.Truncate();
nsAutoCString unescapedSpec;
// NS_UnescapeURL does not fill up unescapedSpec unless there's at least
// one character to unescape.
bool written = NS_UnescapeURL(PromiseFlatCString(aSpec).get(), aSpec.Length(),
esc_OnlyNonASCII, unescapedSpec);
if (!written) {
aUTF8Spec = aSpec;
return NS_OK;
}
// return if ASCII only or escaped UTF-8
if (IsASCII(unescapedSpec) || IsUTF8(unescapedSpec)) {
aUTF8Spec = unescapedSpec;
return NS_OK;
}
return ToUTF8(unescapedSpec, aCharset, true, aUTF8Spec);
}
示例5: PromiseFlatCString
nsresult
nsUrlClassifierUtils::CanonicalizeHostname(const nsACString & hostname,
nsACString & _retval)
{
nsAutoCString unescaped;
if (!NS_UnescapeURL(PromiseFlatCString(hostname).get(),
PromiseFlatCString(hostname).Length(),
0, unescaped)) {
unescaped.Assign(hostname);
}
nsAutoCString cleaned;
CleanupHostname(unescaped, cleaned);
nsAutoCString temp;
ParseIPAddress(cleaned, temp);
if (!temp.IsEmpty()) {
cleaned.Assign(temp);
}
ToLowerCase(cleaned);
SpecialEncode(cleaned, false, _retval);
return NS_OK;
}
示例6: GetSubstitution
nsresult
SubstitutingProtocolHandler::ResolveURI(nsIURI *uri, nsACString &result)
{
nsresult rv;
nsAutoCString host;
nsAutoCString path;
rv = uri->GetAsciiHost(host);
if (NS_FAILED(rv)) return rv;
rv = uri->GetPath(path);
if (NS_FAILED(rv)) return rv;
if (ResolveSpecialCases(host, path, result)) {
return NS_OK;
}
nsCOMPtr<nsIURI> baseURI;
rv = GetSubstitution(host, getter_AddRefs(baseURI));
if (NS_FAILED(rv)) return rv;
// Unescape the path so we can perform some checks on it.
nsCOMPtr<nsIURL> url = do_QueryInterface(uri);
if (!url) {
return NS_ERROR_MALFORMED_URI;
}
nsAutoCString unescapedPath;
rv = url->GetFilePath(unescapedPath);
if (NS_FAILED(rv)) return rv;
NS_UnescapeURL(unescapedPath);
if (unescapedPath.FindChar('\\') != -1) {
return NS_ERROR_MALFORMED_URI;
}
// Some code relies on an empty path resolving to a file rather than a
// directory.
NS_ASSERTION(path.CharAt(0) == '/', "Path must begin with '/'");
if (path.Length() == 1) {
rv = baseURI->GetSpec(result);
} else {
// Make sure we always resolve the path as file-relative to our target URI.
path.InsertLiteral(".", 0);
rv = baseURI->Resolve(path, result);
}
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (MOZ_LOG_TEST(gResLog, LogLevel::Debug)) {
nsAutoCString spec;
uri->GetAsciiSpec(spec);
MOZ_LOG(gResLog, LogLevel::Debug, ("%s\n -> %s\n", spec.get(), PromiseFlatCString(result).get()));
}
return rv;
}
示例7: TestUnescapeHelper
void TestUnescapeHelper(const char* in, const char* expected)
{
nsCString out, strIn(in), strExp(expected);
nsUrlClassifierUtils utils;
NS_UnescapeURL(strIn.get(), strIn.Length(), esc_AlwaysCopy, out);
CheckEquals(strExp, out);
}
示例8: GetURI
NS_IMETHODIMP
Location::GetHash(nsAString& aHash)
{
aHash.SetLength(0);
nsCOMPtr<nsIURI> uri;
nsresult rv = GetURI(getter_AddRefs(uri));
if (NS_FAILED(rv) || !uri) {
return rv;
}
nsAutoCString ref;
nsAutoString unicodeRef;
rv = uri->GetRef(ref);
if (nsContentUtils::GettersDecodeURLHash()) {
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsITextToSubURI> textToSubURI(
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv)) {
nsAutoCString charset;
uri->GetOriginCharset(charset);
rv = textToSubURI->UnEscapeURIForUI(charset, ref, unicodeRef);
}
if (NS_FAILED(rv)) {
// Oh, well. No intl here!
NS_UnescapeURL(ref);
CopyASCIItoUTF16(ref, unicodeRef);
rv = NS_OK;
}
}
if (NS_SUCCEEDED(rv) && !unicodeRef.IsEmpty()) {
aHash.Assign(char16_t('#'));
aHash.Append(unicodeRef);
}
} else { // URL Hash should simply return the value of the Ref segment
if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) {
aHash.Assign(char16_t('#'));
AppendUTF8toUTF16(ref, aHash);
}
}
if (aHash == mCachedHash) {
// Work around ShareThis stupidly polling location.hash every
// 5ms all the time by handing out the same exact string buffer
// we handed out last time.
aHash = mCachedHash;
} else {
mCachedHash = aHash;
}
return rv;
}
示例9: NS_UnescapeURL
NS_IMETHODIMP
nsIOService::UnescapeString(const nsACString &aStr,
uint32_t aFlags, nsACString &aResult)
{
aResult.Truncate();
NS_UnescapeURL(aStr.BeginReading(), aStr.Length(),
aFlags | esc_AlwaysCopy, aResult);
return NS_OK;
}
示例10: tokenizer
void nsMediaFragmentURIParser::Parse()
{
nsCCharSeparatedTokenizer tokenizer(mHash, '&');
while (tokenizer.hasMoreTokens()) {
const nsCSubstring& nv = tokenizer.nextToken();
PRInt32 index = nv.FindChar('=');
if (index >= 0) {
nsCAutoString name;
nsCAutoString value;
NS_UnescapeURL(StringHead(nv, index), esc_Ref | esc_AlwaysCopy, name);
NS_UnescapeURL(Substring(nv, index + 1, nv.Length()),
esc_Ref | esc_AlwaysCopy, value);
nsAutoString a = NS_ConvertUTF8toUTF16(name);
nsAutoString b = NS_ConvertUTF8toUTF16(value);
mFragments.AppendElement(Pair(a, b));
}
}
}
示例11: TestUnescape
// Make sure Unescape from nsEncode.h's unescape does what the server does.
void TestUnescape()
{
// test empty string
TestUnescapeHelper("\0", "\0");
// Test docoding of all characters.
nsCString allCharsEncoded, allCharsEncodedLowercase, allCharsAsString;
for (PRInt32 i = 1; i < 256; ++i) {
allCharsEncoded.Append('%');
allCharsEncoded.Append(int_to_hex_digit(i / 16));
allCharsEncoded.Append((int_to_hex_digit(i % 16)));
allCharsEncodedLowercase.Append('%');
allCharsEncodedLowercase.Append(tolower(int_to_hex_digit(i / 16)));
allCharsEncodedLowercase.Append(tolower(int_to_hex_digit(i % 16)));
allCharsAsString.Append(static_cast<char>(i));
}
nsUrlClassifierUtils utils;
nsCString out;
NS_UnescapeURL(allCharsEncoded.get(), allCharsEncoded.Length(), esc_AlwaysCopy, out);
CheckEquals(allCharsAsString, out);
out.Truncate();
NS_UnescapeURL(allCharsEncodedLowercase.get(), allCharsEncodedLowercase.Length(), esc_AlwaysCopy, out);
CheckEquals(allCharsAsString, out);
// Test %-related edge cases
TestUnescapeHelper("%", "%");
TestUnescapeHelper("%xx", "%xx");
TestUnescapeHelper("%%", "%%");
TestUnescapeHelper("%%%", "%%%");
TestUnescapeHelper("%%%%", "%%%%");
TestUnescapeHelper("%1", "%1");
TestUnescapeHelper("%1z", "%1z");
TestUnescapeHelper("a%1z", "a%1z");
TestUnescapeHelper("abc%d%e%fg%hij%klmno%", "abc%d%e%fg%hij%klmno%");
// A few more tests
TestUnescapeHelper("%25", "%");
TestUnescapeHelper("%25%32%35", "%25");
}
示例12: GetURI
NS_IMETHODIMP
nsLocation::GetHash(nsAString& aHash)
{
if (!CallerSubsumes())
return NS_ERROR_DOM_SECURITY_ERR;
aHash.SetLength(0);
nsCOMPtr<nsIURI> uri;
nsresult rv = GetURI(getter_AddRefs(uri));
if (NS_FAILED(rv) || !uri) {
return rv;
}
nsCAutoString ref;
nsAutoString unicodeRef;
rv = uri->GetRef(ref);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsITextToSubURI> textToSubURI(
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv)) {
nsCAutoString charset;
uri->GetOriginCharset(charset);
rv = textToSubURI->UnEscapeURIForUI(charset, ref, unicodeRef);
}
if (NS_FAILED(rv)) {
// Oh, well. No intl here!
NS_UnescapeURL(ref);
CopyASCIItoUTF16(ref, unicodeRef);
rv = NS_OK;
}
}
if (NS_SUCCEEDED(rv) && !unicodeRef.IsEmpty()) {
aHash.Assign(PRUnichar('#'));
aHash.Append(unicodeRef);
}
if (aHash == mCachedHash) {
// Work around ShareThis stupidly polling location.hash every
// 5ms all the time by handing out the same exact string buffer
// we handed out last time.
aHash = mCachedHash;
} else {
mCachedHash = aHash;
}
return rv;
}
示例13: net_GetFileFromURLSpec
nsresult
net_GetFileFromURLSpec(const nsACString &aURL, nsIFile **result)
{
// NOTE: See also the implementation in nsURLHelperOSX.cpp,
// which is based on this.
nsresult rv;
nsCOMPtr<nsILocalFile> localFile;
rv = NS_NewNativeLocalFile(EmptyCString(), PR_TRUE, getter_AddRefs(localFile));
if (NS_FAILED(rv))
return rv;
nsCAutoString directory, fileBaseName, fileExtension, path;
rv = net_ParseFileURL(aURL, directory, fileBaseName, fileExtension);
if (NS_FAILED(rv)) return rv;
if (!directory.IsEmpty())
NS_EscapeURL(directory, esc_Directory|esc_AlwaysCopy, path);
if (!fileBaseName.IsEmpty())
NS_EscapeURL(fileBaseName, esc_FileBaseName|esc_AlwaysCopy, path);
if (!fileExtension.IsEmpty()) {
path += '.';
NS_EscapeURL(fileExtension, esc_FileExtension|esc_AlwaysCopy, path);
}
NS_UnescapeURL(path);
if (path.Length() != strlen(path.get()))
return NS_ERROR_FILE_INVALID_PATH;
if (IsUTF8(path)) {
// speed up the start-up where UTF-8 is the native charset
// (e.g. on recent Linux distributions)
if (NS_IsNativeUTF8())
rv = localFile->InitWithNativePath(path);
else
rv = localFile->InitWithPath(NS_ConvertUTF8toUTF16(path));
// XXX In rare cases, a valid UTF-8 string can be valid as a native
// encoding (e.g. 0xC5 0x83 is valid both as UTF-8 and Windows-125x).
// However, the chance is very low that a meaningful word in a legacy
// encoding is valid as UTF-8.
}
else
// if path is not in UTF-8, assume it is encoded in the native charset
rv = localFile->InitWithNativePath(path);
if (NS_FAILED(rv)) return rv;
NS_ADDREF(*result = localFile);
return NS_OK;
}
示例14: NS_UnescapeURL
void
URL::GetHash(nsString& aHash) const
{
aHash.Truncate();
nsAutoCString ref;
nsresult rv = mURI->GetRef(ref);
if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) {
NS_UnescapeURL(ref); // XXX may result in random non-ASCII bytes!
aHash.Assign(PRUnichar('#'));
AppendUTF8toUTF16(ref, aHash);
}
}
示例15: url
NS_IMETHODIMP
nsResProtocolHandler::ResolveURI(nsIURI *uri, nsACString &result)
{
nsresult rv;
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
if (!url)
return NS_NOINTERFACE;
nsCAutoString host;
nsCAutoString path;
rv = uri->GetAsciiHost(host);
if (NS_FAILED(rv)) return rv;
rv = uri->GetPath(path);
if (NS_FAILED(rv)) return rv;
nsCAutoString filepath;
url->GetFilePath(filepath);
// Don't misinterpret the filepath as an absolute URI.
if (filepath.FindChar(':') != -1)
return NS_ERROR_MALFORMED_URI;
NS_UnescapeURL(filepath);
if (filepath.FindChar('\\') != -1)
return NS_ERROR_MALFORMED_URI;
const char *p = path.get() + 1; // path always starts with a slash
NS_ASSERTION(*(p-1) == '/', "Path did not begin with a slash!");
if (*p == '/')
return NS_ERROR_MALFORMED_URI;
nsCOMPtr<nsIURI> baseURI;
rv = GetSubstitution(host, getter_AddRefs(baseURI));
if (NS_FAILED(rv)) return rv;
rv = baseURI->Resolve(nsDependentCString(p, path.Length()-1), result);
#if defined(PR_LOGGING)
if (PR_LOG_TEST(gResLog, PR_LOG_DEBUG)) {
nsCAutoString spec;
uri->GetAsciiSpec(spec);
LOG(("%s\n -> %s\n", spec.get(), PromiseFlatCString(result).get()));
}
#endif
return rv;
}