Init
This commit is contained in:
commit
fe8bba1d3b
|
@ -0,0 +1,165 @@
|
||||||
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
|
||||||
|
This version of the GNU Lesser General Public License incorporates
|
||||||
|
the terms and conditions of version 3 of the GNU General Public
|
||||||
|
License, supplemented by the additional permissions listed below.
|
||||||
|
|
||||||
|
0. Additional Definitions.
|
||||||
|
|
||||||
|
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||||
|
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||||
|
General Public License.
|
||||||
|
|
||||||
|
"The Library" refers to a covered work governed by this License,
|
||||||
|
other than an Application or a Combined Work as defined below.
|
||||||
|
|
||||||
|
An "Application" is any work that makes use of an interface provided
|
||||||
|
by the Library, but which is not otherwise based on the Library.
|
||||||
|
Defining a subclass of a class defined by the Library is deemed a mode
|
||||||
|
of using an interface provided by the Library.
|
||||||
|
|
||||||
|
A "Combined Work" is a work produced by combining or linking an
|
||||||
|
Application with the Library. The particular version of the Library
|
||||||
|
with which the Combined Work was made is also called the "Linked
|
||||||
|
Version".
|
||||||
|
|
||||||
|
The "Minimal Corresponding Source" for a Combined Work means the
|
||||||
|
Corresponding Source for the Combined Work, excluding any source code
|
||||||
|
for portions of the Combined Work that, considered in isolation, are
|
||||||
|
based on the Application, and not on the Linked Version.
|
||||||
|
|
||||||
|
The "Corresponding Application Code" for a Combined Work means the
|
||||||
|
object code and/or source code for the Application, including any data
|
||||||
|
and utility programs needed for reproducing the Combined Work from the
|
||||||
|
Application, but excluding the System Libraries of the Combined Work.
|
||||||
|
|
||||||
|
1. Exception to Section 3 of the GNU GPL.
|
||||||
|
|
||||||
|
You may convey a covered work under sections 3 and 4 of this License
|
||||||
|
without being bound by section 3 of the GNU GPL.
|
||||||
|
|
||||||
|
2. Conveying Modified Versions.
|
||||||
|
|
||||||
|
If you modify a copy of the Library, and, in your modifications, a
|
||||||
|
facility refers to a function or data to be supplied by an Application
|
||||||
|
that uses the facility (other than as an argument passed when the
|
||||||
|
facility is invoked), then you may convey a copy of the modified
|
||||||
|
version:
|
||||||
|
|
||||||
|
a) under this License, provided that you make a good faith effort to
|
||||||
|
ensure that, in the event an Application does not supply the
|
||||||
|
function or data, the facility still operates, and performs
|
||||||
|
whatever part of its purpose remains meaningful, or
|
||||||
|
|
||||||
|
b) under the GNU GPL, with none of the additional permissions of
|
||||||
|
this License applicable to that copy.
|
||||||
|
|
||||||
|
3. Object Code Incorporating Material from Library Header Files.
|
||||||
|
|
||||||
|
The object code form of an Application may incorporate material from
|
||||||
|
a header file that is part of the Library. You may convey such object
|
||||||
|
code under terms of your choice, provided that, if the incorporated
|
||||||
|
material is not limited to numerical parameters, data structure
|
||||||
|
layouts and accessors, or small macros, inline functions and templates
|
||||||
|
(ten or fewer lines in length), you do both of the following:
|
||||||
|
|
||||||
|
a) Give prominent notice with each copy of the object code that the
|
||||||
|
Library is used in it and that the Library and its use are
|
||||||
|
covered by this License.
|
||||||
|
|
||||||
|
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||||
|
document.
|
||||||
|
|
||||||
|
4. Combined Works.
|
||||||
|
|
||||||
|
You may convey a Combined Work under terms of your choice that,
|
||||||
|
taken together, effectively do not restrict modification of the
|
||||||
|
portions of the Library contained in the Combined Work and reverse
|
||||||
|
engineering for debugging such modifications, if you also do each of
|
||||||
|
the following:
|
||||||
|
|
||||||
|
a) Give prominent notice with each copy of the Combined Work that
|
||||||
|
the Library is used in it and that the Library and its use are
|
||||||
|
covered by this License.
|
||||||
|
|
||||||
|
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||||
|
document.
|
||||||
|
|
||||||
|
c) For a Combined Work that displays copyright notices during
|
||||||
|
execution, include the copyright notice for the Library among
|
||||||
|
these notices, as well as a reference directing the user to the
|
||||||
|
copies of the GNU GPL and this license document.
|
||||||
|
|
||||||
|
d) Do one of the following:
|
||||||
|
|
||||||
|
0) Convey the Minimal Corresponding Source under the terms of this
|
||||||
|
License, and the Corresponding Application Code in a form
|
||||||
|
suitable for, and under terms that permit, the user to
|
||||||
|
recombine or relink the Application with a modified version of
|
||||||
|
the Linked Version to produce a modified Combined Work, in the
|
||||||
|
manner specified by section 6 of the GNU GPL for conveying
|
||||||
|
Corresponding Source.
|
||||||
|
|
||||||
|
1) Use a suitable shared library mechanism for linking with the
|
||||||
|
Library. A suitable mechanism is one that (a) uses at run time
|
||||||
|
a copy of the Library already present on the user's computer
|
||||||
|
system, and (b) will operate properly with a modified version
|
||||||
|
of the Library that is interface-compatible with the Linked
|
||||||
|
Version.
|
||||||
|
|
||||||
|
e) Provide Installation Information, but only if you would otherwise
|
||||||
|
be required to provide such information under section 6 of the
|
||||||
|
GNU GPL, and only to the extent that such information is
|
||||||
|
necessary to install and execute a modified version of the
|
||||||
|
Combined Work produced by recombining or relinking the
|
||||||
|
Application with a modified version of the Linked Version. (If
|
||||||
|
you use option 4d0, the Installation Information must accompany
|
||||||
|
the Minimal Corresponding Source and Corresponding Application
|
||||||
|
Code. If you use option 4d1, you must provide the Installation
|
||||||
|
Information in the manner specified by section 6 of the GNU GPL
|
||||||
|
for conveying Corresponding Source.)
|
||||||
|
|
||||||
|
5. Combined Libraries.
|
||||||
|
|
||||||
|
You may place library facilities that are a work based on the
|
||||||
|
Library side by side in a single library together with other library
|
||||||
|
facilities that are not Applications and are not covered by this
|
||||||
|
License, and convey such a combined library under terms of your
|
||||||
|
choice, if you do both of the following:
|
||||||
|
|
||||||
|
a) Accompany the combined library with a copy of the same work based
|
||||||
|
on the Library, uncombined with any other library facilities,
|
||||||
|
conveyed under the terms of this License.
|
||||||
|
|
||||||
|
b) Give prominent notice with the combined library that part of it
|
||||||
|
is a work based on the Library, and explaining where to find the
|
||||||
|
accompanying uncombined form of the same work.
|
||||||
|
|
||||||
|
6. Revised Versions of the GNU Lesser General Public License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the GNU Lesser General Public License from time to time. Such new
|
||||||
|
versions will be similar in spirit to the present version, but may
|
||||||
|
differ in detail to address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Library as you received it specifies that a certain numbered version
|
||||||
|
of the GNU Lesser General Public License "or any later version"
|
||||||
|
applies to it, you have the option of following the terms and
|
||||||
|
conditions either of that published version or of any later version
|
||||||
|
published by the Free Software Foundation. If the Library as you
|
||||||
|
received it does not specify a version number of the GNU Lesser
|
||||||
|
General Public License, you may choose any version of the GNU Lesser
|
||||||
|
General Public License ever published by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Library as you received it specifies that a proxy can decide
|
||||||
|
whether future versions of the GNU Lesser General Public License shall
|
||||||
|
apply, that proxy's public statement of acceptance of any version is
|
||||||
|
permanent authorization for you to choose that version for the
|
||||||
|
Library.
|
|
@ -0,0 +1,108 @@
|
||||||
|
================================================================================
|
||||||
|
NIH : `Not Invented Here` A redundant misc. library
|
||||||
|
================================================================================
|
||||||
|
|
||||||
|
I've found that, generally, I end up using the same custom functions over and
|
||||||
|
over again across all of my projects-- sometimes I'll copy-and-paste, other
|
||||||
|
times I'll just re-implement.
|
||||||
|
|
||||||
|
... which, predictably, leads to inconsistensies. While some versions of `x`
|
||||||
|
function will flourish, gain new features, etc. etc., the others will
|
||||||
|
inevitably lag behind.
|
||||||
|
|
||||||
|
Well, no longer!
|
||||||
|
|
||||||
|
I've decided to stuff (somewhat) refactored versions of these generic functions
|
||||||
|
here, in this library!
|
||||||
|
|
||||||
|
Most of them have to deal with string manipulations, but there's a bit more
|
||||||
|
than that-- and everything has tests! :)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
----------------------------------------
|
||||||
|
USAGE
|
||||||
|
----------------------------------------
|
||||||
|
|
||||||
|
I mean... it's a library. Use a function you like. Or not. =w=
|
||||||
|
But here's my logic with the string manipulation functions:
|
||||||
|
|
||||||
|
I want to treat strings like lists. Getting the `car` of "hi there, dad", for
|
||||||
|
example, should return "hi". Getting the `cdr` should be "there, dad".
|
||||||
|
But, then again, that uses WORDS as the unit.
|
||||||
|
What if I wanted to get the `car` or some such thing as say, a character? Or
|
||||||
|
maybe even have the unit be a line?
|
||||||
|
|
||||||
|
Thus, there are three different `units`:
|
||||||
|
* line-
|
||||||
|
* char-
|
||||||
|
* word-
|
||||||
|
|
||||||
|
Each of these have the following functions:
|
||||||
|
* get-all
|
||||||
|
* get
|
||||||
|
* remove-all
|
||||||
|
* remove
|
||||||
|
* position
|
||||||
|
* positions
|
||||||
|
* nth
|
||||||
|
* car
|
||||||
|
* cdr
|
||||||
|
* caar
|
||||||
|
* cddr
|
||||||
|
* (all combos of cdr and car)
|
||||||
|
|
||||||
|
... which behave pretty predictably.
|
||||||
|
|
||||||
|
The `get` functions use regex (as do the remove functions), position(s) use
|
||||||
|
the verbatim item value, etc.
|
||||||
|
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
(word-car "hiya, mate-o. how're you doing? <3")
|
||||||
|
> "hiya,"
|
||||||
|
|
||||||
|
(word-nth 2 "hiya, dad. what's up?")
|
||||||
|
> "dad."
|
||||||
|
|
||||||
|
(line-get-all ".*e.*"
|
||||||
|
"hiya, what's up?
|
||||||
|
don't eat anyone else, OK?
|
||||||
|
i wouldn't like that.
|
||||||
|
would you?")
|
||||||
|
> "don't eat anyone else, OK?
|
||||||
|
would you?"
|
||||||
|
|
||||||
|
(char-remove #\h "hi there")
|
||||||
|
> "i there"
|
||||||
|
|
||||||
|
(char-remove-all #\h "hi there")
|
||||||
|
> "i tere"
|
||||||
|
|
||||||
|
... so on and so forth.
|
||||||
|
|
||||||
|
|
||||||
|
Oh, and those are just for generic string manips. There are still some
|
||||||
|
|
||||||
|
Honourable Mentions
|
||||||
|
--------------------
|
||||||
|
#'get-colon-values
|
||||||
|
#'remove-colon-values
|
||||||
|
#'positions
|
||||||
|
#'nil-blank
|
||||||
|
#'before
|
||||||
|
#'after
|
||||||
|
#'preceding
|
||||||
|
... etc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
----------------------------------------
|
||||||
|
BORING STUFF
|
||||||
|
----------------------------------------
|
||||||
|
|
||||||
|
License is in COPYING.txt (GNU LGPLv3~! <3)
|
||||||
|
Author is Jaidyn Ann <jadedctrl@teknik.io>
|
||||||
|
Sauce is at https://git.eunichx.us/nih
|
|
@ -0,0 +1,17 @@
|
||||||
|
(defsystem "nih"
|
||||||
|
:version "0.1"
|
||||||
|
:author "Jaidyn Ann <jadedctrl@teknik.io>"
|
||||||
|
:license "CC 0"
|
||||||
|
:depends-on ("cl-strings" "cl-ppcre")
|
||||||
|
:components ((:module "src"
|
||||||
|
:components
|
||||||
|
((:file "package")
|
||||||
|
(:file "misc")
|
||||||
|
(:file "list")
|
||||||
|
(:file "string/string")
|
||||||
|
(:file "string/word")
|
||||||
|
(:file "string/line")
|
||||||
|
(:file "string/char"))))
|
||||||
|
|
||||||
|
:description
|
||||||
|
"Library of miscellanous (probably extraneous) functions (mainly string-manipulations).")
|
|
@ -0,0 +1,95 @@
|
||||||
|
(in-package :nih)
|
||||||
|
|
||||||
|
;; ITEM LIST --> DATA_AFTER_ITEM
|
||||||
|
(defun following (item list)
|
||||||
|
"Return all items following the first instance of ITEM"
|
||||||
|
|
||||||
|
(cdr (up-from (position item list :test #'equal) list)))
|
||||||
|
|
||||||
|
|
||||||
|
;; ITEM LIST --> DATA_UP_TO_ITEM
|
||||||
|
(defun preceding (item list)
|
||||||
|
"Return all items preceding the first instance of ITEM"
|
||||||
|
|
||||||
|
(reverse
|
||||||
|
(cdr (reverse
|
||||||
|
(up-to (position item list :test #'equal) list)))))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
;; ITEM LIST --> ITEM_BEFORE_ITEM
|
||||||
|
(defun before (item list)
|
||||||
|
"Return the single item before ITEM"
|
||||||
|
|
||||||
|
(car (reverse (preceding item list))))
|
||||||
|
|
||||||
|
|
||||||
|
;; ITEM LIST --> ITEM_AFTER_ITEM
|
||||||
|
(defun after (item list)
|
||||||
|
"Return the single item after ITEM"
|
||||||
|
|
||||||
|
(car (following item list)))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
;; N LIST --> LIST_FROM_N
|
||||||
|
(defun up-from (n list &optional (n-stack 0))
|
||||||
|
"Return all items after and including the position N in list"
|
||||||
|
|
||||||
|
(if (eq n n-stack)
|
||||||
|
list
|
||||||
|
(up-from n (cdr list) (+ n-stack 1))))
|
||||||
|
|
||||||
|
|
||||||
|
;; N LIST --> LIST_UP_TO_N
|
||||||
|
(defun up-to (n list &optional (n-stack 0))
|
||||||
|
"Return all items before and including the position N in list"
|
||||||
|
|
||||||
|
(cond
|
||||||
|
((not (car list)) nil)
|
||||||
|
((eq n n-stack) (list (car list)))
|
||||||
|
((concatenate 'list
|
||||||
|
(list (car list))
|
||||||
|
(up-to n (cdr list) (+ n-stack 1))))))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
;; ITEM LIST --> LIST_OF_ITEM_POS
|
||||||
|
(defun positions (item list &key (test #'eq))
|
||||||
|
"Return a list of positions of an item in a list."
|
||||||
|
|
||||||
|
(let ((i 0)
|
||||||
|
(stack '()))
|
||||||
|
(loop
|
||||||
|
:while (< i (length list))
|
||||||
|
:do
|
||||||
|
(if (funcall test (nth i list) item)
|
||||||
|
(setq stack (concatenate 'list stack (list i))))
|
||||||
|
(setq i (+ i 1)))
|
||||||
|
|
||||||
|
stack))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
;; LIST ITEM REPLACEMENT --> LIST_WITH_REPLACEMENTS
|
||||||
|
(defun replace-at (list item replacement &key (test #'eq))
|
||||||
|
"Replace all instances of an item within a list with a replacement."
|
||||||
|
|
||||||
|
(let ((pos-list (positions item list :test test))
|
||||||
|
(stack list)
|
||||||
|
(i 0))
|
||||||
|
(loop
|
||||||
|
:while (< i (length pos-list))
|
||||||
|
:do
|
||||||
|
(setf (nth (nth i pos-list) stack) replacement)
|
||||||
|
(setq i (+ 1 i)))
|
||||||
|
|
||||||
|
stack))
|
|
@ -0,0 +1,66 @@
|
||||||
|
(in-package :nih)
|
||||||
|
|
||||||
|
;; DATA --> LIST_OR_SUBLIST
|
||||||
|
(defun list-or-real (data)
|
||||||
|
"If a piece of data's `car` is a list (I.E., if it's a list of a list)
|
||||||
|
then return the sub-list. If it's not a list, then just return the top-level
|
||||||
|
list.
|
||||||
|
|
||||||
|
This is useful for recursion, so that you can just serve the &rest list to
|
||||||
|
a function, instead of having to itemize the &rest list out to reproduce it."
|
||||||
|
|
||||||
|
(if (and
|
||||||
|
(eq (type-of (ignore-errors (car data))) 'CONS)
|
||||||
|
(eq (length data) 1))
|
||||||
|
(car data)
|
||||||
|
data))
|
||||||
|
|
||||||
|
;; DATA ALT --> DATA_OR_ALT
|
||||||
|
(defun value-or (data alt)
|
||||||
|
"If a piece of data exists, return it. Otherwise, return the alternative.
|
||||||
|
literally just `if`, lol"
|
||||||
|
|
||||||
|
(if data
|
||||||
|
data
|
||||||
|
alt))
|
||||||
|
|
||||||
|
|
||||||
|
;; ARG-LIST &REST KEYS_TO_LOOK_FOR --> LIST_OF_KEY-VALUE_PAIRS
|
||||||
|
(defun parse-keys (arg-list key-list)
|
||||||
|
"Return all searched-for keys fom a list in a list of key-value pairs."
|
||||||
|
|
||||||
|
(let ((stack '())
|
||||||
|
(new-list arg-list))
|
||||||
|
(loop
|
||||||
|
:for key
|
||||||
|
:in key-list
|
||||||
|
:do
|
||||||
|
(if (ignore-errors (position key arg-list))
|
||||||
|
(let* ((key-position (position key arg-list))
|
||||||
|
(value-position (+ 1 key-position))
|
||||||
|
(key-value (nth value-position arg-list)))
|
||||||
|
(setq stack (concatenate 'list stack (list key key-value)))
|
||||||
|
(setq new-list (remove key-value (remove key new-list))))))
|
||||||
|
|
||||||
|
(values stack new-list)))
|
||||||
|
|
||||||
|
|
||||||
|
;; LIST --> RANDOM_ITEM
|
||||||
|
(defun random-item (list)
|
||||||
|
"Return a random item from a list."
|
||||||
|
|
||||||
|
(nth (random (length list)) list))
|
||||||
|
|
||||||
|
|
||||||
|
;; UNIVERSAL-TIME --> ISO8601-FORMAT_TIME
|
||||||
|
(defun iso-time (universal-time)
|
||||||
|
"Return `universal-time` in ISO 8601 format. :)"
|
||||||
|
|
||||||
|
(multiple-value-bind
|
||||||
|
(second minute hour date month year)
|
||||||
|
(decode-universal-time universal-time)
|
||||||
|
|
||||||
|
(format nil "~A-~A-~A"
|
||||||
|
year
|
||||||
|
(min-string-length month 2 "0")
|
||||||
|
(min-string-length date 2 "0"))))
|
|
@ -0,0 +1,121 @@
|
||||||
|
(defpackage :nih
|
||||||
|
(:use :cl)
|
||||||
|
(:export
|
||||||
|
|
||||||
|
;; STRING
|
||||||
|
;; =======================
|
||||||
|
:apply-convert
|
||||||
|
:string-manip
|
||||||
|
:create-string-manip
|
||||||
|
:manip-name
|
||||||
|
|
||||||
|
:string-combine
|
||||||
|
:intern-combine
|
||||||
|
|
||||||
|
:regex-get
|
||||||
|
:regex-get-all
|
||||||
|
:regex-remove
|
||||||
|
:regex-remove-all
|
||||||
|
|
||||||
|
:nil-string
|
||||||
|
|
||||||
|
:pad-string
|
||||||
|
:min-string-length
|
||||||
|
|
||||||
|
:getf-string
|
||||||
|
:getf-strings
|
||||||
|
|
||||||
|
:get-colon-values
|
||||||
|
:remove-colon-values
|
||||||
|
|
||||||
|
|
||||||
|
;; STRING/WORD
|
||||||
|
;; =======================
|
||||||
|
:word-list
|
||||||
|
:word-string
|
||||||
|
:word-nth
|
||||||
|
|
||||||
|
:word-get
|
||||||
|
:word-get-all
|
||||||
|
:word-remove
|
||||||
|
:word-remove-all
|
||||||
|
:word-position
|
||||||
|
:word-positions
|
||||||
|
|
||||||
|
:word-car
|
||||||
|
:word-caar :word-cadddrr :word-cadaar :word-cadr :word-caadr
|
||||||
|
:word-caaadr :word-caaaar :word-caadar :word-caddr :word-caaar
|
||||||
|
:word-cdr
|
||||||
|
:word-cdddar :word-cdar :word-cdaaar :word-cddddr :word-cdddr
|
||||||
|
:word-cdaadr :word-cdadar :word-cddadr :word-cdaddr :word-cdadr
|
||||||
|
:word-cddar :word-cddr :word-cddaar :word-cdaar
|
||||||
|
|
||||||
|
|
||||||
|
;; STRING/LINE
|
||||||
|
;; =======================
|
||||||
|
:line-list
|
||||||
|
:line-string
|
||||||
|
:line-nth
|
||||||
|
|
||||||
|
:line-get
|
||||||
|
:line-get-all
|
||||||
|
:line-remove
|
||||||
|
:line-remove-all
|
||||||
|
:line-position
|
||||||
|
:line-positions
|
||||||
|
|
||||||
|
:line-car
|
||||||
|
:line-caar :line-cadddrr :line-cadaar :line-cadr :line-caadr
|
||||||
|
:line-caaadr :line-caaaar :line-caadar :line-caddr :line-caaar
|
||||||
|
:line-cdr
|
||||||
|
:line-cdddar :line-cdar :line-cdaaar :line-cddddr :line-cdddr
|
||||||
|
:line-cdaadr :line-cdadar :line-cddadr :line-cdaddr :line-cdadr
|
||||||
|
:line-cddar :line-cddr :line-cddaar :line-cdaar
|
||||||
|
|
||||||
|
|
||||||
|
;; STRING/CHAR
|
||||||
|
;; =======================
|
||||||
|
:char-list
|
||||||
|
:char-string
|
||||||
|
:char-nth
|
||||||
|
|
||||||
|
:char-remove
|
||||||
|
:char-remove-all
|
||||||
|
:char-position
|
||||||
|
:char-positions
|
||||||
|
|
||||||
|
:char-car
|
||||||
|
:char-caar :char-cadddrr :char-cadaar :char-cadr :char-caadr
|
||||||
|
:char-caaadr :char-caaaar :char-caadar :char-caddr :char-caaar
|
||||||
|
:char-cdr
|
||||||
|
:char-cdddar :char-cdar :char-cdaaar :char-cddddr :char-cdddr
|
||||||
|
:char-cdaadr :char-cdadar :char-cddadr :char-cdaddr :char-cdadr
|
||||||
|
:char-cddar :char-cddr :char-cddaar :char-cdaar
|
||||||
|
|
||||||
|
|
||||||
|
;; LIST
|
||||||
|
;; =======================
|
||||||
|
:up-to
|
||||||
|
:up-from
|
||||||
|
|
||||||
|
:before
|
||||||
|
:after
|
||||||
|
|
||||||
|
:preceding
|
||||||
|
:following
|
||||||
|
|
||||||
|
:positions
|
||||||
|
|
||||||
|
:replace-at
|
||||||
|
|
||||||
|
|
||||||
|
;; MISC
|
||||||
|
;; =======================
|
||||||
|
:random-item
|
||||||
|
:iso-time
|
||||||
|
:list-or-real
|
||||||
|
:value-or
|
||||||
|
:parse-keys))
|
||||||
|
|
||||||
|
|
||||||
|
(in-package :nih)
|
|
@ -0,0 +1,107 @@
|
||||||
|
(in-package :nih)
|
||||||
|
|
||||||
|
;; CHAR-LIST FUNCTIONS
|
||||||
|
;; =====================================
|
||||||
|
|
||||||
|
;; STRING --> LIST_OF_CHARS
|
||||||
|
(defun char-list (string)
|
||||||
|
"Turn a string into a list of characters."
|
||||||
|
|
||||||
|
(let ((stack '()))
|
||||||
|
(loop
|
||||||
|
:for char
|
||||||
|
:across string
|
||||||
|
:do (setq stack
|
||||||
|
(append stack (list char))))
|
||||||
|
stack))
|
||||||
|
|
||||||
|
|
||||||
|
;; LIST_OF_CHARS --> STRING
|
||||||
|
(defun char-string (char-list)
|
||||||
|
"Convert a list of chars into a string"
|
||||||
|
|
||||||
|
(cond
|
||||||
|
((eq (length char-list) 1)
|
||||||
|
(string (car char-list)))
|
||||||
|
('T
|
||||||
|
(reduce
|
||||||
|
(lambda (char-a char-b)
|
||||||
|
(string-combine (string char-a) (string char-b) :seperator ""))
|
||||||
|
char-list))))
|
||||||
|
|
||||||
|
|
||||||
|
;; STRING --> NTH_CHARACTER
|
||||||
|
(defun char-nth (n string)
|
||||||
|
"Return nth line number from a multi-line string."
|
||||||
|
|
||||||
|
(nth n (char-list string)))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
;; REGEX STRING --> LINES_SANS_MATCHES
|
||||||
|
(defun char-remove (character string)
|
||||||
|
"Remove the first instance of a char from a string."
|
||||||
|
|
||||||
|
(let ((switch 0))
|
||||||
|
(reduce
|
||||||
|
(lambda (char-a char-b)
|
||||||
|
(string-combine
|
||||||
|
(if (and (eq switch 0) (eq character char-a))
|
||||||
|
(progn (setq switch 1) "")
|
||||||
|
char-a)
|
||||||
|
char-b))
|
||||||
|
(char-list string))))
|
||||||
|
|
||||||
|
|
||||||
|
;; REGEX STRING --> LIST_OF_MATCHING_WORDS
|
||||||
|
(defun char-remove-all (character string)
|
||||||
|
"Remove all instances of a char in a string."
|
||||||
|
|
||||||
|
(char-string (remove character (char-list string))))
|
||||||
|
|
||||||
|
|
||||||
|
;; CHARACTER STRING --> 1ST_POS_OF_CHAR_IN_STRING
|
||||||
|
(defun char-position (character string)
|
||||||
|
"Return the first position of a character in a string."
|
||||||
|
|
||||||
|
(position character (char-list string)))
|
||||||
|
|
||||||
|
;; CHARACTER STRING --> LIST_OF_CHAR_POS_IN_STRING
|
||||||
|
(defun char-positions (character string)
|
||||||
|
"Return a list of the positions of a character in a string."
|
||||||
|
|
||||||
|
(positions character (char-list string)))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(create-string-manip char-car #'nih:char-list #'nih:char-string #'car)
|
||||||
|
(create-string-manip char-caar #'nih:char-list #'nih:char-string #'caar)
|
||||||
|
(create-string-manip char-cadddrr #'nih:char-list #'nih:char-string #'cadddrr)
|
||||||
|
(create-string-manip char-cadaar #'nih:char-list #'nih:char-string #'cadaar)
|
||||||
|
(create-string-manip char-cadr #'nih:char-list #'nih:char-string #'cadr)
|
||||||
|
(create-string-manip char-caadr #'nih:char-list #'nih:char-string #'caadr)
|
||||||
|
(create-string-manip char-caaadr #'nih:char-list #'nih:char-string #'caaadr)
|
||||||
|
(create-string-manip char-caaaar #'nih:char-list #'nih:char-string #'caaaar)
|
||||||
|
(create-string-manip char-caadar #'nih:char-list #'nih:char-string #'caadar)
|
||||||
|
(create-string-manip char-caddr #'nih:char-list #'nih:char-string #'caddr)
|
||||||
|
(create-string-manip char-caaar #'nih:char-list #'nih:char-string #'caaar)
|
||||||
|
|
||||||
|
(create-string-manip char-cdr #'nih:char-list #'nih:char-string #'cdr)
|
||||||
|
(create-string-manip char-cdddar #'nih:char-list #'nih:char-string #'cdddar)
|
||||||
|
(create-string-manip char-cdar #'nih:char-list #'nih:char-string #'cdar)
|
||||||
|
(create-string-manip char-cdaaar #'nih:char-list #'nih:char-string #'cdaaar)
|
||||||
|
(create-string-manip char-cddddr #'nih:char-list #'nih:char-string #'cddddr)
|
||||||
|
(create-string-manip char-cdddr #'nih:char-list #'nih:char-string #'cdddr)
|
||||||
|
(create-string-manip char-cdaadr #'nih:char-list #'nih:char-string #'cdaadr)
|
||||||
|
(create-string-manip char-cdadar #'nih:char-list #'nih:char-string #'cdadar)
|
||||||
|
(create-string-manip char-cddadr #'nih:char-list #'nih:char-string #'cddadr)
|
||||||
|
(create-string-manip char-cdaddr #'nih:char-list #'nih:char-string #'cdaddr)
|
||||||
|
(create-string-manip char-cdadr #'nih:char-list #'nih:char-string #'cdadr)
|
||||||
|
(create-string-manip char-cddar #'nih:char-list #'nih:char-string #'cddar)
|
||||||
|
(create-string-manip char-cddr #'nih:char-list #'nih:char-string #'cddr)
|
||||||
|
(create-string-manip char-cddaar #'nih:char-list #'nih:char-string #'cddaar)
|
||||||
|
(create-string-manip char-cdaar #'nih:char-list #'nih:char-string #'cdaar)
|
|
@ -0,0 +1,104 @@
|
||||||
|
(in-package :nih)
|
||||||
|
|
||||||
|
;; LINE-LIST FUNCTIONS
|
||||||
|
;; =====================================
|
||||||
|
|
||||||
|
;; MULTI-LINE_STRING --> LIST_OF_LINES
|
||||||
|
(defun line-list (string)
|
||||||
|
"Return a list of lines from a multi-line string."
|
||||||
|
|
||||||
|
(cl-strings:split string (format nil "~%")))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;; LIST_OF_STRINGS --> MULTI-LINE_STRING
|
||||||
|
(defun line-string (line-list)
|
||||||
|
"Turn a list of lines (string) into a multi-line string."
|
||||||
|
|
||||||
|
(if (not (equal (type-of line-list) 'CONS))
|
||||||
|
line-list
|
||||||
|
(reduce
|
||||||
|
(lambda (line-a line-b)
|
||||||
|
(string-combine :seperator (format nil "~%") line-a line-b))
|
||||||
|
line-list)))
|
||||||
|
|
||||||
|
|
||||||
|
;; NUMBER MULTI-LINE_STRING --> SINGLE-LINE_STRING
|
||||||
|
(defun line-nth (n string)
|
||||||
|
"Return nth line number from a multi-line string."
|
||||||
|
|
||||||
|
(nth n (line-list string)))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
;; REGEX STRING --> MATCHING_WORD
|
||||||
|
(defun line-get (query string)
|
||||||
|
"Return a line in a string that matches a regex query."
|
||||||
|
|
||||||
|
(ignore-errors (line-car (line-get-all query string))))
|
||||||
|
|
||||||
|
;; REGEX STRING --> LIST_OF_MATCHING_WORDS
|
||||||
|
(defun line-get-all (query string)
|
||||||
|
"Return all lines in a string that match a regex query."
|
||||||
|
|
||||||
|
(line-string (regex-get-all query (line-list string))))
|
||||||
|
|
||||||
|
|
||||||
|
;; REGEX STRING --> LINES_SANS_MATCHES
|
||||||
|
(defun line-remove (query string)
|
||||||
|
"Remove a line from a string that matches a regex query."
|
||||||
|
|
||||||
|
(line-string (regex-remove query (line-list string))))
|
||||||
|
|
||||||
|
;; REGEX STRING --> LINES_SANS_MATCHES
|
||||||
|
(defun line-remove-all (query string)
|
||||||
|
"Remove all lines from a string that match a regex query."
|
||||||
|
|
||||||
|
(line-string (regex-remove-all query (line-list string))))
|
||||||
|
|
||||||
|
|
||||||
|
;; LINE STRING --> POS_OF_LINE_IN_STRING
|
||||||
|
(defun line-position (line string)
|
||||||
|
"Return the line-number of a line in a string."
|
||||||
|
|
||||||
|
(position line (line-list string) :test #'equal))
|
||||||
|
|
||||||
|
;; LINE STRING --> LIST_OF_LINE_POS_IN_STRING
|
||||||
|
(defun line-positions (line string)
|
||||||
|
"Return a list of the positions of a line in string."
|
||||||
|
|
||||||
|
(positions line (line-list string) :test #'equal))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(create-string-manip line-car #'nih:line-list #'nih:line-string #'car)
|
||||||
|
(create-string-manip line-caar #'nih:line-list #'nih:line-string #'caar)
|
||||||
|
(create-string-manip line-cadddrr #'nih:line-list #'nih:line-string #'cadddrr)
|
||||||
|
(create-string-manip line-cadaar #'nih:line-list #'nih:line-string #'cadaar)
|
||||||
|
(create-string-manip line-cadr #'nih:line-list #'nih:line-string #'cadr)
|
||||||
|
(create-string-manip line-caadr #'nih:line-list #'nih:line-string #'caadr)
|
||||||
|
(create-string-manip line-caaadr #'nih:line-list #'nih:line-string #'caaadr)
|
||||||
|
(create-string-manip line-caaaar #'nih:line-list #'nih:line-string #'caaaar)
|
||||||
|
(create-string-manip line-caadar #'nih:line-list #'nih:line-string #'caadar)
|
||||||
|
(create-string-manip line-caddr #'nih:line-list #'nih:line-string #'caddr)
|
||||||
|
(create-string-manip line-caaar #'nih:line-list #'nih:line-string #'caaar)
|
||||||
|
|
||||||
|
(create-string-manip line-cdr #'nih:line-list #'nih:line-string #'cdr)
|
||||||
|
(create-string-manip line-cdddar #'nih:line-list #'nih:line-string #'cdddar)
|
||||||
|
(create-string-manip line-cdar #'nih:line-list #'nih:line-string #'cdar)
|
||||||
|
(create-string-manip line-cdaaar #'nih:line-list #'nih:line-string #'cdaaar)
|
||||||
|
(create-string-manip line-cddddr #'nih:line-list #'nih:line-string #'cddddr)
|
||||||
|
(create-string-manip line-cdddr #'nih:line-list #'nih:line-string #'cdddr)
|
||||||
|
(create-string-manip line-cdaadr #'nih:line-list #'nih:line-string #'cdaadr)
|
||||||
|
(create-string-manip line-cdadar #'nih:line-list #'nih:line-string #'cdadar)
|
||||||
|
(create-string-manip line-cddadr #'nih:line-list #'nih:line-string #'cddadr)
|
||||||
|
(create-string-manip line-cdaddr #'nih:line-list #'nih:line-string #'cdaddr)
|
||||||
|
(create-string-manip line-cdadr #'nih:line-list #'nih:line-string #'cdadr)
|
||||||
|
(create-string-manip line-cddar #'nih:line-list #'nih:line-string #'cddar)
|
||||||
|
(create-string-manip line-cddr #'nih:line-list #'nih:line-string #'cddr)
|
||||||
|
(create-string-manip line-cddaar #'nih:line-list #'nih:line-string #'cddaar)
|
||||||
|
(create-string-manip line-cdaar #'nih:line-list #'nih:line-string #'cdaar)
|
|
@ -0,0 +1,270 @@
|
||||||
|
(in-package :nih)
|
||||||
|
|
||||||
|
|
||||||
|
;; FUNCTION-NAME #'TO-LIST #'TO-STRING #'MANIPULATION
|
||||||
|
(defmacro create-string-manip (manip-name list-function string-function manip)
|
||||||
|
"Define a function to perform a manipulation (#'manip, i.e. #'car) on the
|
||||||
|
list-form of a particular string (converting to list with #'list-function),
|
||||||
|
then converting back into a string (#'string-function) again
|
||||||
|
(but with the manipulations made)."
|
||||||
|
|
||||||
|
`(defun ,manip-name (string)
|
||||||
|
(funcall ,string-function
|
||||||
|
(funcall ,manip
|
||||||
|
(funcall ,list-function string)))))
|
||||||
|
|
||||||
|
|
||||||
|
;; ========================================
|
||||||
|
|
||||||
|
|
||||||
|
;; STRINGS :SEPERATOR --> STRINGS_COMBINED_W_SEPERATOR
|
||||||
|
(defun string-combine (&rest arg-list)
|
||||||
|
"Combine strings into a single string, marked with a seperator.
|
||||||
|
:seperator is parsed manually, since mixing &rest and &key makes
|
||||||
|
me want to eat my fucking hat. >;c"
|
||||||
|
|
||||||
|
(multiple-value-bind (keys strings)
|
||||||
|
(parse-keys arg-list '(:seperator))
|
||||||
|
|
||||||
|
(let ((seperator (value-or (getf keys :seperator) "")))
|
||||||
|
|
||||||
|
(reduce (lambda (word1 word2)
|
||||||
|
(format nil "~A~A~A" word1 seperator word2))
|
||||||
|
strings))))
|
||||||
|
|
||||||
|
|
||||||
|
;; STRING_A STRING_B --> SYMBOL_OF_STRING_A+STRING_B
|
||||||
|
(defun intern-combine (&rest arg-list)
|
||||||
|
"Combine two strings into a symbol, marked with a seperator.
|
||||||
|
:seperator and :package are parsed manually, since mixing &rest
|
||||||
|
and &key is utterly painful! ;_:"
|
||||||
|
|
||||||
|
(multiple-value-bind (keys strings)
|
||||||
|
(parse-keys arg-list '(:seperator :package))
|
||||||
|
|
||||||
|
(let* ((seperator (value-or (getf keys :seperator) ""))
|
||||||
|
(package (value-or (getf keys :package) nil))
|
||||||
|
(combined (string-upcase
|
||||||
|
(reduce (lambda (str1 str2)
|
||||||
|
(string-combine str1 str2
|
||||||
|
:seperator seperator))
|
||||||
|
strings))))
|
||||||
|
|
||||||
|
(if package
|
||||||
|
(intern combined (string-upcase package))
|
||||||
|
(intern combined)))))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
;; LIST --> LIST_SANS_NIL_WITH_""
|
||||||
|
(defun nil-string (list)
|
||||||
|
"Replace all instances of nil in a list with a blank string."
|
||||||
|
|
||||||
|
(replace-at list nil ""))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
;; STRING PREFIX SUFFIX --> STRING_ONE_OR_TWO_CHARS_LARGER
|
||||||
|
(defun pad-string (string &key prefix suffix)
|
||||||
|
"Increase the character-count of a string by 1; either by
|
||||||
|
adding a prefix-substitutor or a suffix-substitutor.
|
||||||
|
If both a :prefix and a :suffix are provided, :suffix is
|
||||||
|
ignored."
|
||||||
|
|
||||||
|
(flet ((padding (prefix string suffix)
|
||||||
|
(format nil "~A~A~A" prefix string suffix)))
|
||||||
|
|
||||||
|
(cond
|
||||||
|
((and prefix suffix)
|
||||||
|
(padding prefix string ""))
|
||||||
|
(prefix
|
||||||
|
(padding prefix string ""))
|
||||||
|
(suffix
|
||||||
|
(padding "" string suffix)))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;; STRING DESIRED_LENGTH [PREFIX] [SUFFIX] --> STRING_OF_DESIRED_LENGTH
|
||||||
|
(defun min-string-length (string target-length
|
||||||
|
&key (prefix "") (suffix ""))
|
||||||
|
"If a string *must* be a certain length (formatting reasons), use
|
||||||
|
this function.
|
||||||
|
|
||||||
|
Returns a string of `length`, using the `prefix-substitutor` or
|
||||||
|
`suffix-substitutor` to beef up the character-count if it's too short.
|
||||||
|
|
||||||
|
If both `prefix` and `suffix` are defined, `prefix` is used.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
(min-string-length \"9\" 3 \"0\")
|
||||||
|
|
||||||
|
\"009\""
|
||||||
|
|
||||||
|
(let* ((string (format nil "~A" string))
|
||||||
|
(cur-length (length string)))
|
||||||
|
|
||||||
|
(if (eq cur-length target-length)
|
||||||
|
string
|
||||||
|
|
||||||
|
(min-string-length
|
||||||
|
(if (eq (length suffix) 0)
|
||||||
|
(pad-string string :prefix prefix)
|
||||||
|
(pad-string string :suffix suffix))
|
||||||
|
target-length
|
||||||
|
:prefix prefix
|
||||||
|
:suffix suffix))))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
;; REGEX STRING --> MATCHING_WORD
|
||||||
|
(defun regex-get (query strings)
|
||||||
|
"Return a string in a list that matches a regex query."
|
||||||
|
|
||||||
|
(car (regex-get-all query strings)))
|
||||||
|
|
||||||
|
|
||||||
|
;; REGEX STRING --> LIST_OF_MATCHING_WORDS
|
||||||
|
(defun regex-get-all (query strings)
|
||||||
|
"Return all strings in a list that match a regex query."
|
||||||
|
|
||||||
|
(let ((stack '())
|
||||||
|
(i 0))
|
||||||
|
|
||||||
|
(loop
|
||||||
|
:while (< i (length strings))
|
||||||
|
:do
|
||||||
|
(if (cl-ppcre:scan-to-strings query (nth i strings))
|
||||||
|
(setq stack (concatenate 'list stack (list (nth i strings)))))
|
||||||
|
|
||||||
|
(setq i (+ 1 i)))
|
||||||
|
|
||||||
|
stack))
|
||||||
|
|
||||||
|
|
||||||
|
;; REGEX STRING --> ALL_BUT_MATCHES
|
||||||
|
(defun regex-remove (query strings)
|
||||||
|
"Return a list of strings without a matches to a regex query."
|
||||||
|
|
||||||
|
(let ((stack '())
|
||||||
|
(switch 0)
|
||||||
|
(i 0))
|
||||||
|
|
||||||
|
(loop
|
||||||
|
:while (< i (length strings))
|
||||||
|
:do
|
||||||
|
(cond
|
||||||
|
((eq switch 1)
|
||||||
|
(setq stack (concatenate 'list stack (list (nth i strings)))))
|
||||||
|
((cl-ppcre:scan-to-strings query (nth i strings))
|
||||||
|
(setq switch 1))
|
||||||
|
('T
|
||||||
|
(setq stack (concatenate 'list stack (list (nth i strings))))))
|
||||||
|
|
||||||
|
(setq i (+ 1 i)))
|
||||||
|
|
||||||
|
stack))
|
||||||
|
|
||||||
|
;; REGEX STRING --> ALL_BUT_MATCHES
|
||||||
|
(defun regex-remove-all (query strings)
|
||||||
|
"Return a list of strings without any matches to a regex query."
|
||||||
|
|
||||||
|
(let ((stack '())
|
||||||
|
(i 0))
|
||||||
|
|
||||||
|
(loop
|
||||||
|
:while (< i (length strings))
|
||||||
|
:do
|
||||||
|
(if (not (cl-ppcre:scan-to-strings query (nth i strings)))
|
||||||
|
(setq stack (concatenate 'list stack (list (nth i strings)))))
|
||||||
|
|
||||||
|
(setq i (+ 1 i)))
|
||||||
|
|
||||||
|
stack))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
;; LIST_OF_SUBLISTS STRING --> SUBLIST_WITH_STRING_AS_CAR
|
||||||
|
(defun getf-string (list string)
|
||||||
|
"Get an item from a list by an identifying string in `car`.
|
||||||
|
I.E., if the string is 'apple', the first sublist like this:
|
||||||
|
('apple' 1 2 3)
|
||||||
|
will be returned."
|
||||||
|
|
||||||
|
(car (getf-strings list string)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;; LIST_OF_SUBLISTS STRING --> LIST_OF_SUBLISTS_WITH_STRING_AS_CAR
|
||||||
|
(defun getf-strings (list string &optional (stack '()))
|
||||||
|
"Get items from list by an identifying string in `car`.
|
||||||
|
I.E., if the string is 'apple', any sublists like this:
|
||||||
|
('apple' 1 2 3)
|
||||||
|
will be returned."
|
||||||
|
|
||||||
|
;; just recurse through the list, adding each new matching
|
||||||
|
;; item to the `stack`
|
||||||
|
|
||||||
|
(if (and (< 0 (length list)) (listp list))
|
||||||
|
(if (ignore-errors
|
||||||
|
;; the item might not be a list; for our purposes, let's ignore that.
|
||||||
|
(equal
|
||||||
|
(car (car list)) ;; '( ( here ) )
|
||||||
|
string))
|
||||||
|
(getf-strings (cdr list) string (concatenate 'list stack (list (car list))))
|
||||||
|
(getf-strings (cdr list) string stack))
|
||||||
|
stack))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
;; STRING COLON_VARIABLE_NAME --> COLON_VALUE
|
||||||
|
(defun get-colon-values (string)
|
||||||
|
"Return a the value of a `colon variable`; I.E.,
|
||||||
|
a line of a string starting with `:` followed by a variable
|
||||||
|
name, a space, then the value of said `colon variable`.
|
||||||
|
|
||||||
|
Here's an example:
|
||||||
|
(setq *example-string*
|
||||||
|
\"Blah blah blah
|
||||||
|
:Date 1999
|
||||||
|
Blah blah blah\")
|
||||||
|
|
||||||
|
If you ran
|
||||||
|
(get-colon-values *example-string*)
|
||||||
|
|
||||||
|
you would get
|
||||||
|
(:DATE \"1999\") in return.
|
||||||
|
|
||||||
|
Mainly useful for multi-line strings, but your use-case might
|
||||||
|
involve a `colon variable` in a single-lined string."
|
||||||
|
|
||||||
|
(if (line-get-all "^:" string)
|
||||||
|
(let* ((colon-lines (line-get-all "^:.* " string))
|
||||||
|
(colon-list (line-list colon-lines))
|
||||||
|
(cur-line (line-car colon-lines))
|
||||||
|
(variable (word-car cur-line))
|
||||||
|
(value (word-cdr cur-line)))
|
||||||
|
|
||||||
|
(cond
|
||||||
|
((eq 1 (length colon-list))
|
||||||
|
(list (read-from-string variable) value))
|
||||||
|
('T
|
||||||
|
(concatenate 'list (list (read-from-string variable) value)
|
||||||
|
(get-colon-values (line-cdr colon-lines))))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;; STRING COLON_VARIABLE_NAME --> STRING_WITHOUT_COLON_VARIABLE
|
||||||
|
(defun remove-colon-values (string)
|
||||||
|
"Remove the colon-variable declaration from a string."
|
||||||
|
|
||||||
|
(line-remove-all "^:.*" string))
|
|
@ -0,0 +1,104 @@
|
||||||
|
(in-package :nih)
|
||||||
|
|
||||||
|
;; WORD-LIST FUNCTIONS
|
||||||
|
;; =====================================
|
||||||
|
|
||||||
|
;; STRING --> LIST_OF_WORDS
|
||||||
|
(defun word-list (string)
|
||||||
|
"Turn a string into a list of words."
|
||||||
|
|
||||||
|
(cl-strings:split string " "))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;; LIST_OF_WORDS --> STRING
|
||||||
|
(defun word-string (word-list)
|
||||||
|
"Convert a list of words into a string"
|
||||||
|
|
||||||
|
(if (not (equal (type-of word-list) 'CONS))
|
||||||
|
word-list
|
||||||
|
(reduce
|
||||||
|
(lambda (word-a word-b)
|
||||||
|
(string-combine :seperator " " word-a word-b))
|
||||||
|
word-list)))
|
||||||
|
|
||||||
|
|
||||||
|
;; STRING --> NTH_WORD_FROM_STRING
|
||||||
|
(defun word-nth (n string)
|
||||||
|
"Get nth word from a string."
|
||||||
|
|
||||||
|
(word-string (nth n (word-list string))))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
;; REGEX STRING --> MATCHING_WORD
|
||||||
|
(defun word-get (query string)
|
||||||
|
"Return a word in a string that matches a regex query."
|
||||||
|
|
||||||
|
(word-car (word-get-all query string)))
|
||||||
|
|
||||||
|
;; REGEX STRING --> LIST_OF_MATCHING_WORDS
|
||||||
|
(defun word-get-all (query string)
|
||||||
|
"Return all words in a string that match a regex query."
|
||||||
|
|
||||||
|
(word-string (regex-get-all query (word-list string))))
|
||||||
|
|
||||||
|
|
||||||
|
;; REGEX STRING --> LINES_SANS_MATCHES
|
||||||
|
(defun word-remove (query string)
|
||||||
|
"Remove a word from a string that matches a regex query."
|
||||||
|
|
||||||
|
(word-string (regex-remove query (word-list string))))
|
||||||
|
|
||||||
|
;; REGEX STRING --> LINES_SANS_MATCHES
|
||||||
|
(defun word-remove-all (query string)
|
||||||
|
"Remove all words from a string that match a regex query."
|
||||||
|
|
||||||
|
(word-string (regex-remove-all query (word-list string))))
|
||||||
|
|
||||||
|
|
||||||
|
;; WORD STRING --> WORD_POS_IN_STRING
|
||||||
|
(defun word-position (word string)
|
||||||
|
"Return the position of a word (relative to other words) in a string."
|
||||||
|
|
||||||
|
(position word (word-list string) :test #'equal))
|
||||||
|
|
||||||
|
;; WORD STRING --> LIST_OF_WORD_POS_IN_STRING
|
||||||
|
(defun word-positions (word string)
|
||||||
|
"Return a list of positions of a word (relative to other words) in a string."
|
||||||
|
|
||||||
|
(positions word (word-list string) :test #'equal))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(create-string-manip word-car #'nih:word-list #'nih:word-string #'car)
|
||||||
|
(create-string-manip word-caar #'nih:word-list #'nih:word-string #'caar)
|
||||||
|
(create-string-manip word-cadddrr #'nih:word-list #'nih:word-string #'cadddrr)
|
||||||
|
(create-string-manip word-cadaar #'nih:word-list #'nih:word-string #'cadaar)
|
||||||
|
(create-string-manip word-cadr #'nih:word-list #'nih:word-string #'cadr)
|
||||||
|
(create-string-manip word-caadr #'nih:word-list #'nih:word-string #'caadr)
|
||||||
|
(create-string-manip word-caaadr #'nih:word-list #'nih:word-string #'caaadr)
|
||||||
|
(create-string-manip word-caaaar #'nih:word-list #'nih:word-string #'caaaar)
|
||||||
|
(create-string-manip word-caadar #'nih:word-list #'nih:word-string #'caadar)
|
||||||
|
(create-string-manip word-caddr #'nih:word-list #'nih:word-string #'caddr)
|
||||||
|
(create-string-manip word-caaar #'nih:word-list #'nih:word-string #'caaar)
|
||||||
|
|
||||||
|
(create-string-manip word-cdr #'nih:word-list #'nih:word-string #'cdr)
|
||||||
|
(create-string-manip word-cdddar #'nih:word-list #'nih:word-string #'cdddar)
|
||||||
|
(create-string-manip word-cdar #'nih:word-list #'nih:word-string #'cdar)
|
||||||
|
(create-string-manip word-cdaaar #'nih:word-list #'nih:word-string #'cdaaar)
|
||||||
|
(create-string-manip word-cddddr #'nih:word-list #'nih:word-string #'cddddr)
|
||||||
|
(create-string-manip word-cdddr #'nih:word-list #'nih:word-string #'cdddr)
|
||||||
|
(create-string-manip word-cdaadr #'nih:word-list #'nih:word-string #'cdaadr)
|
||||||
|
(create-string-manip word-cdadar #'nih:word-list #'nih:word-string #'cdadar)
|
||||||
|
(create-string-manip word-cddadr #'nih:word-list #'nih:word-string #'cddadr)
|
||||||
|
(create-string-manip word-cdaddr #'nih:word-list #'nih:word-string #'cdaddr)
|
||||||
|
(create-string-manip word-cdadr #'nih:word-list #'nih:word-string #'cdadr)
|
||||||
|
(create-string-manip word-cddar #'nih:word-list #'nih:word-string #'cddar)
|
||||||
|
(create-string-manip word-cddr #'nih:word-list #'nih:word-string #'cddr)
|
||||||
|
(create-string-manip word-cddaar #'nih:word-list #'nih:word-string #'cddaar)
|
||||||
|
(create-string-manip word-cdaar #'nih:word-list #'nih:word-string #'cdaar)
|
|
@ -0,0 +1,12 @@
|
||||||
|
================================================================================
|
||||||
|
TESTING FOR :NIH
|
||||||
|
================================================================================
|
||||||
|
|
||||||
|
To test :nih functions, just change directories into the root of the
|
||||||
|
repository; then, load `t.lisp` from there, like so:
|
||||||
|
|
||||||
|
[0]> (load "t/t.lisp")
|
||||||
|
|
||||||
|
Then, you can run the tests as you please:
|
||||||
|
|
||||||
|
[1]> (nih-testing:do-all)
|
|
@ -0,0 +1,106 @@
|
||||||
|
;; ----------------------------------------
|
||||||
|
;; STRING.LISP
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
;; DATA DECLARATIONS
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
(defvar *number-list* '(98 37 23 24 14 14 24 52 5325 32 4234))
|
||||||
|
|
||||||
|
(defvar *one-number-list* '(1))
|
||||||
|
|
||||||
|
|
||||||
|
;; TESTS
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
(rt:deftest up-to-i
|
||||||
|
(nih:up-to 2 *number-list*)
|
||||||
|
(98 37 23))
|
||||||
|
|
||||||
|
(rt:deftest up-to-ii
|
||||||
|
(nih:up-to 0 *one-number-list*)
|
||||||
|
(1))
|
||||||
|
|
||||||
|
(rt:deftest up-to-iii
|
||||||
|
(nih:up-to 3 *one-number-list*)
|
||||||
|
(1))
|
||||||
|
|
||||||
|
(rt:deftest up-to-iv
|
||||||
|
(nih:up-to 13 *number-list*)
|
||||||
|
(98 37 23 24 14 14 24 52 5325 32 4234))
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest up-from-i
|
||||||
|
(nih:up-from 2 *number-list*)
|
||||||
|
(23 24 14 14 24 52 5325 32 4234))
|
||||||
|
|
||||||
|
(rt:deftest up-from-ii
|
||||||
|
(nih:up-from 10 *number-list*)
|
||||||
|
(4234))
|
||||||
|
|
||||||
|
(rt:deftest up-from-iii
|
||||||
|
(nih:up-from 11 *number-list*)
|
||||||
|
nil)
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest before-i
|
||||||
|
(nih:before 37 *number-list*)
|
||||||
|
98)
|
||||||
|
|
||||||
|
(rt:deftest before-ii
|
||||||
|
(nih:before 98 *number-list*)
|
||||||
|
nil)
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest after-i
|
||||||
|
(nih:after 37 *number-list*)
|
||||||
|
23)
|
||||||
|
|
||||||
|
(rt:deftest after-ii
|
||||||
|
(nih:after 4234 *number-list*)
|
||||||
|
nil)
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest following-i
|
||||||
|
(nih:following 37 *number-list*)
|
||||||
|
(23 24 14 14 24 52 5325 32 4234))
|
||||||
|
|
||||||
|
(rt:deftest following-ii
|
||||||
|
(nih:following 4234 *number-list*)
|
||||||
|
nil)
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest preceding-i
|
||||||
|
(nih:preceding 23 *number-list*)
|
||||||
|
(98 37))
|
||||||
|
|
||||||
|
(rt:deftest preceding-ii
|
||||||
|
(nih:preceding 98 *number-list*)
|
||||||
|
nil)
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest positions
|
||||||
|
(nih:positions 14 *number-list*)
|
||||||
|
(4 5))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest replace-at-i
|
||||||
|
(nih:replace-at '(1 2 3 1 4) 1 0)
|
||||||
|
(0 2 3 0 4))
|
||||||
|
|
||||||
|
(rt:deftest replace-at-ii
|
||||||
|
(nih:replace-at '("yo" "hi" "hi" "ya") "hi" "ye" :test #'equal)
|
||||||
|
("yo" "ye" "ye" "ya"))
|
|
@ -0,0 +1,60 @@
|
||||||
|
;; ----------------------------------------
|
||||||
|
;; STRING.LISP
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
;; DATA DECLARATIONS
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
(defvar *list-in-list* '((1 2 3 4)))
|
||||||
|
|
||||||
|
(defvar *keyed-list* '(1 2 :morto "hi" 3 :ploro 4))
|
||||||
|
|
||||||
|
|
||||||
|
;; TESTS
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest parse-keys-i
|
||||||
|
(nih:parse-keys *keyed-list* '(:morto))
|
||||||
|
(:morto "hi")
|
||||||
|
(1 2 3 :ploro 4))
|
||||||
|
|
||||||
|
(rt:deftest parse-keys-ii
|
||||||
|
(nih:parse-keys *keyed-list* '(:ploro))
|
||||||
|
(:ploro 4)
|
||||||
|
(1 2 :morto "hi" 3))
|
||||||
|
|
||||||
|
(rt:deftest parse-keys-iii
|
||||||
|
(nih:parse-keys *keyed-list* '(:ploro :morto))
|
||||||
|
(:ploro 4 :morto "hi")
|
||||||
|
(1 2 3))
|
||||||
|
|
||||||
|
(rt:deftest parse-keys-iv
|
||||||
|
(nih:parse-keys *list-in-list* '(:ploro :morto))
|
||||||
|
nil
|
||||||
|
((1 2 3 4)))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest value-or-i
|
||||||
|
(nih:value-or nil "")
|
||||||
|
"")
|
||||||
|
|
||||||
|
(rt:deftest value-or-ii
|
||||||
|
(nih:value-or 2 "")
|
||||||
|
2)
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest list-or-real-i
|
||||||
|
(nih:list-or-real *list-in-list*)
|
||||||
|
(1 2 3 4))
|
||||||
|
|
||||||
|
(rt:deftest list-or-real-ii
|
||||||
|
(nih:list-or-real *keyed-list*)
|
||||||
|
(1 2 :morto "hi" 3 :ploro 4))
|
|
@ -0,0 +1,80 @@
|
||||||
|
;; ----------------------------------------
|
||||||
|
;; WORD.LISP
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
;; DATA DECLARATIONS
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
(defvar *three-words*
|
||||||
|
"Hiya! <3<3<3 daddyyyyy")
|
||||||
|
|
||||||
|
(defvar *three-words-char-list*
|
||||||
|
'(#\H #\i #\y #\a #\!
|
||||||
|
#\Space #\< #\3 #\< #\3 #\< #\3
|
||||||
|
#\Space #\d #\a #\d #\d #\y #\y #\y #\y #\y))
|
||||||
|
|
||||||
|
(defvar *char-repeat*
|
||||||
|
"I like to eat like to eat like to eat babies")
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest char-list
|
||||||
|
(nih:char-list *three-words*)
|
||||||
|
(#\H #\i #\y #\a #\!
|
||||||
|
#\Space #\< #\3 #\< #\3 #\< #\3
|
||||||
|
#\Space #\d #\a #\d #\d #\y #\y #\y #\y #\y))
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest char-string
|
||||||
|
(nih:char-string *three-words-char-list*)
|
||||||
|
"Hiya! <3<3<3 daddyyyyy")
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest char-nth-i
|
||||||
|
(nih:char-nth 0 *three-words*)
|
||||||
|
#\H)
|
||||||
|
|
||||||
|
(rt:deftest char-nth-ii
|
||||||
|
(nih:char-nth 2 *three-words*)
|
||||||
|
#\y)
|
||||||
|
|
||||||
|
(rt:deftest char-nth-iii
|
||||||
|
(nih:char-nth 21 *three-words*)
|
||||||
|
#\y)
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest char-remove-i
|
||||||
|
(nih:char-remove #\h "hi there :)")
|
||||||
|
"i there :)")
|
||||||
|
|
||||||
|
(rt:deftest char-remove-ii
|
||||||
|
(nih:char-remove #\h "hi")
|
||||||
|
"i")
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest char-remove-all
|
||||||
|
(nih:char-remove-all #\h "hi there :)")
|
||||||
|
"i tere :)")
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest char-position-i
|
||||||
|
(nih:char-position #\H *three-words*)
|
||||||
|
0)
|
||||||
|
|
||||||
|
(rt:deftest char-position-ii
|
||||||
|
(nih:char-position #\y *three-words*)
|
||||||
|
2)
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest char-positions
|
||||||
|
(nih:char-positions #\y *three-words*)
|
||||||
|
(2 17 18 19 20 21))
|
|
@ -0,0 +1,105 @@
|
||||||
|
;; ----------------------------------------
|
||||||
|
;; LINE.LISP
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
;; DATA DECLARATIONS
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
(defvar *single-line-string*
|
||||||
|
"Hiya! <3<3<3 daddyyyyy")
|
||||||
|
|
||||||
|
(defvar *single-line-list*
|
||||||
|
'("Hiya! <3<3<3 daddyyyyy"))
|
||||||
|
|
||||||
|
(defvar *multi-line-string*
|
||||||
|
"I like to eat
|
||||||
|
like to eat
|
||||||
|
like to eat
|
||||||
|
babies")
|
||||||
|
|
||||||
|
(defvar *multi-line-list*
|
||||||
|
'("I like to eat"
|
||||||
|
"like to eat"
|
||||||
|
"like to eat"
|
||||||
|
"babies"))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest line-list-i
|
||||||
|
(nih:line-list *multi-line-string*)
|
||||||
|
("I like to eat" "like to eat" "like to eat" "babies"))
|
||||||
|
|
||||||
|
(rt:deftest line-list-ii
|
||||||
|
(nih:line-list *single-line-string*)
|
||||||
|
("Hiya! <3<3<3 daddyyyyy"))
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest line-string-i
|
||||||
|
(nih:line-string *multi-line-list*)
|
||||||
|
"I like to eat
|
||||||
|
like to eat
|
||||||
|
like to eat
|
||||||
|
babies")
|
||||||
|
|
||||||
|
(rt:deftest line-string-ii
|
||||||
|
(nih:line-string *single-line-list*)
|
||||||
|
"Hiya! <3<3<3 daddyyyyy")
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest line-nth-i
|
||||||
|
(nih:line-nth 2 *multi-line-string*)
|
||||||
|
"like to eat")
|
||||||
|
|
||||||
|
(rt:deftest line-nth-ii
|
||||||
|
(nih:line-nth 0 *multi-line-string*)
|
||||||
|
"I like to eat")
|
||||||
|
|
||||||
|
(rt:deftest line-nth-iii
|
||||||
|
(nih:line-nth 3 *multi-line-string*)
|
||||||
|
"babies")
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest line-get
|
||||||
|
(nih:line-get "eat" *multi-line-string*)
|
||||||
|
"I like to eat")
|
||||||
|
|
||||||
|
(rt:deftest line-get-all
|
||||||
|
(nih:line-get-all ".*eat.*" *multi-line-string*)
|
||||||
|
"I like to eat
|
||||||
|
like to eat
|
||||||
|
like to eat")
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest line-remove
|
||||||
|
(nih:line-remove "eat" *multi-line-string*)
|
||||||
|
"like to eat
|
||||||
|
like to eat
|
||||||
|
babies")
|
||||||
|
|
||||||
|
(rt:deftest line-remove-all
|
||||||
|
(nih:line-remove-all "eat" *multi-line-string*)
|
||||||
|
"babies")
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest line-position-i
|
||||||
|
(nih:line-position "I like to eat" *multi-line-string*)
|
||||||
|
0)
|
||||||
|
|
||||||
|
(rt:deftest line-position-ii
|
||||||
|
(nih:line-position "like to eat" *multi-line-string*)
|
||||||
|
1)
|
||||||
|
|
||||||
|
(rt:deftest line-position-iii
|
||||||
|
(nih:line-position "babies" *multi-line-string*)
|
||||||
|
3)
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest line-positions
|
||||||
|
(nih:line-positions "like to eat" *multi-line-string*)
|
||||||
|
(1 2))
|
|
@ -0,0 +1,188 @@
|
||||||
|
;; ----------------------------------------
|
||||||
|
;; STRING.LISP
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
;; DATA DECLARATIONS
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
(defvar *a-string*
|
||||||
|
"Hiya! <3<3<3")
|
||||||
|
|
||||||
|
(defvar *multiple-lines*
|
||||||
|
"Oh, hi, how're you doing?
|
||||||
|
I hope you responded 'fine'.
|
||||||
|
Honestly, I can't hear you from here,
|
||||||
|
Hopefully your day is OK, though. <3")
|
||||||
|
|
||||||
|
(defvar *multiple-lines-list*
|
||||||
|
'("Oh, hi, how're you doing?"
|
||||||
|
"I hope you responded 'fine'."
|
||||||
|
"Honestly, I can't hear you from here,"
|
||||||
|
"Hopefully your day is OK, though. <3"))
|
||||||
|
|
||||||
|
(defvar *single-multiple-lines-list*
|
||||||
|
'("Hiya! <3<3<3"))
|
||||||
|
|
||||||
|
(defvar *number-string*
|
||||||
|
"9")
|
||||||
|
|
||||||
|
(defvar *getf-strings-list*
|
||||||
|
'(("one" 1)("two" 2)("three" 3)("four" iv)("four" 4)))
|
||||||
|
|
||||||
|
(defvar *colon-valued-string*
|
||||||
|
":Date 1999-01-23
|
||||||
|
This is a QOTD-format colon-value thing!
|
||||||
|
:Programme QOTDD
|
||||||
|
From QOTDD, of course =w=
|
||||||
|
:Spice tasty")
|
||||||
|
|
||||||
|
(defvar *misc-strings-list*
|
||||||
|
'("hi" "hiya" "fhi" "die" "love"))
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest string-combine-i
|
||||||
|
(nih:string-combine "hi")
|
||||||
|
"hi")
|
||||||
|
|
||||||
|
(rt:deftest string-combine-ii
|
||||||
|
(nih:string-combine "hi" "dad" :seperator " ")
|
||||||
|
"hi dad")
|
||||||
|
|
||||||
|
(rt:deftest string-combine-iii
|
||||||
|
(nih:string-combine "the" "lad" "which" "never" :seperator "-")
|
||||||
|
"the-lad-which-never")
|
||||||
|
|
||||||
|
(rt:deftest string-combine-iv
|
||||||
|
(nih:string-combine "she" "who" "never" :seperator "^" "lied")
|
||||||
|
"she^who^never^lied")
|
||||||
|
|
||||||
|
(rt:deftest string-combine-v
|
||||||
|
(nih:string-combine "hi" "dad")
|
||||||
|
"hidad")
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest intern-combine-i
|
||||||
|
(nih:intern-combine "hi")
|
||||||
|
hi :internal)
|
||||||
|
|
||||||
|
(rt:deftest intern-combine-ii
|
||||||
|
(nih:intern-combine "hi" "dad" :seperator " ")
|
||||||
|
|HI DAD| :internal)
|
||||||
|
|
||||||
|
(rt:deftest intern-combine-iii
|
||||||
|
(nih:intern-combine :package "nih" "the" "lad" "which"
|
||||||
|
"never" :seperator "-")
|
||||||
|
NIH::the-lad-which-never :internal)
|
||||||
|
;; notice that keys are interspersed with strings
|
||||||
|
|
||||||
|
(rt:deftest intern-combine-iv
|
||||||
|
(nih:intern-combine "she" "who" "never" :seperator "^" "lied")
|
||||||
|
she^who^never^lied :internal)
|
||||||
|
|
||||||
|
(rt:deftest intern-combine-v
|
||||||
|
(nih:intern-combine "hi" "dad")
|
||||||
|
hidad :internal)
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest pad-string-i
|
||||||
|
(nih:pad-string *a-string* :prefix "a")
|
||||||
|
"aHiya! <3<3<3")
|
||||||
|
|
||||||
|
(rt:deftest pad-string-ii
|
||||||
|
(nih:pad-string *a-string* :prefix "a" :suffix "b")
|
||||||
|
"aHiya! <3<3<3") ;; notice how the :suffix is ignored!
|
||||||
|
|
||||||
|
(rt:deftest pad-string-iii
|
||||||
|
(nih:pad-string *a-string* :suffix "b")
|
||||||
|
"Hiya! <3<3<3b")
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest min-string-length-i
|
||||||
|
(nih:min-string-length *number-string* 3 :prefix "0")
|
||||||
|
"009")
|
||||||
|
|
||||||
|
(rt:deftest min-string-length-ii
|
||||||
|
(nih:min-string-length *number-string* 9 :prefix "9")
|
||||||
|
"999999999")
|
||||||
|
|
||||||
|
(rt:deftest min-string-length-iii
|
||||||
|
(nih:min-string-length "bonege" 10 :suffix "e")
|
||||||
|
"bonegeeeee")
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest regex-get
|
||||||
|
(nih:regex-get ".*hi.*" *misc-strings-list*)
|
||||||
|
"hi")
|
||||||
|
|
||||||
|
(rt:deftest regex-get-all
|
||||||
|
(nih:regex-get-all ".*hi.*" *misc-strings-list*)
|
||||||
|
("hi" "hiya" "fhi"))
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest regex-remove
|
||||||
|
(nih:regex-remove ".*hi.*" *misc-strings-list*)
|
||||||
|
("hiya" "fhi" "die" "love"))
|
||||||
|
|
||||||
|
(rt:deftest regex-remove-all
|
||||||
|
(nih:regex-remove-all ".*hi.*" *misc-strings-list*)
|
||||||
|
("die" "love"))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest nil-string
|
||||||
|
(nih:nil-string '(1 2 3 nil "hi" nil 3))
|
||||||
|
(1 2 3 "" "hi" "" 3))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest getf-strings-i
|
||||||
|
(nih:getf-strings *getf-strings-list* "one")
|
||||||
|
(("one" 1)))
|
||||||
|
|
||||||
|
(rt:deftest getf-strings-ii
|
||||||
|
(nih:getf-strings *getf-strings-list* "two")
|
||||||
|
(("two" 2)))
|
||||||
|
|
||||||
|
(rt:deftest getf-strings-iii
|
||||||
|
(nih:getf-strings *getf-strings-list* "four")
|
||||||
|
(("four" iv)("four" 4)))
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest getf-string
|
||||||
|
(nih:getf-string *getf-strings-list* "four")
|
||||||
|
("four" iv))
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest get-colon-values-i
|
||||||
|
(nih:get-colon-values *colon-valued-string*)
|
||||||
|
(:DATE "1999-01-23" :PROGRAMME "QOTDD" :SPICE "tasty"))
|
||||||
|
|
||||||
|
(rt:deftest get-colon-values-ii
|
||||||
|
(nih:get-colon-values *a-string*)
|
||||||
|
nil)
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest remove-colon-values-i
|
||||||
|
(nih:remove-colon-values *colon-valued-string*)
|
||||||
|
"This is a QOTD-format colon-value thing!
|
||||||
|
From QOTDD, of course =w=")
|
||||||
|
|
||||||
|
(rt:deftest remove-colon-values-ii
|
||||||
|
(nih:remove-colon-values *a-string*)
|
||||||
|
"Hiya! <3<3<3")
|
|
@ -0,0 +1,85 @@
|
||||||
|
;; ----------------------------------------
|
||||||
|
;; WORD.LISP
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
;; DATA DECLARATIONS
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
(defvar *three-word-string*
|
||||||
|
"Hiya! <3<3<3 daddyyyyy")
|
||||||
|
|
||||||
|
(defvar *three-word-list*
|
||||||
|
'("Hiya!" "<3<3<3" "daddyyyyy"))
|
||||||
|
|
||||||
|
(defvar *word-repeat*
|
||||||
|
"I like to eat like to eat like to eat babies")
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest word-list-i
|
||||||
|
(nih:word-list *three-word-string*)
|
||||||
|
("Hiya!" "<3<3<3" "daddyyyyy"))
|
||||||
|
|
||||||
|
(rt:deftest word-list-ii
|
||||||
|
(nih:word-list "hi")
|
||||||
|
("hi"))
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest word-string-i
|
||||||
|
(nih:word-string *three-word-list*)
|
||||||
|
"Hiya! <3<3<3 daddyyyyy")
|
||||||
|
|
||||||
|
(rt:deftest word-string-ii
|
||||||
|
(nih:word-string '("hi"))
|
||||||
|
"hi")
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest word-nth-i
|
||||||
|
(nih:word-nth 2 *three-word-string*)
|
||||||
|
"daddyyyyy")
|
||||||
|
|
||||||
|
(rt:deftest word-nth-ii
|
||||||
|
(nih:word-nth 0 *three-word-string*)
|
||||||
|
"Hiya!")
|
||||||
|
|
||||||
|
(rt:deftest word-nth-iii
|
||||||
|
(nih:word-nth 1 *three-word-string*)
|
||||||
|
"<3<3<3")
|
||||||
|
|
||||||
|
(rt:deftest word-nth-iv
|
||||||
|
(nih:word-nth 0 "hi")
|
||||||
|
"hi")
|
||||||
|
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest word-get
|
||||||
|
(nih:word-get "Hi" *three-word-string*)
|
||||||
|
"Hiya!")
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest word-get-all
|
||||||
|
(nih:word-get-all ".*a.*" *three-word-string*)
|
||||||
|
"Hiya! daddyyyyy")
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest word-remove
|
||||||
|
(nih:word-remove "a" *three-word-string*)
|
||||||
|
"<3<3<3 daddyyyyy")
|
||||||
|
|
||||||
|
(rt:deftest word-remove-all
|
||||||
|
(nih:word-remove-all ".*a.*" *three-word-string*)
|
||||||
|
"<3<3<3")
|
||||||
|
|
||||||
|
|
||||||
|
(rt:deftest word-position
|
||||||
|
(nih:word-position "Hiya!" *three-word-string*)
|
||||||
|
0)
|
||||||
|
|
||||||
|
(rt:deftest word-positions
|
||||||
|
(nih:word-positions "like" *word-repeat*)
|
||||||
|
(1 4 7))
|
|
@ -0,0 +1,45 @@
|
||||||
|
(ql:quickload :rt)
|
||||||
|
(ql:quickload :cl-strings)
|
||||||
|
(ql:quickload :cl-ppcre)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(defpackage :nih-testing
|
||||||
|
(:use :cl)
|
||||||
|
(:export
|
||||||
|
|
||||||
|
:do-all))
|
||||||
|
|
||||||
|
(in-package :nih-testing)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(defun do-all ()
|
||||||
|
"Execute all tests."
|
||||||
|
|
||||||
|
(rt:do-tests))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(load "src/package.lisp")
|
||||||
|
|
||||||
|
(load "src/misc.lisp")
|
||||||
|
(load "t/misc.lisp")
|
||||||
|
|
||||||
|
(load "src/list.lisp")
|
||||||
|
(load "t/list.lisp")
|
||||||
|
|
||||||
|
(load "src/string/string.lisp")
|
||||||
|
(load "t/string/string.lisp")
|
||||||
|
|
||||||
|
(load "src/string/word.lisp")
|
||||||
|
(load "t/string/word.lisp")
|
||||||
|
|
||||||
|
(load "src/string/line.lisp")
|
||||||
|
(load "t/string/line.lisp")
|
||||||
|
|
||||||
|
(load "src/string/char.lisp")
|
||||||
|
(load "t/string/char.lisp")
|
||||||
|
|
||||||
|
(nih-testing:do-all)
|
Reference in New Issue