File: kdab-qstring.el

package info (click to toggle)
kde-dev-scripts 4%3A20.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,476 kB
  • sloc: perl: 15,559; lisp: 5,627; sh: 4,315; python: 3,892; ruby: 1,386; makefile: 13; sed: 9
file content (53 lines) | stat: -rw-r--r-- 1,533 bytes parent folder | download | duplicates (7)
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
;; Strings are just the most annoying things in Lisp, so this file will
;; contain some of the well known string functions from QString

(defun string-startsWith (fullstring substring)
  (and
   ( >= (length fullstring) (length substring))
   (string= (substring fullstring 0 (length substring)) substring)))

(defun string-endsWith (fullstring substring)
  (string= (substring fullstring (- (length fullstring) (length substring))) substring))

(defun string-indexOf-regexp (fullstring regexp) 
  (string-match regexp fullstring))

(defun string-left (string count)
  (if (> count (length string))
      string
    (substring string 0 count)))

(defun string-mid (string start &optional count)
  (if count
      (substring string start (+ start count))
  (substring string start)))

(defun string-right (string count)
  (if (> count (length string))
      string
    (substring string (- 0 count))))


(defun stringlist-contains (list str)
  (let (elm (more 't) (res 'nil))
    (while (and more list)
      (if (symbolp (car list))
          (if (eq (car list) (intern str))
              (progn
                (setq more nil)
                (setq res 't)))
        (if (string= (car list) str)
              (progn
                (setq more nil)
                (setq res 't))))
      (setq list (cdr list)))
    res))

(defun stringlist-join (list str)
  (mapconcat (lambda (x) x) list str))


(defun string-simplified (str)
  (replace-in-string (replace-in-string str "^[ \t\n]+" "") "[ \t\n]+$" ""))

(provide 'kdab-qstring)