-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
str.clj
42 lines (35 loc) · 1.14 KB
/
str.clj
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
(ns polylith.clj.core.util.str
(:require [clojure.string :as str]
[polylith.clj.core.util.core :as core]))
(defn take-until [string separator]
(when string
(let [index (str/index-of string separator)]
(when index
(subs string 0 index)))))
(defn skip-until [string separator]
(when string
(let [index (str/index-of string separator)]
(when index
(subs string (+ (count separator) index))))))
(defn skip-prefix [string prefix]
(when string
(if (str/starts-with? string prefix)
(subs string (count prefix))
string)))
(defn skip-suffix [string suffix]
(when string
(if (str/ends-with? string suffix)
(let [string-cnt (count string)
suffix-cnt (count suffix)]
(if (< suffix-cnt string-cnt)
(subs string 0 (- string-cnt suffix-cnt))
string))
string)))
(defn skip-suffixes [string suffixes]
(if-let [suffix (core/find-first #(str/ends-with? string %) suffixes)]
(skip-suffix string suffix)
string))
(defn spaces [length]
(str/join (take length (repeat " "))))
(defn line [length]
(str/join (take length (repeat "-"))))