首页 > 解决方案 > 如何使用 Common Lisp 中名为 Quri 的替代库获得相同的 puri:uri-parsed-path 输出?

问题描述

使用 CL (SBCL) 和 Puri 库,我得到了 Slime 的 REPL:

CL-USER> (puri:uri-parsed-path  (puri:parse-uri "http://www.gnu.org/software/emacs/manual/html_node/emacs/index.html"))

(:ABSOLUTE "software" "emacs" "manual" "html_node" "emacs" "index.html")

我正在尝试使用Quri而不是 Puri 来实现相同的输出(包含 URL 路径中的拆分项的列表)。

不幸的是,我没有实现它。我试过了quri-parse-path

CL-USER> quri-object
#<QURI.URI.HTTP:URI-HTTP http://www.gnu.org/software/emacs/>
CL-USER> (quri:parse-path (quri:uri-path quri-object))
"/software/emacs/"
0
16

库是否已经支持此操作?

我不确定它是否仅通过阅读 Quri 的文档。不过,我仍然是 CL 的菜鸟。

标签: uricommon-lisp

解决方案


我建议获取uri路径,并用“/”分割:

(quri:uri "http://www.gnu.org/software/emacs/manual/html_node/emacs/index.html")
#<QURI.URI.HTTP:URI-HTTP http://www.gnu.org/software/emacs/manual/html_node/emacs/index.html>

(quri:uri-path *)
"/software/emacs/manual/html_node/emacs/index.html"

(ql:quickload "str")
(str:split "/" * :omit-nulls t)
("software" "emacs" "manual" "html_node" "emacs" "index.html")

推荐阅读