-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring.el
86 lines (69 loc) · 2.09 KB
/
string.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
;******************************************************************************;
; ;
; string.el for string ;
; Created on : Thu Oct 20 15:36:57 2011 ;
; Made by : David "Thor" GIRON <[email protected]> ;
; ;
;******************************************************************************;
(require 'list)
(defun string-reverse (s)
"Returns the reversed string of 's'."
(concat (reverse (string-to-list s)))
)
(defun string-length (s)
"Returns the length of string 's'."
(length s)
)
(defun string-fill (len)
(make-string len ? )
)
(defun string-compare (s1 s2)
"Compares 's1' and 's2'. Returns :
- -1 if 's1' is shorter than 's2'
- 0 if 's1' and 's2' are equal
- 1 if 's1' is longer than 's2'"
(let ((len1 (string-length s1))
(len2 (string-length s2)))
(cond
((= len1 len2) 0)
((< len1 len2) -1)
((> len1 len2) 1)
)
)
)
(defun string-longest (s1 s2)
"Returns the length of the longest string"
(let ((res (string-compare s1 s2)))
(cond
((= res 1 ) (string-length s1))
((= res 0 ) (string-length s1))
((= res -1) (string-length s2))
)
)
)
(defun string-pick-longest (s1 s2)
"Returns the longest string between 's1' and 's2', or 's1' otherwise."
(let ((res (string-compare s1 s2)))
(cond
((= res 1 ) s1)
((= res 0 ) s1)
((= res -1) s2)
)
)
)
(defun string-longest-from-list (l)
"Returns the length of longest string of the strings list 'l'."
(list-fold
(lambda (acc s) (if (> acc (string-length s)) acc (string-length s)))
0
l)
)
(defun string-pick-longest-from-list (l)
"Returns the longest string of the strings list 'l'."
(list-fold
(lambda (s1 s2) (string-pick-longest s1 s2))
""
l)
)
;******************************************************************************;
(provide 'string)