File tree Expand file tree Collapse file tree 2 files changed +14
-11
lines changed Expand file tree Collapse file tree 2 files changed +14
-11
lines changed Original file line number Diff line number Diff line change 67
67
68
68
; ; ## Constructors
69
69
70
+ (defn- string-of?
71
+ [^String s pred]
72
+ (and s
73
+ (string? s)
74
+ (pos? (.length s))
75
+ (every? pred s)))
76
+
70
77
(defn whitespace-node
71
78
" Create whitespace node."
72
79
[s]
73
- {:pre [(string? s)
74
- (re-matches #"\s +" s)
75
- (not (re-matches #".*[\n\r ].*" s))]}
80
+ {:pre [(string-of? s r/space?)]}
76
81
(->WhitespaceNode s))
77
82
78
83
(defn comma-node
79
84
" Create comma node."
80
85
[s]
81
- {:pre [(string? s)
82
- (re-matches #",+" s)]}
86
+ {:pre [(string-of? s r/comma?)]}
83
87
(->CommaNode s))
84
88
85
89
(defn newline-node
86
90
" Create newline node."
87
91
[s]
88
- {:pre [(string? s)
89
- (re-matches #"[\n\r ]+" s)]}
92
+ {:pre [(string-of? s r/linebreak?)]}
90
93
(->NewlineNode s))
91
94
92
95
(defn- classify-whitespace
98
101
(defn whitespace-nodes
99
102
" Convert a string of whitespace to whitespace/newline nodes."
100
103
[s]
101
- {:pre [(string? s)
102
- (re-matches #"(\s |,)+" s)]}
104
+ {:pre [(string-of? s r/whitespace?)]}
103
105
(->> (partition-by classify-whitespace s)
104
106
(map
105
107
(fn [char-seq]
Original file line number Diff line number Diff line change 44
44
45
45
(defn space?
46
46
[^java.lang.Character c]
47
- (and (whitespace? c)
48
- (not (linebreak? c))))
47
+ (and c
48
+ (Character/isWhitespace c)
49
+ (not (contains? #{\newline \return \,} c))))
49
50
50
51
(defn whitespace-or-boundary?
51
52
[c]
You can’t perform that action at this time.
0 commit comments