nsIURLParser 编辑

netwerk/base/public/nsIURLParser.idlScriptable Specifies the interface to an URL parser that attempts to follow the definitions of RFC 2396. Inherits from: nsISupports Last changed in Gecko 1.7

Method overview

void parseAuthority(in string authority, in long authorityLen, out unsigned long usernamePos, out long usernameLen, out unsigned long passwordPos, out long passwordLen, out unsigned long hostnamePos, out long hostnameLen, out long port);
void parseFileName(in string filename, in long filenameLen, out unsigned long basenamePos, out long basenameLen, out unsigned long extensionPos, out long extensionLen);
void parseFilePath(in string filepath, in long filepathLen, out unsigned long directoryPos, out long directoryLen, out unsigned long basenamePos, out long basenameLen, out unsigned long extensionPos, out long extensionLen);
void parsePath(in string path, in long pathLen, out unsigned long filepathPos, out long filepathLen, out unsigned long paramPos, out long paramLen, out unsigned long queryPos, out long queryLen, out unsigned long refPos, out long refLen);
void parseServerInfo(in string serverinfo, in long serverinfoLen, out unsigned long hostnamePos, out long hostnameLen, out long port);
void parseURL(in string spec, in long specLen, out unsigned long schemePos, out long schemeLen, out unsigned long authorityPos, out long authorityLen, out unsigned long pathPos, out long pathLen);
void parseUserInfo(in string userinfo, in long userinfoLen, out unsigned long usernamePos, out long usernameLen, out unsigned long passwordPos, out long passwordLen);

Methods

The string to parse in the methods may be given as a null terminated string, in which case the length argument should be -1.

Out parameters of the methods are all optional (that is the caller may pass-in a null value if the corresponding results are not needed). Signed out parameters may hold a value of -1 if the corresponding result is not part of the string being parsed.

The parsing routines attempt to be as forgiving as possible.

parseAuthority()

Breaks the authority string up into its 4 components: username, password, hostname, and hostport.

auth = <username>:<password>@<hostname>:<port>

void parseAuthority(
  in string authority,
  in long authorityLen,
  out unsigned long usernamePos,
  out long usernameLen,
  out unsigned long passwordPos,
  out long passwordLen,
  out unsigned long hostnamePos,
  out long hostnameLen,
  out long port
);
Parameters
authority
authorityLen
usernamePos
usernameLen
passwordPos
passwordLen
hostnamePos
hostnameLen
port

parseFileName()

filename = <basename>.<extension>

void parseFileName(
  in string filename,
  in long filenameLen,
  out unsigned long basenamePos,
  out long basenameLen,
  out unsigned long extensionPos,
  out long extensionLen
);
Parameters
filename
filenameLen
basenamePos
basenameLen
extensionPos
extensionLen

parseFilePath()

Breaks the file path string up into: the directory portion, file base name, and file extension.

filepath = <directory><basename>.<extension>

void parseFilePath(
  in string filepath,
  in long filepathLen,
  out unsigned long directoryPos,
  out long directoryLen,
  out unsigned long basenamePos,
  out long basenameLen,
  out unsigned long extensionPos,
  out long extensionLen
);
Parameters
filepath
filepathLen
directoryPos
directoryLen
basenamePos
basenameLen
extensionPos
extensionLen

parsePath()

Breaks the path string up into its 4 major components: a file path, a param string, a query string, and a reference string.

path = <filepath>;<param>?<query>#<ref>

void parsePath(
  in string path,
  in long pathLen,
  out unsigned long filepathPos,
  out long filepathLen,
  out unsigned long paramPos, // Removed in Gecko 9.0
  out long paramLen, // Removed in Gecko 9.0
  out unsigned long queryPos,
  out long queryLen,
  out unsigned long refPos,
  out long refLen
);
Parameters
path
pathLen
filepathPos
filepathLen
paramPos Obsolete since Gecko 9.0
paramLenObsolete since Gecko 9.0
queryPos
queryLen
refPos
refLen

parseServerInfo()

serverinfo = <hostname>:<port>

void parseServerInfo(
  in string serverinfo,
  in long serverinfoLen,
  out unsigned long hostnamePos,
  out long hostnameLen,
  out long port
);
Parameters
serverinfo
serverinfoLen
hostnamePos
hostnameLen
port

parseURL()

Breaks the URL string up into its 3 major components: a scheme, an authority section (hostname, and so on.), and a path.

spec = <scheme>://<authority><path>

void parseURL(
  in string spec,
  in long specLen,
  out unsigned long schemePos,
  out long schemeLen,
  out unsigned long authorityPos,
  out long authorityLen,
  out unsigned long pathPos,
  out long pathLen
);
Parameters
spec
specLen
schemePos
schemeLen
authorityPos
authorityLen
pathPos
pathLen

parseUserInfo()

userinfo = <username>:<password>

void parseUserInfo(
  in string userinfo,
  in long userinfoLen,
  out unsigned long usernamePos,
  out long usernameLen,
  out unsigned long passwordPos,
  out long passwordLen
);
Parameters
userinfo
userinfoLen
usernamePos
usernameLen
passwordPos
passwordLen

Notes

Starting in Gecko 9.0 (Firefox 9.0 / Thunderbird 9.0 / SeaMonkey 2.6), this no longer treats the semicolon as a "parameter string" marker. This was never a valid part of a URL, and is now no longer supported. This makes URLs with semicolons in them work correctly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:67 次

字数:9613

最后编辑:6年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文