Common Lisp Package: CLACK.APP.URLMAP

# Clack.App.URLMap - Map multiple apps in different paths. ## SYNOPSIS (defparameter *urlmap* (make-instance '<clack-app-urlmap>)) (mount *urlmap* "/pc/" #'app-for-pc) (mount *urlmap* "/api/" #'app-for-api) (call *urlmap* env) ;; Useful synonym. (builder-urlmap ("/pc/" #'app-for-pc) ("/api/" #'app-for-api)) ## AUTHOR * Eitarow Fukamachi (e.arrows@gmail.com) ## SEE ALSO * Clack.Builder

README:

FUNCTION

Private

REGEX-REPLACE (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 the first match 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.

MACRO

Public

BUILDER-URLMAP (&REST APPS)

Useful syntax sugar for building applications.

GENERIC-FUNCTION

Public

Undocumented

MOUNT (THIS LOCATION APP)

Private

SCAN (REGEX TARGET-STRING &KEY START END REAL-START-POS ((REAL-START-POS *REAL-START-POS*) NIL) (END (LENGTH TARGET-STRING)) (START 0))

Searches TARGET-STRING from START to END and tries to match REGEX. On success returns four values - the start of the match, the end of the match, and two arrays denoting the beginnings and ends of register matches. On failure returns NIL. REGEX can be a string which will be parsed according to Perl syntax, a parse tree, or a pre-compiled scanner created by CREATE-SCANNER. TARGET-STRING will be coerced to a simple string if it isn't one already. The REAL-START-POS parameter should be ignored - it exists only for internal purposes.

CLASS

Public

<CLACK-APP-URLMAP>

Class to map multiple apps in different paths.