cl-data-format-validation

API Reference

data-format-validation

Validation and conversion between user and internal data.

DATA-FORMAT-VALIDATION

Exports API for validation and conversion of user
  data to internal types and back again.
  • Condition INVALID-FORMAT  (CONDITION)
  • Generic-Function FORMAT-OUTPUT (specification value &key &allow-other-keys)
    Return a string representation of value formatted according to a specification. If specification is a list the first element specifies the actual validation method and the rest of the list are passed as keyword arguments to the specific method e.g. (format-output '(date :fmt :rfc2822) (get-universal-time)) >"Mon, 10 Jul 2006 15:43:45 +00"
  • Generic-Function PARSE-INPUT (specification input &key &allow-other-keys)
    Validate and parse user input according to specification, returning the validated object. Throws an invalid-format condition if input is invalid. If specification is a list the first element specifies the actual validation method and the rest of the list are passed as keyword arguments to the specific method e.g. (parse-input '(integer :min 0) input) will return the integer value from string if it is >0, or signal and invalid-format condition if not. (parse-input '(member :type integer :set (1 5 7)) input) will return it only if it has a value in the set. The use-value restart may be used to provide substitute value if the input is invalid.
  • Method PARSE-INPUT ((specification symbol) input &rest args)
  • Method PARSE-INPUT ((specification symbol) input &rest args)
  • Method PARSE-INPUT ((specification symbol) input &rest args)
  • Function SPLIT-STRING (string &key count (delimiter +ws+) remove-empty-subseqs)
    Split `string' along whitespace as defined by the sequence `ws'. Whitespace which causes a split is elided from the result. The whole string will be split, unless `max' is provided, in which case the string will be split into `max' tokens at most, the last one containing the whole rest of the given `string', if any.
  • Function JOIN-STRINGS (strings &optional (separator #\ ))
    Return a new string by joining together the STRINGS, separating each string with a SEPARATOR character or string
  • Method PARSE-INPUT ((spec list) input &rest rest)
    Dispatch a list spec to appropriate method
  • Method PARSE-INPUT ((spec (eql nil)) input &key &allow-other-keys)
    No validation - just return string
  • Method PARSE-INPUT ((spec function) input &key &allow-other-keys)
    Function - call it with data
  • Method PARSE-INPUT ((spec (eql 'boolean)) input &key &allow-other-keys)
  • Method FORMAT-OUTPUT ((spec (eql 'boolean)) input &key fmt &allow-other-keys)
  • Method PARSE-INPUT ((spec (eql 'integer)) (input string) &key min max nil-allowed (radix 10))
  • Method PARSE-INPUT ((spec (eql 'number)) (input string) &key min max nil-allowed format (radix 10) (rational-as-float-p nil) (coerce-to nil))
    Real, integer or rational numbers
  • Method PARSE-INPUT ((spec (eql 'string)) s &key (strip-return nil) nil-allowed min-word-count max-word-count (min-length 0) max-length)
  • Method PARSE-INPUT ((spec (eql 'symbol)) (input string) &key nil-allowed (package :keyword) (convert #'identity))
  • Method PARSE-INPUT ((spec (eql 'member)) input &key type set (test #'equal) key)
  • Method PARSE-INPUT ((spec (eql 'pathname)) (input string) &key must-exist wild-allowed nil-allowed)
  • Method PARSE-INPUT ((spec (eql 'pathnames)) (input string) &key must-exist wild-allowed nil-allowed)
  • Method PARSE-INPUT ((spec (eql 'filename)) value &key (if-invalid :error) (replacement "-"))
    Return a safe filename from a string path value. May return an error or replace invalid characters.
  • Method PARSE-INPUT ((spec (eql 'list)) input &key (separator ", ") type min-length max-length)
    Validates that a list of given of between min-length and max-length in length. Each member of list is validated against type
  • Method PARSE-INPUT ((spec (eql 'date)) (input string) &key nil-allowed (zone nil) (patterns *default-date-time-patterns*))
  • Variable *TIMEZONE*
    nil
    Default timezone for date handling
  • Function DATE (os utime &optional colon-p at-p (precision 7) (timezone *timezone*))
    Formatter which formats a universal time for output as a date and time Modifiers: - os: an output stream designator - arg: a universal time - colon-p: a generalised boolean (default false). If true use month and day names in date - at-p: a generalised boolean (default false) - if true print in yyyy-mm-dd (sortable) format rather than dd-mm-yyy - precision: what precision to print it to. 6 is to the second, 7 includes timezone, a negative number counts backward. - timezone: an integer (default nil). If nil no timezone used and time is in current timezone adjusted for daylight saving time. Result: nil Examples: (format nil "~/date/" (get-universal-time)) => "19-03-2009 08:30"
  • Function DURATION (os seconds &optional colon-p at-p precision width)
  • Method PARSE-INPUT ((spec (eql 'read)) (value string) &key (multiplep nil) (type 't) (package *package*))
    Parse input using read. If multiple is true will read until finished, returning a list of values. If type is set, then returned value(s) must be of this type
  • Method PARSE-INPUT ((spec (eql 'eval)) (value string) &key (type 't) (package *package*))
  • Method PARSE-INPUT ((spec (eql 'separated)) (value sequence) &key (separator ",") type)
  • Method FORMAT-OUTPUT ((spec (eql 'separated)) (value list) &key (separator ", ") type)
  • Method FORMAT-OUTPUT ((spec list) output &rest rest)
    Dispatch a list spec to appropriate method
  • Method FORMAT-OUTPUT (spec output &key &allow-other-keys)
    No validation - just output value
  • Method FORMAT-OUTPUT ((spec string) output &key &allow-other-keys)
  • Method FORMAT-OUTPUT ((spec function) output &key &allow-other-keys)
  • Method FORMAT-OUTPUT ((spec (eql nil)) output &key &allow-other-keys)
    No validation - just output value
  • Method FORMAT-OUTPUT ((spec (eql 'date)) output &key (fmt :iso) (zone *timezone*) (if-nil nil) &allow-other-keys)
  • Method FORMAT-OUTPUT ((spec (eql 'number)) output &key radix format &allow-other-keys)
  • Method FORMAT-OUTPUT ((spec (eql 'integer)) output &key format &allow-other-keys)
  • Method FORMAT-OUTPUT ((spec (eql 'read)) output &key (multiplep nil) (package *package*))
    Parse input using read. If multiple is true will read until finsihed, returning a list of values.
  • Method FORMAT-OUTPUT ((spec (eql 'list)) output &key type (separator ", "))
  • Method FORMAT-OUTPUT ((spec (eql 'member)) output &key type)
  • Method PARSE-INPUT ((spec (eql 'time-period)) (value string) &key &allow-other-keys)
    A time period in hours, minutes and (optionally) seconds
  • Method FORMAT-OUTPUT ((spec (eql 'time-period)) (value number) &key &allow-other-keys)
  • Function PARSE-OPTIONS (spec options-list &optional allow-other-options)
    Parse an option list (alist of names and strings to be parsed) against a specification. The specification is a list of entries each of which lists the name, and optionally type and default values. The output is an alist of variable names and parsed values. Options in options-list not in spec are not returned and will signal an error unless allow-other-options is true
  • Method PARSE-INPUT ((spec (eql 'headers)) (s string) &rest rest)
  • Method PARSE-INPUT ((spec (eql 'headers)) (p pathname) &rest rest)
  • Method PARSE-INPUT ((spec (eql 'headers)) (is stream) &key (skip-blanks-p t) field-specifications (preserve-newlines-p t) (termination-test #'(lambda (line) (zerop (length line)))) if-no-specification &allow-other-keys)
  • Method FORMAT-OUTPUT ((spec (eql 'headers)) (headers list) &key field-specifications if-no-specification stream (preserve-newlines-p t))
  • Function PARSE-ARGUMENTS (spec argument-string &optional allow-spaces)
    Parse a string of whitespace delimited arguments according to spec. The specification is a list of entries each of which lists the name, and optionally type and default values. The output is an alist of variable names and parsed values. If allow-spaces is true, last element can contain spaces
  • Function ENG (os arg &optional colon-p at-p (d 2) (padchar #\ ) (exponentchar #\e))
    Formatter which outputs its numerical argument `arg` in engineering format to stream `os`. It takes arguments d,padchar,exponentchar where d is the number of decimal places to display after the decimal point padchar is the character to pad the start of the number exponentchar is the character to use to display between radix and exponent It also takes the : modifier which will cause it to output the exponent as an SI units prefix rather than a number. Arguments: - `os`: an output stream designator - `arg`: a number - `colon-p`: a generalised boolean (default false) - `at-p`: a generalised boolean (default false) - if set right align field - `d`: an integer (default 2) - `padchar`: a character (default `space`) - `exponentchar`: a character (default `e`)) Result: nil Examples: `(format nil "~/eng/" 35000) => "35.00e+3"`
  • Method FORMAT-OUTPUT ((spec (eql 'eng)) (value number) &key (units t) (padchar #\ ) (decimal-places 2) &allow-other-keys)
    Output in engineering style with units. If units is a string then the output will contain that unit and the appropriate suffix. If t only the suffix is output. If nil no units or suffix is output
  • Method PARSE-INPUT ((spec (eql 'eng)) (value string) &key (units t) &allow-other-keys)
  • Method FORMAT-OUTPUT ((spec (eql 'roman)) (n integer) &key &allow-other-keys)
    convert integer to Roman numeral
  • Method PARSE-INPUT ((spec (eql 'roman)) (s string) &key &allow-other-keys)
    Convert roman numeral to integer
  • Method PARSE-INPUT ((spec (eql 'bit-vector)) (input string) &key &allow-other-keys)
  • Method FORMAT-OUTPUT ((spec (eql 'bit-vector)) (input bit-vector) &key &allow-other-keys)
  • Generic-Function EQUIVALENT (specification input reference &key &allow-other-keys)
    Returns true if the parsed value input is equivalent (equals) the reference value according to the stype specification. If specification is a list the first element specifies the actual validation method and the rest of the list are passed as keyword arguments to the specific method.
  • Method EQUIVALENT ((spec (eql 'number)) input reference &key (tol 0.001) &allow-other-keys)
  • Method EQUIVALENT ((spec (eql 'number)) input reference &key (tol 0.001) &allow-other-keys)
  • Method EQUIVALENT ((spec (eql 'number)) input reference &key (tol 0.001) &allow-other-keys)
  • Method EQUIVALENT (spec input reference &key (test #'equal) &allow-other-keys)
  • Method EQUIVALENT (spec input reference &key (test #'equal) &allow-other-keys)
  • Method EQUIVALENT (spec input reference &key (test #'equal) &allow-other-keys)
  • Method EQUIVALENT ((spec list) input reference &rest rest)
  • Method EQUIVALENT ((spec list) input reference &rest rest)
  • Method EQUIVALENT ((spec list) input reference &rest rest)
  • Method FORMAT-OUTPUT ((spec (eql 'dimensional-parameter)) value &key (padchar #\ ) (decimal-places 2) nil-allowed &allow-other-keys)
    Output in engineering style with units. If units is a string then the output will contain that unit and the appropriate suffix. If t only the suffix is output. If nil no units or suffix is output
  • Method PARSE-INPUT ((spec (eql 'dimensional-parameter)) (value string) &key &allow-other-keys)
  • Method EQUIVALENT ((spec (eql 'dimensional-parameter)) input reference &rest rest)
  • Method PARSE-INPUT ((spec (eql 'percentage)) (value string) &key (min 0) (max 100) nil-allowed &allow-other-keys)
  • Method FORMAT-OUTPUT ((spec (eql 'percentage)) num &key (places 0) (%-p t) (mult 1))
    Return a percentage value formatted for user output (default 0 places)