Common Lisp Package: URL-REWRITE

README:

FUNCTION

Public

ADD-GET-PARAM-TO-URL (URL NAME VALUE)

URL is assumed to be a http URL. The pair of NAME and VALUE will be added as a GET parameter to this URL. Assumes that there's no other parameter of the same name. Only checks if #? is part of the string to decide how to attach the new parameter to the end of the string.

REWRITE-URLS (REWRITE-FN &OPTIONAL (TEST-FN (COMPLEMENT #'STARTS-WITH-SCHEME-P)))

Reads an (X)HTML document from *STANDARD-INPUT* and writes it back to *STANDARD-OUTPUT*. Any attribute value which is in one of the positions denoted by *URL-REWRITE-TAGS* is rewritten by REWRITE-FN if it passes the test denoted by the optional function TEST-FN which defaults to the complement of STARTS-WITH-SCHEME-P. This function aims to yield correct results for correct (X)HTML input and it also tries hard to never signal an error although it may warn if it encounters syntax errors. It will NOT detect any possible error nor is there any warranty that it will work correctly with faulty input.

STARTS-WITH-SCHEME-P (STRING)

Checks whether the string STRING represents a URL which starts with a scheme, i.e. something like 'https://' or 'mailto:'.

URL-ENCODE (STRING)

URL-encode a string.

Private

COMMENT-START-P

Checks whether *STANDARD-OUTPUT* currently 'looks at' the string "--". Will move the position within the stream by one unless the first characters it sees is not a hyphen.

LETTERP (C)

Checks whether C is a character between A and Z (case-insensitive).

NAME-CHAR-P (C)

Checks whether C is a name constituent character in the sense of HTML.

PEEK-CHAR*

PEEK-CHAR with input stream bound to *STANDARD-INPUT* and returning NIL on EOF.

READ-ATTRIBUTE (&KEY (SKIP T) (WRITE-THROUGH T))

Read characters from *STANDARD-INPUT* assuming that they constitue a SGML-style attribute/value pair. Returns three values - the name of the attribute, its value, and the whole string which was read. On EOF the string(s) read so far is/are returned. If SKIP is true NIL is returned. Writes all characters read to *STANDARD-OUTPUT* if WRITE-THROUGH is true.

READ-DELIMITED-STRING (&KEY (SKIP T) (WRITE-THROUGH T))

Reads and returns as its first value a string from *STANDARD-INPUT*. The string is either delimited by ' or " in which case the delimiters aren't part of the string but the second return value is the delimiter character or it is assumed to extend to the next character which is not a name constituent (see NAME-CHAR-P). On EOF the string read so far is returned. If SKIP is true NIL is returned. Writes all characters read to *STANDARD-OUTPUT* if WRITE-THROUGH is true.

READ-NAME (&KEY (SKIP T) (WRITE-THROUGH T))

Read characters from *STANDARD-INPUT* as long as they are name constituents. Returns the string which was read unless SKIP is true. On EOF the string read so far is returned. Writes all characters read to *STANDARD-OUTPUT* if WRITE-THROUGH is true.

READ-UNTIL (STRING &KEY (SKIP T) (WRITE-THROUGH T))

Reads characters from *STANDARD-INPUT* up to and including STRING. Returns the string which was read (excluding STRING) unless SKIP is true. Writes all characters read to *STANDARD-OUTPUT* if WRITE-THROUGH is true. On EOF the string read so far is returned.

READ-WHILE (PREDICATE &KEY (SKIP T) (WRITE-THROUGH T))

Reads characters from *STANDARD-INPUT* while PREDICATE returns a true value for each character. Returns the string which was read unless SKIP is true. Writes all characters read to *STANDARD-OUTPUT* if WRITE-THROUGH is true. On EOF the string read so far is returned.

SKIP-COMMENT

Skip SGML comment from *STANDARD-INPUT*, i.e. a string enclosed in '--' on both sides. Returns no values. Writes all characters read to *STANDARD-OUTPUT*. This function assumes (without checking) that the current position of *STANDARD-INPUT* is at the beginning of a comment, after the first hyphen - see COMMENT-START-P.

SKIP-WHITESPACE (&KEY (SKIP T) (WRITE-THROUGH T))

Read characters from *STANDARD-INPUT* as long as they are whitespace. Returns the string which was read unless SKIP is true. On EOF the string read so far is returned. Writes all characters read to *STANDARD-OUTPUT* if WRITE-THROUGH is true.

WHITESPACEP (C)

Checks whether C is a whitespace character.

Undocumented

HYPERDOC-LOOKUP (SYMBOL TYPE)

VARIABLE

Public

*URL-REWRITE-FILL-TAGS*

The tag/attribute combinations where URL-rewriting should optionally add an attribute.

*URL-REWRITE-TAGS*

The tag/attribute combinations where URL-rewriting should happen.

Private

*FIND-STRING-HASH*

Hash tables used internally by READ-UNTIL to cache offset arrays.

Undocumented

*HYPERDOC-BASE-URI*