Jaidyn Lev authored on 2018-10-31 01:20:57
Showing 18 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,165 @@
1
+                   GNU LESSER GENERAL PUBLIC LICENSE
2
+                       Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+  This version of the GNU Lesser General Public License incorporates
10
+the terms and conditions of version 3 of the GNU General Public
11
+License, supplemented by the additional permissions listed below.
12
+
13
+  0. Additional Definitions.
14
+
15
+  As used herein, "this License" refers to version 3 of the GNU Lesser
16
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+General Public License.
18
+
19
+  "The Library" refers to a covered work governed by this License,
20
+other than an Application or a Combined Work as defined below.
21
+
22
+  An "Application" is any work that makes use of an interface provided
23
+by the Library, but which is not otherwise based on the Library.
24
+Defining a subclass of a class defined by the Library is deemed a mode
25
+of using an interface provided by the Library.
26
+
27
+  A "Combined Work" is a work produced by combining or linking an
28
+Application with the Library.  The particular version of the Library
29
+with which the Combined Work was made is also called the "Linked
30
+Version".
31
+
32
+  The "Minimal Corresponding Source" for a Combined Work means the
33
+Corresponding Source for the Combined Work, excluding any source code
34
+for portions of the Combined Work that, considered in isolation, are
35
+based on the Application, and not on the Linked Version.
36
+
37
+  The "Corresponding Application Code" for a Combined Work means the
38
+object code and/or source code for the Application, including any data
39
+and utility programs needed for reproducing the Combined Work from the
40
+Application, but excluding the System Libraries of the Combined Work.
41
+
42
+  1. Exception to Section 3 of the GNU GPL.
43
+
44
+  You may convey a covered work under sections 3 and 4 of this License
45
+without being bound by section 3 of the GNU GPL.
46
+
47
+  2. Conveying Modified Versions.
48
+
49
+  If you modify a copy of the Library, and, in your modifications, a
50
+facility refers to a function or data to be supplied by an Application
51
+that uses the facility (other than as an argument passed when the
52
+facility is invoked), then you may convey a copy of the modified
53
+version:
54
+
55
+   a) under this License, provided that you make a good faith effort to
56
+   ensure that, in the event an Application does not supply the
57
+   function or data, the facility still operates, and performs
58
+   whatever part of its purpose remains meaningful, or
59
+
60
+   b) under the GNU GPL, with none of the additional permissions of
61
+   this License applicable to that copy.
62
+
63
+  3. Object Code Incorporating Material from Library Header Files.
64
+
65
+  The object code form of an Application may incorporate material from
66
+a header file that is part of the Library.  You may convey such object
67
+code under terms of your choice, provided that, if the incorporated
68
+material is not limited to numerical parameters, data structure
69
+layouts and accessors, or small macros, inline functions and templates
70
+(ten or fewer lines in length), you do both of the following:
71
+
72
+   a) Give prominent notice with each copy of the object code that the
73
+   Library is used in it and that the Library and its use are
74
+   covered by this License.
75
+
76
+   b) Accompany the object code with a copy of the GNU GPL and this license
77
+   document.
78
+
79
+  4. Combined Works.
80
+
81
+  You may convey a Combined Work under terms of your choice that,
82
+taken together, effectively do not restrict modification of the
83
+portions of the Library contained in the Combined Work and reverse
84
+engineering for debugging such modifications, if you also do each of
85
+the following:
86
+
87
+   a) Give prominent notice with each copy of the Combined Work that
88
+   the Library is used in it and that the Library and its use are
89
+   covered by this License.
90
+
91
+   b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+   document.
93
+
94
+   c) For a Combined Work that displays copyright notices during
95
+   execution, include the copyright notice for the Library among
96
+   these notices, as well as a reference directing the user to the
97
+   copies of the GNU GPL and this license document.
98
+
99
+   d) Do one of the following:
100
+
101
+       0) Convey the Minimal Corresponding Source under the terms of this
102
+       License, and the Corresponding Application Code in a form
103
+       suitable for, and under terms that permit, the user to
104
+       recombine or relink the Application with a modified version of
105
+       the Linked Version to produce a modified Combined Work, in the
106
+       manner specified by section 6 of the GNU GPL for conveying
107
+       Corresponding Source.
108
+
109
+       1) Use a suitable shared library mechanism for linking with the
110
+       Library.  A suitable mechanism is one that (a) uses at run time
111
+       a copy of the Library already present on the user's computer
112
+       system, and (b) will operate properly with a modified version
113
+       of the Library that is interface-compatible with the Linked
114
+       Version.
115
+
116
+   e) Provide Installation Information, but only if you would otherwise
117
+   be required to provide such information under section 6 of the
118
+   GNU GPL, and only to the extent that such information is
119
+   necessary to install and execute a modified version of the
120
+   Combined Work produced by recombining or relinking the
121
+   Application with a modified version of the Linked Version. (If
122
+   you use option 4d0, the Installation Information must accompany
123
+   the Minimal Corresponding Source and Corresponding Application
124
+   Code. If you use option 4d1, you must provide the Installation
125
+   Information in the manner specified by section 6 of the GNU GPL
126
+   for conveying Corresponding Source.)
127
+
128
+  5. Combined Libraries.
129
+
130
+  You may place library facilities that are a work based on the
131
+Library side by side in a single library together with other library
132
+facilities that are not Applications and are not covered by this
133
+License, and convey such a combined library under terms of your
134
+choice, if you do both of the following:
135
+
136
+   a) Accompany the combined library with a copy of the same work based
137
+   on the Library, uncombined with any other library facilities,
138
+   conveyed under the terms of this License.
139
+
140
+   b) Give prominent notice with the combined library that part of it
141
+   is a work based on the Library, and explaining where to find the
142
+   accompanying uncombined form of the same work.
143
+
144
+  6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+  The Free Software Foundation may publish revised and/or new versions
147
+of the GNU Lesser General Public License from time to time. Such new
148
+versions will be similar in spirit to the present version, but may
149
+differ in detail to address new problems or concerns.
150
+
151
+  Each version is given a distinguishing version number. If the
152
+Library as you received it specifies that a certain numbered version
153
+of the GNU Lesser General Public License "or any later version"
154
+applies to it, you have the option of following the terms and
155
+conditions either of that published version or of any later version
156
+published by the Free Software Foundation. If the Library as you
157
+received it does not specify a version number of the GNU Lesser
158
+General Public License, you may choose any version of the GNU Lesser
159
+General Public License ever published by the Free Software Foundation.
160
+
161
+  If the Library as you received it specifies that a proxy can decide
162
+whether future versions of the GNU Lesser General Public License shall
163
+apply, that proxy's public statement of acceptance of any version is
164
+permanent authorization for you to choose that version for the
165
+Library.
0 166
new file mode 100644
... ...
@@ -0,0 +1,108 @@
1
+================================================================================
2
+NIH : `Not Invented Here`	A redundant misc. library
3
+================================================================================
4
+
5
+I've found that, generally, I end up using the same custom functions over and
6
+over again across all of my projects-- sometimes I'll copy-and-paste, other
7
+times I'll just re-implement.
8
+
9
+... which, predictably, leads to inconsistensies. While some versions of `x`
10
+function will flourish, gain new features, etc. etc., the others will
11
+inevitably lag behind.
12
+
13
+Well, no longer!
14
+
15
+I've decided to stuff (somewhat) refactored versions of these generic functions
16
+here, in this library!
17
+
18
+Most of them have to deal with string manipulations, but there's a bit more 
19
+than that-- and everything has tests! :)
20
+
21
+
22
+
23
+----------------------------------------
24
+USAGE
25
+----------------------------------------
26
+
27
+I mean... it's a library. Use a function you like. Or not. =w=
28
+But here's my logic with the string manipulation functions:
29
+
30
+I want to treat strings like lists. Getting the `car` of "hi there, dad", for
31
+example, should return "hi". Getting the `cdr` should be "there, dad".
32
+But, then again, that uses WORDS as the unit.
33
+What if I wanted to get the `car` or some such thing as say, a character? Or
34
+maybe even have the unit be a line?
35
+
36
+Thus, there are three different `units`:
37
+	* line-
38
+	* char-
39
+	* word-
40
+
41
+Each of these have the following functions:
42
+	* get-all
43
+	* get
44
+	* remove-all
45
+	* remove
46
+	* position
47
+	* positions
48
+	* nth
49
+	* car
50
+	* cdr
51
+	* caar
52
+	* cddr
53
+	* (all combos of cdr and car)
54
+
55
+... which behave pretty predictably.
56
+
57
+The `get` functions use regex (as do the remove functions), position(s) use
58
+the verbatim item value, etc.
59
+
60
+
61
+Examples
62
+--------------------
63
+
64
+(word-car "hiya, mate-o. how're you doing? <3")
65
+> "hiya,"
66
+
67
+(word-nth 2 "hiya, dad. what's up?")
68
+> "dad."
69
+
70
+(line-get-all ".*e.*"
71
+"hiya, what's up?
72
+don't eat anyone else, OK?
73
+i wouldn't like that.
74
+would you?")
75
+> "don't eat anyone else, OK?
76
+would you?"
77
+
78
+(char-remove #\h "hi there")
79
+> "i there"
80
+
81
+(char-remove-all #\h "hi there")
82
+> "i tere"
83
+
84
+... so on and so forth. 
85
+
86
+
87
+Oh, and those are just for generic string manips. There are still some
88
+
89
+Honourable Mentions
90
+--------------------
91
+	#'get-colon-values
92
+	#'remove-colon-values
93
+	#'positions
94
+	#'nil-blank
95
+	#'before
96
+	#'after
97
+	#'preceding
98
+	... etc
99
+
100
+
101
+
102
+----------------------------------------
103
+BORING STUFF
104
+----------------------------------------
105
+
106
+License is in COPYING.txt (GNU LGPLv3~! <3)
107
+Author is Jaidyn Ann <jadedctrl@teknik.io>
108
+Sauce is at https://git.eunichx.us/nih
0 109
new file mode 100755
... ...
@@ -0,0 +1,17 @@
1
+(defsystem "nih"
2
+	   :version "0.1"
3
+	   :author "Jaidyn Ann <jadedctrl@teknik.io>"
4
+           :license "CC 0"
5
+	   :depends-on ("cl-strings" "cl-ppcre")
6
+	   :components ((:module "src"
7
+			   :components
8
+			   ((:file "package")
9
+			    (:file "misc")
10
+			    (:file "list")
11
+			    (:file "string/string")
12
+			    (:file "string/word")
13
+			    (:file "string/line")
14
+			    (:file "string/char"))))
15
+
16
+           :description
17
+           "Library of miscellanous (probably extraneous) functions (mainly string-manipulations).")
0 18
new file mode 100644
... ...
@@ -0,0 +1,95 @@
1
+(in-package :nih)
2
+
3
+;; ITEM LIST --> DATA_AFTER_ITEM
4
+(defun following (item list)
5
+  "Return all items following the first instance of ITEM"
6
+
7
+  (cdr (up-from (position item list :test #'equal) list)))
8
+
9
+
10
+;; ITEM LIST --> DATA_UP_TO_ITEM
11
+(defun preceding (item list)
12
+  "Return all items preceding the first instance of ITEM"
13
+
14
+  (reverse
15
+    (cdr (reverse
16
+	   (up-to (position item list :test #'equal) list)))))
17
+
18
+
19
+;; ----------------------------------------
20
+
21
+
22
+;; ITEM LIST --> ITEM_BEFORE_ITEM
23
+(defun before (item list)
24
+  "Return the single item before ITEM"
25
+
26
+  (car (reverse (preceding item list))))
27
+
28
+
29
+;; ITEM LIST --> ITEM_AFTER_ITEM
30
+(defun after (item list)
31
+  "Return the single item after ITEM"
32
+
33
+  (car (following item list)))
34
+
35
+
36
+;; ----------------------------------------
37
+
38
+
39
+;; N LIST --> LIST_FROM_N
40
+(defun up-from (n list &optional (n-stack 0))
41
+  "Return all items after and including the position N in list"
42
+
43
+  (if (eq n n-stack)
44
+    list
45
+    (up-from n (cdr list) (+ n-stack 1))))
46
+
47
+
48
+;; N LIST --> LIST_UP_TO_N
49
+(defun up-to (n list &optional (n-stack 0))
50
+  "Return all items before and including the position N in list"
51
+
52
+  (cond
53
+    ((not (car list)) nil)
54
+    ((eq n n-stack) (list (car list)))
55
+    ((concatenate 'list
56
+		  (list (car list))
57
+		  (up-to n (cdr list) (+ n-stack 1))))))
58
+
59
+
60
+;; ----------------------------------------
61
+
62
+
63
+;; ITEM LIST --> LIST_OF_ITEM_POS
64
+(defun positions (item list &key (test #'eq))
65
+  "Return a list of positions of an item in a list."
66
+
67
+  (let ((i 0)
68
+	(stack '()))
69
+    (loop
70
+      :while (< i (length list))
71
+      :do
72
+      (if (funcall test (nth i list) item)
73
+	(setq stack (concatenate 'list stack (list i))))
74
+      (setq i (+ i 1)))
75
+
76
+    stack))
77
+
78
+
79
+;; ----------------------------------------
80
+
81
+
82
+;; LIST ITEM REPLACEMENT --> LIST_WITH_REPLACEMENTS
83
+(defun replace-at (list item replacement &key (test #'eq))
84
+  "Replace all instances of an item within a list with a replacement."
85
+
86
+  (let ((pos-list (positions item list :test test))
87
+	(stack list)
88
+	(i 0))
89
+    (loop
90
+      :while (< i (length pos-list))
91
+      :do
92
+      (setf (nth (nth i pos-list) stack) replacement)
93
+      (setq i (+ 1 i)))
94
+
95
+    stack))
0 96
new file mode 100644
... ...
@@ -0,0 +1,66 @@
1
+(in-package :nih)
2
+
3
+;; DATA --> LIST_OR_SUBLIST
4
+(defun list-or-real (data)
5
+  "If a piece of data's `car` is a list (I.E., if it's a list of a list)
6
+  then return the sub-list. If it's not a list, then just return the top-level
7
+  list.
8
+
9
+  This is useful for recursion, so that you can just serve the &rest list to
10
+  a function, instead of having to itemize the &rest list out to reproduce it."
11
+
12
+  (if (and
13
+	(eq (type-of (ignore-errors (car data))) 'CONS)
14
+	(eq (length data) 1))
15
+    (car data)
16
+    data))
17
+
18
+;; DATA ALT --> DATA_OR_ALT
19
+(defun value-or (data alt)
20
+  "If a piece of data exists, return it. Otherwise, return the alternative.
21
+  literally just `if`, lol"
22
+
23
+  (if data
24
+    data
25
+    alt))
26
+
27
+
28
+;; ARG-LIST &REST KEYS_TO_LOOK_FOR --> LIST_OF_KEY-VALUE_PAIRS
29
+(defun parse-keys (arg-list key-list)
30
+  "Return all searched-for keys fom a list in a list of key-value pairs."
31
+
32
+  (let ((stack '())
33
+	(new-list arg-list))
34
+    (loop
35
+      :for key
36
+      :in key-list
37
+      :do
38
+      (if (ignore-errors (position key arg-list))
39
+	(let* ((key-position (position key arg-list))
40
+	       (value-position (+ 1 key-position))
41
+	       (key-value (nth value-position arg-list)))
42
+	  (setq stack (concatenate 'list stack (list key key-value)))
43
+	  (setq new-list (remove key-value (remove key new-list))))))
44
+
45
+    (values stack new-list)))
46
+
47
+
48
+;; LIST --> RANDOM_ITEM
49
+(defun random-item (list)
50
+  "Return a random item from a list."
51
+
52
+  (nth (random (length list)) list))
53
+
54
+
55
+;; UNIVERSAL-TIME --> ISO8601-FORMAT_TIME
56
+(defun iso-time (universal-time)
57
+  "Return `universal-time` in ISO 8601 format. :)"
58
+
59
+  (multiple-value-bind
60
+    (second minute hour date month year)
61
+    (decode-universal-time universal-time)
62
+
63
+    (format nil "~A-~A-~A"
64
+	    year
65
+	    (min-string-length month 2 "0")
66
+	    (min-string-length date 2 "0"))))
0 67
new file mode 100644
... ...
@@ -0,0 +1,121 @@
1
+(defpackage :nih
2
+  (:use :cl)
3
+  (:export
4
+
5
+    ;; STRING
6
+    ;; =======================
7
+    :apply-convert
8
+    :string-manip
9
+    :create-string-manip
10
+    :manip-name
11
+
12
+    :string-combine
13
+    :intern-combine
14
+
15
+    :regex-get
16
+    :regex-get-all
17
+    :regex-remove
18
+    :regex-remove-all
19
+
20
+    :nil-string
21
+
22
+    :pad-string
23
+    :min-string-length
24
+
25
+    :getf-string
26
+    :getf-strings
27
+
28
+    :get-colon-values
29
+    :remove-colon-values
30
+
31
+
32
+    ;; STRING/WORD
33
+    ;; =======================
34
+    :word-list
35
+    :word-string
36
+    :word-nth
37
+
38
+    :word-get
39
+    :word-get-all
40
+    :word-remove
41
+    :word-remove-all
42
+    :word-position
43
+    :word-positions
44
+
45
+    :word-car
46
+    :word-caar :word-cadddrr :word-cadaar :word-cadr :word-caadr
47
+    :word-caaadr :word-caaaar :word-caadar :word-caddr :word-caaar
48
+    :word-cdr
49
+    :word-cdddar :word-cdar :word-cdaaar :word-cddddr :word-cdddr
50
+    :word-cdaadr :word-cdadar :word-cddadr :word-cdaddr :word-cdadr
51
+    :word-cddar :word-cddr :word-cddaar :word-cdaar
52
+
53
+
54
+    ;; STRING/LINE
55
+    ;; =======================
56
+    :line-list
57
+    :line-string
58
+    :line-nth
59
+
60
+    :line-get
61
+    :line-get-all
62
+    :line-remove
63
+    :line-remove-all
64
+    :line-position
65
+    :line-positions
66
+
67
+    :line-car
68
+    :line-caar :line-cadddrr :line-cadaar :line-cadr :line-caadr
69
+    :line-caaadr :line-caaaar :line-caadar :line-caddr :line-caaar
70
+    :line-cdr
71
+    :line-cdddar :line-cdar :line-cdaaar :line-cddddr :line-cdddr
72
+    :line-cdaadr :line-cdadar :line-cddadr :line-cdaddr :line-cdadr
73
+    :line-cddar :line-cddr :line-cddaar :line-cdaar
74
+
75
+
76
+    ;; STRING/CHAR
77
+    ;; =======================
78
+    :char-list
79
+    :char-string
80
+    :char-nth
81
+
82
+    :char-remove
83
+    :char-remove-all
84
+    :char-position
85
+    :char-positions
86
+
87
+    :char-car
88
+    :char-caar :char-cadddrr :char-cadaar :char-cadr :char-caadr
89
+    :char-caaadr :char-caaaar :char-caadar :char-caddr :char-caaar
90
+    :char-cdr
91
+    :char-cdddar :char-cdar :char-cdaaar :char-cddddr :char-cdddr
92
+    :char-cdaadr :char-cdadar :char-cddadr :char-cdaddr :char-cdadr
93
+    :char-cddar :char-cddr :char-cddaar :char-cdaar
94
+
95
+
96
+    ;; LIST
97
+    ;; =======================
98
+    :up-to
99
+    :up-from
100
+
101
+    :before
102
+    :after
103
+
104
+    :preceding
105
+    :following
106
+
107
+    :positions
108
+    
109
+    :replace-at
110
+
111
+
112
+    ;; MISC
113
+    ;; =======================
114
+    :random-item
115
+    :iso-time
116
+    :list-or-real
117
+    :value-or
118
+    :parse-keys))
119
+
120
+
121
+(in-package :nih)
0 122
new file mode 100644
... ...
@@ -0,0 +1,107 @@
1
+(in-package :nih)
2
+
3
+;; CHAR-LIST FUNCTIONS
4
+;; =====================================
5
+
6
+;; STRING --> LIST_OF_CHARS
7
+(defun char-list (string)
8
+  "Turn a string into a list of characters."
9
+
10
+  (let ((stack '()))
11
+    (loop
12
+      :for char
13
+      :across string
14
+      :do (setq stack
15
+		(append stack (list char))))
16
+    stack))
17
+
18
+
19
+;; LIST_OF_CHARS --> STRING
20
+(defun char-string (char-list)
21
+  "Convert a list of chars into a string"
22
+
23
+  (cond
24
+    ((eq (length char-list) 1)
25
+     (string (car char-list)))
26
+    ('T
27
+     (reduce
28
+       (lambda (char-a char-b)
29
+	 (string-combine (string char-a) (string char-b) :seperator ""))
30
+       char-list))))
31
+
32
+
33
+;; STRING --> NTH_CHARACTER
34
+(defun char-nth (n string)
35
+  "Return nth line number from a multi-line string."
36
+
37
+  (nth n (char-list string)))
38
+
39
+
40
+;; ----------------------------------------
41
+
42
+
43
+;; REGEX STRING --> LINES_SANS_MATCHES
44
+(defun char-remove (character string)
45
+  "Remove the first instance of a char from a string."
46
+
47
+  (let ((switch 0))
48
+    (reduce
49
+      (lambda (char-a char-b)
50
+	(string-combine
51
+	  (if (and (eq switch 0) (eq character char-a))
52
+	    (progn (setq switch 1) "")
53
+	    char-a)
54
+	  char-b))
55
+      (char-list string))))
56
+
57
+
58
+;; REGEX STRING --> LIST_OF_MATCHING_WORDS
59
+(defun char-remove-all (character string)
60
+  "Remove all instances of a char in a string."
61
+
62
+  (char-string (remove character (char-list string))))
63
+
64
+
65
+;; CHARACTER STRING --> 1ST_POS_OF_CHAR_IN_STRING
66
+(defun char-position (character string)
67
+  "Return the first position of a character in a string."
68
+
69
+  (position character (char-list string)))
70
+
71
+;; CHARACTER STRING --> LIST_OF_CHAR_POS_IN_STRING
72
+(defun char-positions (character string)
73
+  "Return a list of the positions of a character in a string."
74
+
75
+  (positions character (char-list string)))
76
+
77
+
78
+;; ----------------------------------------
79
+
80
+
81
+(create-string-manip char-car #'nih:char-list #'nih:char-string #'car)
82
+(create-string-manip char-caar #'nih:char-list #'nih:char-string #'caar)
83
+(create-string-manip char-cadddrr #'nih:char-list #'nih:char-string #'cadddrr)
84
+(create-string-manip char-cadaar #'nih:char-list #'nih:char-string #'cadaar)
85
+(create-string-manip char-cadr #'nih:char-list #'nih:char-string #'cadr)
86
+(create-string-manip char-caadr #'nih:char-list #'nih:char-string #'caadr)
87
+(create-string-manip char-caaadr #'nih:char-list #'nih:char-string #'caaadr)
88
+(create-string-manip char-caaaar #'nih:char-list #'nih:char-string #'caaaar)
89
+(create-string-manip char-caadar #'nih:char-list #'nih:char-string #'caadar)
90
+(create-string-manip char-caddr #'nih:char-list #'nih:char-string #'caddr)
91
+(create-string-manip char-caaar #'nih:char-list #'nih:char-string #'caaar)
92
+
93
+(create-string-manip char-cdr #'nih:char-list #'nih:char-string #'cdr)
94
+(create-string-manip char-cdddar #'nih:char-list #'nih:char-string #'cdddar)
95
+(create-string-manip char-cdar #'nih:char-list #'nih:char-string #'cdar)
96
+(create-string-manip char-cdaaar #'nih:char-list #'nih:char-string #'cdaaar)
97
+(create-string-manip char-cddddr #'nih:char-list #'nih:char-string #'cddddr)
98
+(create-string-manip char-cdddr #'nih:char-list #'nih:char-string #'cdddr)
99
+(create-string-manip char-cdaadr #'nih:char-list #'nih:char-string #'cdaadr)
100
+(create-string-manip char-cdadar #'nih:char-list #'nih:char-string #'cdadar)
101
+(create-string-manip char-cddadr #'nih:char-list #'nih:char-string #'cddadr)
102
+(create-string-manip char-cdaddr #'nih:char-list #'nih:char-string #'cdaddr)
103
+(create-string-manip char-cdadr #'nih:char-list #'nih:char-string #'cdadr)
104
+(create-string-manip char-cddar #'nih:char-list #'nih:char-string #'cddar)
105
+(create-string-manip char-cddr #'nih:char-list #'nih:char-string #'cddr)
106
+(create-string-manip char-cddaar #'nih:char-list #'nih:char-string #'cddaar)
107
+(create-string-manip char-cdaar #'nih:char-list #'nih:char-string #'cdaar)
0 108
new file mode 100644
... ...
@@ -0,0 +1,104 @@
1
+(in-package :nih)
2
+
3
+;; LINE-LIST FUNCTIONS
4
+;; =====================================
5
+
6
+;; MULTI-LINE_STRING --> LIST_OF_LINES
7
+(defun line-list (string)
8
+  "Return a list of lines from a multi-line string."
9
+
10
+  (cl-strings:split string (format nil "~%")))
11
+
12
+
13
+
14
+;; LIST_OF_STRINGS --> MULTI-LINE_STRING
15
+(defun line-string (line-list)
16
+  "Turn a list of lines (string) into a multi-line string."
17
+
18
+  (if (not (equal (type-of line-list) 'CONS))
19
+    line-list
20
+    (reduce
21
+      (lambda (line-a line-b)
22
+	(string-combine :seperator (format nil "~%") line-a line-b))
23
+      line-list)))
24
+
25
+
26
+;; NUMBER MULTI-LINE_STRING --> SINGLE-LINE_STRING
27
+(defun line-nth (n string)
28
+  "Return nth line number from a multi-line string."
29
+
30
+  (nth n (line-list string)))
31
+
32
+
33
+;; ----------------------------------------
34
+
35
+
36
+;; REGEX STRING --> MATCHING_WORD
37
+(defun line-get (query string)
38
+  "Return a line in a string that matches a regex query."
39
+
40
+  (ignore-errors (line-car (line-get-all query string))))
41
+
42
+;; REGEX STRING --> LIST_OF_MATCHING_WORDS
43
+(defun line-get-all (query string)
44
+  "Return all lines in a string that match a regex query."
45
+
46
+  (line-string (regex-get-all query (line-list string))))
47
+
48
+
49
+;; REGEX STRING --> LINES_SANS_MATCHES
50
+(defun line-remove (query string)
51
+  "Remove a line from a string that matches a regex query."
52
+
53
+  (line-string (regex-remove query (line-list string))))
54
+
55
+;; REGEX STRING --> LINES_SANS_MATCHES
56
+(defun line-remove-all (query string)
57
+  "Remove all lines from a string that match a regex query."
58
+
59
+  (line-string (regex-remove-all query (line-list string))))
60
+
61
+
62
+;; LINE STRING --> POS_OF_LINE_IN_STRING
63
+(defun line-position (line string)
64
+  "Return the line-number of a line in a string."
65
+
66
+  (position line (line-list string) :test #'equal))
67
+
68
+;; LINE STRING --> LIST_OF_LINE_POS_IN_STRING
69
+(defun line-positions (line string)
70
+  "Return a list of the positions of a line in string."
71
+
72
+  (positions line (line-list string) :test #'equal))
73
+
74
+
75
+;; ----------------------------------------
76
+
77
+
78
+(create-string-manip line-car #'nih:line-list #'nih:line-string #'car)
79
+(create-string-manip line-caar #'nih:line-list #'nih:line-string #'caar)
80
+(create-string-manip line-cadddrr #'nih:line-list #'nih:line-string #'cadddrr)
81
+(create-string-manip line-cadaar #'nih:line-list #'nih:line-string #'cadaar)
82
+(create-string-manip line-cadr #'nih:line-list #'nih:line-string #'cadr)
83
+(create-string-manip line-caadr #'nih:line-list #'nih:line-string #'caadr)
84
+(create-string-manip line-caaadr #'nih:line-list #'nih:line-string #'caaadr)
85
+(create-string-manip line-caaaar #'nih:line-list #'nih:line-string #'caaaar)
86
+(create-string-manip line-caadar #'nih:line-list #'nih:line-string #'caadar)
87
+(create-string-manip line-caddr #'nih:line-list #'nih:line-string #'caddr)
88
+(create-string-manip line-caaar #'nih:line-list #'nih:line-string #'caaar)
89
+
90
+(create-string-manip line-cdr #'nih:line-list #'nih:line-string #'cdr)
91
+(create-string-manip line-cdddar #'nih:line-list #'nih:line-string #'cdddar)
92
+(create-string-manip line-cdar #'nih:line-list #'nih:line-string #'cdar)
93
+(create-string-manip line-cdaaar #'nih:line-list #'nih:line-string #'cdaaar)
94
+(create-string-manip line-cddddr #'nih:line-list #'nih:line-string #'cddddr)
95
+(create-string-manip line-cdddr #'nih:line-list #'nih:line-string #'cdddr)
96
+(create-string-manip line-cdaadr #'nih:line-list #'nih:line-string #'cdaadr)
97
+(create-string-manip line-cdadar #'nih:line-list #'nih:line-string #'cdadar)
98
+(create-string-manip line-cddadr #'nih:line-list #'nih:line-string #'cddadr)
99
+(create-string-manip line-cdaddr #'nih:line-list #'nih:line-string #'cdaddr)
100
+(create-string-manip line-cdadr #'nih:line-list #'nih:line-string #'cdadr)
101
+(create-string-manip line-cddar #'nih:line-list #'nih:line-string #'cddar)
102
+(create-string-manip line-cddr #'nih:line-list #'nih:line-string #'cddr)
103
+(create-string-manip line-cddaar #'nih:line-list #'nih:line-string #'cddaar)
104
+(create-string-manip line-cdaar #'nih:line-list #'nih:line-string #'cdaar)
0 105
new file mode 100644
... ...
@@ -0,0 +1,270 @@
1
+(in-package :nih)
2
+
3
+
4
+;; FUNCTION-NAME #'TO-LIST #'TO-STRING #'MANIPULATION
5
+(defmacro create-string-manip (manip-name list-function string-function manip)
6
+  "Define a function to perform a manipulation (#'manip, i.e. #'car)  on the
7
+  list-form of a particular string (converting to list with #'list-function),
8
+  then converting back into a string (#'string-function) again
9
+  (but with the manipulations made)."
10
+
11
+  `(defun ,manip-name (string)
12
+     (funcall ,string-function
13
+	      (funcall ,manip
14
+		       (funcall ,list-function string)))))
15
+
16
+
17
+;; ======================================== 
18
+
19
+
20
+;; STRINGS :SEPERATOR --> STRINGS_COMBINED_W_SEPERATOR
21
+(defun string-combine (&rest arg-list)
22
+  "Combine strings into a single string, marked with a seperator.
23
+  :seperator is parsed manually, since mixing &rest and &key makes
24
+  me want to eat my fucking hat. >;c"
25
+
26
+  (multiple-value-bind (keys strings)
27
+    (parse-keys arg-list '(:seperator))
28
+
29
+    (let ((seperator (value-or (getf keys :seperator) "")))
30
+
31
+      (reduce (lambda (word1 word2)
32
+		(format nil "~A~A~A" word1 seperator word2))
33
+	      strings))))
34
+
35
+
36
+;; STRING_A STRING_B --> SYMBOL_OF_STRING_A+STRING_B
37
+(defun intern-combine (&rest arg-list)
38
+  "Combine two strings into a symbol, marked with a seperator.
39
+  :seperator and :package are parsed manually, since mixing &rest
40
+  and &key is utterly painful! ;_:"
41
+
42
+  (multiple-value-bind (keys strings)
43
+    (parse-keys arg-list '(:seperator :package))
44
+
45
+    (let* ((seperator (value-or (getf keys :seperator) ""))
46
+	   (package (value-or (getf keys :package) nil))
47
+	   (combined (string-upcase
48
+		       (reduce (lambda (str1 str2)
49
+				 (string-combine  str1 str2
50
+						  :seperator seperator))
51
+			       strings))))
52
+
53
+      (if package
54
+	(intern combined (string-upcase package))
55
+	(intern combined)))))
56
+
57
+
58
+;; ---------------------------------------- 
59
+
60
+
61
+;; LIST --> LIST_SANS_NIL_WITH_""
62
+(defun nil-string (list)
63
+  "Replace all instances of nil in a list with a blank string."
64
+
65
+  (replace-at list nil ""))
66
+
67
+
68
+;; ---------------------------------------- 
69
+
70
+
71
+;; STRING PREFIX SUFFIX --> STRING_ONE_OR_TWO_CHARS_LARGER
72
+(defun pad-string (string &key prefix suffix)
73
+  "Increase the character-count of a string by 1; either by
74
+  adding a prefix-substitutor or a suffix-substitutor.
75
+  If both a :prefix and a :suffix are provided, :suffix is
76
+  ignored."
77
+
78
+  (flet ((padding (prefix string suffix)
79
+		  (format nil "~A~A~A" prefix string suffix)))
80
+
81
+    (cond
82
+      ((and prefix suffix)
83
+       (padding prefix string ""))
84
+      (prefix
85
+	(padding prefix string ""))
86
+      (suffix
87
+	(padding "" string suffix)))))
88
+
89
+
90
+
91
+;; STRING DESIRED_LENGTH [PREFIX] [SUFFIX] --> STRING_OF_DESIRED_LENGTH
92
+(defun min-string-length (string target-length
93
+				 &key (prefix "") (suffix ""))
94
+  "If a string *must* be a certain length (formatting reasons), use
95
+this function.
96
+
97
+Returns a string of `length`, using the `prefix-substitutor` or
98
+`suffix-substitutor` to beef up the character-count if it's too short.
99
+
100
+If both `prefix` and `suffix` are defined, `prefix` is used.
101
+
102
+Example:
103
+(min-string-length \"9\" 3 \"0\")
104
+
105
+\"009\""
106
+
107
+(let* ((string (format nil "~A" string))
108
+       (cur-length (length string)))
109
+
110
+  (if (eq cur-length target-length)
111
+    string
112
+
113
+    (min-string-length
114
+      (if (eq (length suffix) 0)
115
+	(pad-string string :prefix prefix)
116
+	(pad-string string :suffix suffix))
117
+      target-length
118
+      :prefix prefix
119
+      :suffix suffix))))
120
+
121
+
122
+;; ---------------------------------------- 
123
+
124
+
125
+;; REGEX STRING --> MATCHING_WORD
126
+(defun regex-get (query strings)
127
+  "Return a string in a list that matches a regex query."
128
+
129
+  (car (regex-get-all query strings)))
130
+
131
+
132
+;; REGEX STRING --> LIST_OF_MATCHING_WORDS
133
+(defun regex-get-all (query strings)
134
+  "Return all strings in a list that match a regex query."
135
+
136
+  (let ((stack '())
137
+	(i 0))
138
+
139
+    (loop
140
+      :while (< i (length strings))
141
+      :do
142
+      (if (cl-ppcre:scan-to-strings query (nth i strings))
143
+	(setq stack (concatenate 'list stack (list (nth i strings)))))
144
+
145
+      (setq i (+ 1 i)))
146
+
147
+    stack))
148
+
149
+
150
+;; REGEX STRING --> ALL_BUT_MATCHES
151
+(defun regex-remove (query strings)
152
+  "Return a list of strings without a matches to a regex query."
153
+
154
+  (let ((stack '())
155
+	(switch 0)
156
+	(i 0))
157
+
158
+    (loop
159
+      :while (< i (length strings))
160
+      :do
161
+      (cond
162
+	((eq switch 1)
163
+	 (setq stack (concatenate 'list stack (list (nth i strings)))))
164
+	((cl-ppcre:scan-to-strings query (nth i strings))
165
+	 (setq switch 1))
166
+	('T 
167
+	 (setq stack (concatenate 'list stack (list (nth i strings))))))
168
+
169
+      (setq i (+ 1 i)))
170
+
171
+    stack))
172
+
173
+;; REGEX STRING --> ALL_BUT_MATCHES
174
+(defun regex-remove-all (query strings)
175
+  "Return a list of strings without any matches to a regex query."
176
+
177
+  (let ((stack '())
178
+	(i 0))
179
+
180
+    (loop
181
+      :while (< i (length strings))
182
+      :do
183
+      (if (not (cl-ppcre:scan-to-strings query (nth i strings)))
184
+	(setq stack (concatenate 'list stack (list (nth i strings)))))
185
+
186
+      (setq i (+ 1 i)))
187
+
188
+    stack))
189
+
190
+
191
+;; ---------------------------------------- 
192
+
193
+
194
+;; LIST_OF_SUBLISTS STRING --> SUBLIST_WITH_STRING_AS_CAR
195
+(defun getf-string (list string)
196
+  "Get an item from a list by an identifying string in `car`.
197
+  I.E., if the string is 'apple', the first sublist like this:
198
+  ('apple' 1 2 3)
199
+  will be returned."
200
+
201
+  (car (getf-strings list string)))
202
+
203
+
204
+
205
+;; LIST_OF_SUBLISTS STRING --> LIST_OF_SUBLISTS_WITH_STRING_AS_CAR
206
+(defun getf-strings (list string &optional (stack '()))
207
+  "Get items from list by an identifying string in `car`.
208
+  I.E., if the string is 'apple', any sublists like this:
209
+  ('apple' 1 2 3)
210
+  will be returned."
211
+
212
+  ;; just recurse through the list, adding each new matching
213
+  ;; item to the `stack`
214
+
215
+  (if (and (< 0 (length list)) (listp list))
216
+    (if (ignore-errors
217
+	  ;; the item might not be a list; for our purposes, let's ignore that.
218
+	  (equal
219
+	    (car (car list))    ;; '( ( here ) )
220
+	    string))
221
+      (getf-strings (cdr list) string (concatenate 'list stack (list (car list))))
222
+      (getf-strings (cdr list) string stack))
223
+    stack))
224
+
225
+
226
+;; ---------------------------------------- 
227
+
228
+
229
+;; STRING COLON_VARIABLE_NAME --> COLON_VALUE
230
+(defun get-colon-values (string)
231
+  "Return a the value of a `colon variable`; I.E.,
232
+  a line of a string starting with `:` followed by a variable
233
+  name, a space, then the value of said `colon variable`.
234
+
235
+  Here's an example:
236
+  (setq *example-string*
237
+	\"Blah blah blah
238
+	:Date 1999
239
+	Blah blah blah\")
240
+
241
+  If you ran
242
+  (get-colon-values *example-string*)
243
+
244
+  you would get
245
+  (:DATE \"1999\") in return.
246
+
247
+  Mainly useful for multi-line strings, but your use-case might
248
+  involve a `colon variable` in a single-lined string."
249
+
250
+  (if (line-get-all "^:" string)
251
+    (let* ((colon-lines (line-get-all "^:.* " string))
252
+	   (colon-list (line-list colon-lines))
253
+	   (cur-line (line-car colon-lines))
254
+	   (variable (word-car cur-line))
255
+	   (value (word-cdr cur-line)))
256
+
257
+      (cond
258
+	((eq 1 (length colon-list))
259
+	 (list (read-from-string variable) value))
260
+	('T
261
+	 (concatenate 'list (list (read-from-string variable) value)
262
+		      (get-colon-values (line-cdr colon-lines))))))))
263
+
264
+
265
+
266
+  ;; STRING COLON_VARIABLE_NAME --> STRING_WITHOUT_COLON_VARIABLE
267
+  (defun remove-colon-values (string)
268
+    "Remove the colon-variable declaration from a string."
269
+
270
+    (line-remove-all "^:.*" string))
0 271
new file mode 100644
... ...
@@ -0,0 +1,104 @@
1
+(in-package :nih)
2
+
3
+;; WORD-LIST FUNCTIONS
4
+;; =====================================
5
+
6
+;; STRING --> LIST_OF_WORDS
7
+(defun word-list (string)
8
+  "Turn a string into a list of words."
9
+
10
+  (cl-strings:split string " "))
11
+
12
+
13
+
14
+;; LIST_OF_WORDS --> STRING
15
+(defun word-string (word-list)
16
+  "Convert a list of words into a string"
17
+
18
+  (if (not (equal (type-of word-list) 'CONS))
19
+    word-list
20
+    (reduce
21
+      (lambda (word-a word-b)
22
+	(string-combine :seperator " " word-a word-b))
23
+      word-list)))
24
+
25
+
26
+;; STRING --> NTH_WORD_FROM_STRING
27
+(defun word-nth (n string)
28
+  "Get nth word from a string."
29
+
30
+  (word-string (nth n (word-list string))))
31
+
32
+
33
+;; ----------------------------------------
34
+
35
+
36
+;; REGEX STRING --> MATCHING_WORD
37
+(defun word-get (query string)
38
+  "Return a word in a string that matches a regex query."
39
+
40
+  (word-car (word-get-all query string)))
41
+
42
+;; REGEX STRING --> LIST_OF_MATCHING_WORDS
43
+(defun word-get-all (query string)
44
+  "Return all words in a string that match a regex query."
45
+
46
+  (word-string (regex-get-all query (word-list string))))
47
+
48
+
49
+;; REGEX STRING --> LINES_SANS_MATCHES
50
+(defun word-remove (query string)
51
+    "Remove a word from a string that matches a regex query."
52
+
53
+      (word-string (regex-remove query (word-list string))))
54
+
55
+;; REGEX STRING --> LINES_SANS_MATCHES
56
+(defun word-remove-all (query string)
57
+    "Remove all words from a string that match a regex query."
58
+
59
+      (word-string (regex-remove-all query (word-list string))))
60
+
61
+
62
+;; WORD STRING --> WORD_POS_IN_STRING
63
+(defun word-position (word string)
64
+  "Return the position of a word (relative to other words) in a string."
65
+
66
+  (position word (word-list string) :test #'equal))
67
+
68
+;; WORD STRING --> LIST_OF_WORD_POS_IN_STRING
69
+(defun word-positions (word string)
70
+  "Return a list of positions of a word (relative to other words) in a string."
71
+
72
+  (positions word (word-list string) :test #'equal))
73
+
74
+
75
+;; ----------------------------------------
76
+
77
+
78
+(create-string-manip word-car #'nih:word-list #'nih:word-string #'car)
79
+(create-string-manip word-caar #'nih:word-list #'nih:word-string #'caar)
80
+(create-string-manip word-cadddrr #'nih:word-list #'nih:word-string #'cadddrr)
81
+(create-string-manip word-cadaar #'nih:word-list #'nih:word-string #'cadaar)
82
+(create-string-manip word-cadr #'nih:word-list #'nih:word-string #'cadr)
83
+(create-string-manip word-caadr #'nih:word-list #'nih:word-string #'caadr)
84
+(create-string-manip word-caaadr #'nih:word-list #'nih:word-string #'caaadr)
85
+(create-string-manip word-caaaar #'nih:word-list #'nih:word-string #'caaaar)
86
+(create-string-manip word-caadar #'nih:word-list #'nih:word-string #'caadar)
87
+(create-string-manip word-caddr #'nih:word-list #'nih:word-string #'caddr)
88
+(create-string-manip word-caaar #'nih:word-list #'nih:word-string #'caaar)
89
+
90
+(create-string-manip word-cdr #'nih:word-list #'nih:word-string #'cdr)
91
+(create-string-manip word-cdddar #'nih:word-list #'nih:word-string #'cdddar)
92
+(create-string-manip word-cdar #'nih:word-list #'nih:word-string #'cdar)
93
+(create-string-manip word-cdaaar #'nih:word-list #'nih:word-string #'cdaaar)
94
+(create-string-manip word-cddddr #'nih:word-list #'nih:word-string #'cddddr)
95
+(create-string-manip word-cdddr #'nih:word-list #'nih:word-string #'cdddr)
96
+(create-string-manip word-cdaadr #'nih:word-list #'nih:word-string #'cdaadr)
97
+(create-string-manip word-cdadar #'nih:word-list #'nih:word-string #'cdadar)
98
+(create-string-manip word-cddadr #'nih:word-list #'nih:word-string #'cddadr)
99
+(create-string-manip word-cdaddr #'nih:word-list #'nih:word-string #'cdaddr)
100
+(create-string-manip word-cdadr #'nih:word-list #'nih:word-string #'cdadr)
101
+(create-string-manip word-cddar #'nih:word-list #'nih:word-string #'cddar)
102
+(create-string-manip word-cddr #'nih:word-list #'nih:word-string #'cddr)
103
+(create-string-manip word-cddaar #'nih:word-list #'nih:word-string #'cddaar)
104
+(create-string-manip word-cdaar #'nih:word-list #'nih:word-string #'cdaar)
0 105
new file mode 100644
... ...
@@ -0,0 +1,12 @@
1
+================================================================================
2
+TESTING FOR :NIH
3
+================================================================================
4
+
5
+To test :nih functions, just change directories into the root of the
6
+repository; then, load `t.lisp` from there, like so:
7
+
8
+	[0]> (load "t/t.lisp")
9
+
10
+Then, you can run the tests as you please:
11
+
12
+	[1]> (nih-testing:do-all)
0 13
new file mode 100644
... ...
@@ -0,0 +1,106 @@
1
+;; ----------------------------------------
2
+;; STRING.LISP
3
+;; ----------------------------------------
4
+
5
+
6
+;; DATA DECLARATIONS
7
+;; ----------------------------------------
8
+
9
+(defvar *number-list* '(98 37 23 24 14 14 24 52 5325 32 4234))
10
+
11
+(defvar *one-number-list* '(1))
12
+
13
+
14
+;; TESTS
15
+;; ----------------------------------------
16
+
17
+(rt:deftest up-to-i
18
+	    (nih:up-to 2 *number-list*)
19
+	    (98 37 23))
20
+
21
+(rt:deftest up-to-ii
22
+	    (nih:up-to 0 *one-number-list*)
23
+	    (1))
24
+
25
+(rt:deftest up-to-iii
26
+	    (nih:up-to 3 *one-number-list*)
27
+	    (1))
28
+
29
+(rt:deftest up-to-iv
30
+	    (nih:up-to 13 *number-list*)
31
+	    (98 37 23 24 14 14 24 52 5325  32 4234))
32
+
33
+
34
+(rt:deftest up-from-i
35
+	    (nih:up-from 2 *number-list*)
36
+	    (23 24 14 14 24 52 5325 32 4234))
37
+
38
+(rt:deftest up-from-ii
39
+	    (nih:up-from 10 *number-list*)
40
+	    (4234))
41
+
42
+(rt:deftest up-from-iii
43
+	    (nih:up-from 11 *number-list*)
44
+	    nil)
45
+
46
+
47
+;; ----------------------------------------
48
+
49
+
50
+(rt:deftest before-i
51
+	    (nih:before 37 *number-list*)
52
+	    98)
53
+
54
+(rt:deftest before-ii
55
+	    (nih:before 98 *number-list*)
56
+	    nil)
57
+
58
+
59
+(rt:deftest after-i
60
+	    (nih:after 37 *number-list*)
61
+	    23)
62
+
63
+(rt:deftest after-ii
64
+	    (nih:after 4234 *number-list*)
65
+	    nil)
66
+
67
+
68
+;; ----------------------------------------
69
+
70
+
71
+(rt:deftest following-i
72
+	    (nih:following 37 *number-list*)
73
+	    (23 24 14 14 24 52 5325 32 4234))
74
+
75
+(rt:deftest following-ii
76
+	    (nih:following 4234 *number-list*)
77
+	    nil)
78
+
79
+
80
+(rt:deftest preceding-i
81
+	    (nih:preceding 23 *number-list*)
82
+	    (98 37))
83
+
84
+(rt:deftest preceding-ii
85
+	    (nih:preceding 98 *number-list*)
86
+	    nil)
87
+
88
+
89
+;; ----------------------------------------
90
+
91
+
92
+(rt:deftest positions
93
+	    (nih:positions 14 *number-list*)
94
+	    (4 5))
95
+
96
+
97
+;; ----------------------------------------
98
+
99
+
100
+(rt:deftest replace-at-i
101
+	    (nih:replace-at '(1 2 3 1 4) 1 0)
102
+	    (0 2 3 0 4))
103
+
104
+(rt:deftest replace-at-ii
105
+	    (nih:replace-at '("yo" "hi" "hi" "ya") "hi" "ye" :test #'equal)
106
+	    ("yo" "ye" "ye" "ya"))
0 107
new file mode 100644
... ...
@@ -0,0 +1,60 @@
1
+;; ----------------------------------------
2
+;; STRING.LISP
3
+;; ----------------------------------------
4
+
5
+
6
+;; DATA DECLARATIONS
7
+;; ----------------------------------------
8
+
9
+(defvar *list-in-list* '((1 2 3 4)))
10
+
11
+(defvar *keyed-list* '(1 2 :morto "hi" 3 :ploro 4))
12
+
13
+
14
+;; TESTS
15
+;; ----------------------------------------
16
+
17
+
18
+(rt:deftest parse-keys-i
19
+	    (nih:parse-keys *keyed-list* '(:morto))
20
+	    (:morto "hi")
21
+	    (1 2 3 :ploro 4))
22
+
23
+(rt:deftest parse-keys-ii
24
+	    (nih:parse-keys *keyed-list* '(:ploro))
25
+	    (:ploro 4)
26
+	    (1 2 :morto "hi" 3))
27
+
28
+(rt:deftest parse-keys-iii
29
+	    (nih:parse-keys *keyed-list* '(:ploro :morto))
30
+	    (:ploro 4 :morto "hi")
31
+	    (1 2 3))
32
+
33
+(rt:deftest parse-keys-iv
34
+	    (nih:parse-keys *list-in-list* '(:ploro :morto))
35
+	    nil
36
+	    ((1 2 3 4)))
37
+
38
+
39
+;; ----------------------------------------
40
+
41
+
42
+(rt:deftest value-or-i
43
+	    (nih:value-or nil "")
44
+	    "")
45
+
46
+(rt:deftest value-or-ii
47
+	    (nih:value-or 2 "")
48
+	    2)
49
+
50
+
51
+;; ----------------------------------------
52
+
53
+
54
+(rt:deftest list-or-real-i
55
+	    (nih:list-or-real *list-in-list*)
56
+	    (1 2 3 4))
57
+
58
+(rt:deftest list-or-real-ii
59
+	    (nih:list-or-real *keyed-list*)
60
+	    (1 2 :morto "hi" 3 :ploro 4))
0 61
new file mode 100644
... ...
@@ -0,0 +1,80 @@
1
+;; ----------------------------------------
2
+;; WORD.LISP
3
+;; ----------------------------------------
4
+
5
+
6
+;; DATA DECLARATIONS
7
+;; ----------------------------------------
8
+
9
+(defvar *three-words*
10
+  "Hiya! <3<3<3 daddyyyyy")
11
+
12
+(defvar *three-words-char-list*
13
+  '(#\H #\i #\y #\a #\!
14
+    #\Space #\< #\3 #\< #\3 #\< #\3
15
+    #\Space #\d #\a #\d #\d #\y #\y #\y #\y #\y))
16
+
17
+(defvar *char-repeat*
18
+  "I like to eat like to eat like to eat babies")
19
+
20
+
21
+;; ----------------------------------------
22
+
23
+
24
+(rt:deftest char-list
25
+	    (nih:char-list *three-words*)
26
+	    (#\H #\i #\y #\a #\!
27
+	     #\Space #\< #\3 #\< #\3 #\< #\3
28
+	     #\Space #\d #\a #\d #\d #\y #\y #\y #\y #\y))
29
+
30
+
31
+(rt:deftest char-string
32
+	    (nih:char-string *three-words-char-list*)
33
+	    "Hiya! <3<3<3 daddyyyyy")
34
+
35
+
36
+(rt:deftest char-nth-i
37
+	    (nih:char-nth 0 *three-words*)
38
+	    #\H)
39
+
40
+(rt:deftest char-nth-ii
41
+	    (nih:char-nth 2 *three-words*)
42
+	    #\y)
43
+
44
+(rt:deftest char-nth-iii
45
+	    (nih:char-nth 21 *three-words*)
46
+	    #\y)
47
+
48
+
49
+;; ----------------------------------------
50
+