Common Lisp Package: CLACK.UTIL.ROUTE

# Clack.Util.Route - Class for Sinatra-compatible URL rule. ## SYNOPSIS (defvar *url-rule* (make-url-rule "/hello/:name")) (match *url-rule* "/hello/fukamachi") ;=> (NAME "fukamachi") (match *url-rule* "/bye/fukamachi") ;=> NIL (url-for *url-rule* '(:name "fukamachi")) ;=> "/hello/fukamachi" ## DESCRIPTION Clack.Util.Route provides a Sinatra-compatible routing class. ### Named Parameter (match (make-url-rule "/hello/:name") "/hello/fukamachi") ;=> "/hello/fukamachi" (:NAME "fukamachi") ### Wildcard Parameter (match (make-url-rule "/say/*/to/*") "/say/hello/to/world") ;=> "/say/hello/to/world" (:SPLAT ("hello" "world")) ### Optional Parameter (match (make-url-rule "/?:foo?/?:bar?") "/hello/world") ;=> "/hello/world" (:FOO "hello" :BAR "world") (match (make-url-rule "/?:foo?/?:bar?") "/hello") ;=> "/hello" (:FOO "hello" :BAR NIL) (match (make-url-rule "/?:foo?/?:bar?") "/") ;=> "/" (:FOO NIL :BAR NIL) ### Regular Expression (match (make-url-rule "/hello([\w]+)" :regexp t) "/hello/world") ;=> "/hello/world" (:CAPTURES ("world")) ## AUTHOR * Eitarow Fukamachi (e.arrows@gmail.com) * Tomohiro Matsuyama (tomo@cx4a.org) Note: `compile-rule` was originally written by Tomohiro Matsuyama as `parse-url-rule` in Clack.App.Route.

README:

FUNCTION

Public

MAKE-URL-RULE (URL &KEY (METHOD GET) REGEXP)

Construct `<url-rule>` and return it. You must always use this function when you need `<url-rule>`.

Private

QUOTE-META-CHARS (STRING &KEY (START 0) (END (LENGTH STRING)))

Quote, i.e. prefix with #\\, all non-word characters in STRING.

REGEX-REPLACE-ALL (REGEX TARGET-STRING REPLACEMENT &KEY (START 0) (END (LENGTH TARGET-STRING)) PRESERVE-CASE SIMPLE-CALLS (ELEMENT-TYPE 'CHARACTER))

Try to match TARGET-STRING between START and END against REGEX and replace all matches with REPLACEMENT. Two values are returned; the modified string, and T if REGEX matched or NIL otherwise. REPLACEMENT can be a string which may contain the special substrings "\&" for the whole match, "\`" for the part of TARGET-STRING before the match, "\'" for the part of TARGET-STRING after the match, "\N" or "\{N}" for the Nth register where N is a positive integer. REPLACEMENT can also be a function designator in which case the match will be replaced with the result of calling the function designated by REPLACEMENT with the arguments TARGET-STRING, START, END, MATCH-START, MATCH-END, REG-STARTS, and REG-ENDS. (REG-STARTS and REG-ENDS are arrays holding the start and end positions of matched registers or NIL - the meaning of the other arguments should be obvious.) Finally, REPLACEMENT can be a list where each element is a string, one of the symbols :MATCH, :BEFORE-MATCH, or :AFTER-MATCH - corresponding to "\&", "\`", and "\'" above -, an integer N - representing register (1+ N) -, or a function designator. If PRESERVE-CASE is true, the replacement will try to preserve the case (all upper case, all lower case, or capitalized) of the match. The result will always be a fresh string, even if REGEX doesn't match. ELEMENT-TYPE is the element type of the resulting string.

SCAN-TO-STRINGS (REGEX TARGET-STRING &KEY (START 0) (END (LENGTH TARGET-STRING)) SHAREDP)

Like SCAN but returns substrings of TARGET-STRING instead of positions, i.e. this function returns two values on success: the whole match as a string plus an array of substrings (or NILs) corresponding to the matched registers. If SHAREDP is true, the substrings may share structure with TARGET-STRING.

SPLIT (REGEX TARGET-STRING &KEY (START 0) (END (LENGTH TARGET-STRING)) LIMIT WITH-REGISTERS-P OMIT-UNMATCHED-P SHAREDP)

Matches REGEX against TARGET-STRING as often as possible and returns a list of the substrings between the matches. If WITH-REGISTERS-P is true, substrings corresponding to matched registers are inserted into the list as well. If OMIT-UNMATCHED-P is true, unmatched registers will simply be left out, otherwise they will show up as NIL. LIMIT limits the number of elements returned - registers aren't counted. If LIMIT is NIL (or 0 which is equivalent), trailing empty strings are removed from the result list. If REGEX matches an empty string the scan is continued one position behind this match. If SHAREDP is true, the substrings may share structure with TARGET-STRING.

Undocumented

ESCAPE-SPECIAL-CHAR (CHAR)

GENERIC-FUNCTION

Public

Undocumented

MATCH (THIS METHOD URL-STRING &KEY ALLOW-HEAD)

URL-FOR (THIS PARAMS)

Private

Undocumented

COMPILE-RULE (THIS)

MATCH-METHOD-P (THIS METHOD &KEY ALLOW-HEAD)

SLOT-ACCESSOR

Private

Undocumented

FORMAT-STRING (OBJECT)

SETFFORMAT-STRING (NEW-VALUE OBJECT)

PARAM-KEYS (OBJECT)

SETFPARAM-KEYS (NEW-VALUE OBJECT)

REGEX (OBJECT)

SETFREGEX (NEW-VALUE OBJECT)

REQUEST-METHOD (OBJECT)

SETFREQUEST-METHOD (NEW-VALUE OBJECT)

URL (OBJECT)

SETFURL (NEW-VALUE OBJECT)

CLASS

Public

Undocumented

<URL-RULE>

Private

Undocumented

<REGEX-URL-RULE>