Permalink
Browse files

Shorten cp-escape definition using docodepoints, and eliminate bad co…

…py-and-paste line
  • Loading branch information...
1 parent 2652bb4 commit 03c2f0f0b98bd7557a625e2ce9513262344382b5 @jafingerhut committed Jan 18, 2012
Showing with 6 additions and 18 deletions.
  1. +6 −18 src/com/fingerhutpress/text/unicode.clj
View
24 src/com/fingerhutpress/text/unicode.clj
@@ -207,22 +207,10 @@
The behavior is undefined if s is not a valid UTF-16 string, as
determined by function utf16?"
- {:added "1.2"}
[^CharSequence s cmap]
- (let [len (.length s)
- buffer (StringBuilder. len)]
- (loop [i 0]
- (if (< i len)
- (let [c (.charAt s i)]
- (if (Character/isHighSurrogate c)
- (let [cp (.codePointAt s i)]
- (if-let [replacement (cmap cp)]
- (.append buffer replacement)
- (.appendCodePoint buffer cp))
- (recur (+ i 2)))
- (let [cp (int c)]
- (if-let [replacement (cmap cp)]
- (.append buffer replacement)
- (.appendCodePoint buffer cp))
- (recur (inc i)))))
- (.toString buffer)))))
+ (let [buffer (StringBuilder. (count s))]
+ (docodepoints [c s]
+ (if-let [replacement (cmap c)]
+ (.append buffer replacement)
+ (.appendCodePoint buffer c)))
+ (.toString buffer)))

0 comments on commit 03c2f0f

Please sign in to comment.