Skip to content

Commit

Permalink
minor fixes to #359:
Browse files Browse the repository at this point in the history
  - add clojure.string to build,
  - make replace,replace-first use CharSequence in same way

Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information
stuarthalloway committed Jun 4, 2010
1 parent 8c8fc40 commit fc8af8c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
<arg value="clojure.java.javadoc"/>
<arg value="clojure.java.shell"/>
<arg value="clojure.java.browse-ui"/>
<arg value="clojure.string"/>
</java>
</target>

Expand Down
5 changes: 3 additions & 2 deletions src/clj/clojure/string.clj
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ clojure.string adheres to the following design principles:
(cond
(instance? Character match) (.replace s ^Character match ^Character replacement)
(instance? CharSequence match) (.replace s ^CharSequence match ^CharSequence replacement)
(instance? Pattern match) (if (string? replacement)
(.replaceAll (re-matcher ^Pattern match s) ^CharSequence replacement)
(instance? Pattern match) (if (instance? CharSequence replacement)
(.replaceAll (re-matcher ^Pattern match s)
(.toString replacement))
(replace-by s match replacement))
:else (throw (IllegalArgumentException. (str "Invalid match arg: " match))))))

Expand Down
1 change: 1 addition & 0 deletions test/clojure/test_clojure/string.clj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"paz" s/reverse ["zap"]
"foo:bar" s/replace ["foo-bar" \- \:]
"ABC" s/replace ["abc" #"\w" s/upper-case]
"faa" s/replace ["foo" #"o" (StringBuffer. "a")]
"baz::quux" s/replace-first ["baz--quux" #"--" "::"]
"baz::quux" s/replace-first ["baz--quux" (StringBuffer. "--") (StringBuffer. "::")]
"zim-zam" s/replace-first ["zim zam" #" " (StringBuffer. "-")]
Expand Down

0 comments on commit fc8af8c

Please sign in to comment.