/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
for (; len && *p && !colon && !slash; ++p, --len) { switch (*p) { case':': if (!colon) colon = p; break; case'/': // start of filepath case'?': // start of query case'#': // start of ref if (!slash) slash = p; break; case'@': // username@hostname case'[': // start of IPv6 address literal if (!stop) stop = p; break;
}
} // disregard the first colon if it follows an '@' or a '[' if (colon && stop && colon > stop) colon = nullptr;
// if the spec only contained whitespace ... if (specLen == 0) {
SET_RESULT(scheme, 0, -1);
SET_RESULT(authority, 0, 0);
SET_RESULT(path, 0, 0); return NS_OK;
}
// ignore trailing whitespace and control characters for (p = spec + specLen - 1; ((unsignedchar)*p <= ' ') && (p != spec); --p) {
;
}
// search for first occurrence of either ? or # constchar *query_beg = nullptr, *query_end = nullptr; constchar* ref_beg = nullptr; constchar* p = nullptr; for (p = path; p < path + pathLen; ++p) { // only match the query string if it precedes the reference fragment if (!ref_beg && !query_beg && *p == '?') {
query_beg = p + 1;
} elseif (*p == '#') {
ref_beg = p + 1; if (query_beg) query_end = p; break;
}
}
// everything is the path
uint32_t pos = 0; switch (CountConsecutiveSlashes(spec, specLen)) { case 0: case 1: break; case 2: { constchar* p = nullptr; if (specLen > 2) { // looks like there is an authority section
// if the authority looks like a drive number then we // really want to treat it as part of the path // [a-zA-Z][:|]{/\} // i.e one of: c: c:\foo c:/foo c| c|\foo c|/foo if ((specLen > 3) && (spec[3] == ':' || spec[3] == '|') &&
IsAsciiAlpha(spec[2]) &&
((specLen == 4) || (spec[4] == '/') || (spec[4] == '\\'))) {
pos = 1; break;
} // Ignore apparent authority; path is everything after it for (p = spec + 2; p < spec + specLen; ++p) { if (*p == '/' || *p == '?' || *p == '#') break;
}
}
SET_RESULT(auth, 0, -1); if (p && p != spec + specLen) {
SET_RESULT(path, p - spec, specLen - (p - spec));
} else {
SET_RESULT(path, 0, -1);
} return;
} default:
pos = 2; break;
}
SET_RESULT(auth, pos, 0);
SET_RESULT(path, pos, specLen - pos);
}
if (filepathLen < 0) filepathLen = strlen(filepath);
// look for a filepath consisting of only a drive number, which may or // may not have a leading slash. if (filepathLen > 1 && filepathLen < 4) { constchar* end = filepath + filepathLen; constchar* p = filepath; if (*p == '/') p++; if ((end - p == 2) && (p[1] == ':' || p[1] == '|') && IsAsciiAlpha(*p)) { // filepath = <drive-number>:
SET_RESULT(directory, 0, filepathLen);
SET_RESULT(basename, 0, -1);
SET_RESULT(extension, 0, -1); return NS_OK;
}
}
// otherwise fallback on common implementation return nsBaseURLParser::ParseFilePath(filepath, filepathLen, directoryPos,
directoryLen, basenamePos, basenameLen,
extensionPos, extensionLen);
} #endif
if (serverinfoLen < 0) serverinfoLen = strlen(serverinfo);
if (serverinfoLen == 0) {
SET_RESULT(hostname, 0, 0); if (port) *port = -1; return NS_OK;
}
// search backwards for a ':' but stop on ']' (IPv6 address literal // delimiter). check for illegal characters in the hostname. constchar* p = serverinfo + serverinfoLen - 1; constchar *colon = nullptr, *bracket = nullptr; for (; p > serverinfo; --p) { switch (*p) { case']':
bracket = p; break; case':': if (bracket == nullptr) colon = p; break; case' ': // hostname must not contain a space return NS_ERROR_MALFORMED_URI;
}
}
if (colon) { // serverinfo = <hostname:port>
SET_RESULT(hostname, 0, colon - serverinfo); if (port) { // XXX unfortunately ToInteger is not defined for substrings
nsAutoCString buf(colon + 1, serverinfoLen - (colon + 1 - serverinfo)); if (buf.Length() == 0) {
*port = -1;
} else { constchar* nondigit = NS_strspnp("0123456789", buf.get()); if (nondigit && *nondigit) return NS_ERROR_MALFORMED_URI;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.