A Clojure library for fast string operations. (See the Development section to run performance benchmarks.)
Leiningen coordinates: [stringer "0.3.1"]
(require '[stringer.core :as s])
strcat
is a macro that accepts arguments to concatenate as a string.
(s/strcat "foo" :bar 707 nil 'baz)
=> "foo:bar707baz"
strdel
is a macro that accepts delimiter as first argument, and tokens as
the remaining arguments.
(s/strdel ", " "foo" :bar 707 nil 'baz)
=> "foo, :bar, 707, , baz"
strfmt
is a macro that accepts format-string as first argument, and format
parameters as arguments.
(s/strfmt "Hello %s, here are %d products costing %f each." "human" 42 23.35)
=> "Hello human, here are 42 products costing 23.35 each."
Note: Only limited format-specifier support exists. See CHANGES.md for details.
(s/with-obj-str w
(.append w "foo")
(.append w 707))
=> "foo707"
There are append!
, join-all!
and join!
macros to work with StringBuilder
.
(s/with-obj-str w
(s/append! w "foo" :bar 707 nil 'baz)
(s/join-all! w ", " :quux :norf)
(s/join! w \| ["quick" "brown" "fox"]))
=> "foo:bar707baz:quux, :norfquick|brown|fox"
The local can be bound to something else too:
(s/with-obj-str [w (java.util.ArrayList.)]
(.add w 1)
(.add w 2)
(.add w 3))
=> "[1, 2, 3]"
The strtbl
function generates string representation of a textual table equivalent to clojure.pprint/print-table
.
(println (s/strtbl
[{:name "Bill" :age 32 :gender :male}
{:name "Anna" :age 47 :gender :female}
{:name "Ravi" :age 39 :gender :male}]))
Exception in thread "main" java.lang.IllegalArgumentException: More than one matching method found: append, compiling:(...)
Maybe you have nil
as one of the non type-hinted arguments? Provide a type hint ^Object
.strfmt
macro expects the first argument, i.e. the format string, to be a string at compile time.With Clojure 1.6: lein with-profile c06,perf do clean, test
With Clojure 1.7: lein with-profile c07,perf do clean, test
With Clojure 1.8: lein with-profile c08,perf do clean, test
With Clojure 1.9: lein with-profile c09,perf do clean, test
To run with Clojure 1.6, 1.7, 1.8 and 1.9 in order: lein cascade perf
If you are running the tests on a laptop, connect it to the power supply (so that the CPU is not clocked down) and turn the screensaver/suspend off.
Copyright © 2015-2018 Shantanu Kumar (kumar.shantanu@gmail.com, shantanu.kumar@concur.com)
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close