A website for producing interactive charts without writing a single line of code. Built with Common Lisp and Python. https://charts.craigoates.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

45 lines
1.6 KiB

(defpackage #:validation
(:use #:cl)
(:export
#:clean-filename
#:string-is-nil-or-empty-p
#:separate-files-in-web-request))
(in-package #:validation)
(defun validation-test ()
(format t "~&[INFO] Validation package reached."))
(defun request-params (request)
(loop :for (key . value) :in request
:collect (let ((*package* (find-package :keyword)))
(read-from-string key))
:collect value))
(defun string-is-nil-or-empty-p (string-to-test)
"Tests to see if `STRING-TO-TEST' is empty of just whitespace.
This is essentially the 'IsNullOrWhiteSpace' function I use in C#. It
expands the 'empty string' check to include a check to see if there is
string with just a '(white) space' in it."
(if (or (string= string-to-test " ")
(zerop (length string-to-test))
(null string-to-test))
t
nil))
(defun separate-files-in-web-request (request &optional request-value)
"Creates a new list of 'upload' files from a web `REQUEST'.
You will mostly use this for processing a multi-file upload (HTML)
form. The standard value for the 'name' attribute in (file) input tag
in the HTML form is `CONTENT-FILES' but you can use a different
name. Just specify it in this function's `REQUEST-VALUE' argument."
(loop :for item :in request
if (or (string= "CONTENT-FILES" (car item))
(string= request-value (car item)))
collect item))
(defun clean-filename (filename)
"Basically, slugifies it, removes whitespace, trims it Etc."
(let* ((lowercased (string-downcase filename))
(trimmed (string-trim '(#\Space #\Tab) lowercased))
(whitespaced (substitute #\- #\Space trimmed)))
whitespaced))