Back
trimr (clj)
(source)function
(trimr s)
Removes whitespace from the right side of string.
Examples
clojure
(ns clojure.test-clojure.string
(:require [clojure.string :as s])
(:use clojure.test))
(deftest t-trimr
(is (= " foo" (s/trimr " foo ")))
(is (= "" (s/trimr " ")))
(is (= "bar" (s/trimr "bar\t \u2002"))))
(deftest nil-handling
(are [f args] (thrown? NullPointerException (apply f args))
s/reverse [nil]
s/replace [nil #"foo" "bar"]
s/replace-first [nil #"foo" "bar"]
s/re-quote-replacement [nil]
s/capitalize [nil]
s/upper-case [nil]
s/lower-case [nil]
s/split [nil #"-"]
s/split [nil #"-" 1]
s/trim [nil]
s/triml [nil]
s/trimr [nil]
s/trim-newline [nil]))
(deftest char-sequence-handling
(are [result f args] (let [[^CharSequence s & more] args]
(= result (apply f (StringBuffer. s) more)))
"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. "-")]
"\\\\ \\$" s/re-quote-replacement ["\\ $"]
"Pow" s/capitalize ["POW"]
"BOOM" s/upper-case ["boom"]
"whimper" s/lower-case ["whimPER"]
["foo" "bar"] s/split ["foo-bar" #"-"]
"calvino" s/trim [" calvino "]
"calvino " s/triml [" calvino "]
" calvino" s/trimr [" calvino "]
"the end" s/trim-newline ["the end\r\n\r\r\n"]
true s/blank? [" "]
["a" "b"] s/split-lines ["a\nb"]
"fa la la" s/escape ["fo lo lo" {\o \a}]))
clojure/clojure
(ns clojure.test-clojure.string
(:require [clojure.string :as s])
(:use clojure.test))
(deftest t-trimr
(is (= " foo" (s/trimr " foo ")))
(is (= "" (s/trimr " ")))
(is (= "bar" (s/trimr "bar\t \u2002"))))
(deftest nil-handling
(are [f args] (thrown? NullPointerException (apply f args))
s/reverse [nil]
s/replace [nil #"foo" "bar"]
s/replace-first [nil #"foo" "bar"]
s/re-quote-replacement [nil]
s/capitalize [nil]
s/upper-case [nil]
s/lower-case [nil]
s/split [nil #"-"]
s/split [nil #"-" 1]
s/trim [nil]
s/triml [nil]
s/trimr [nil]
s/trim-newline [nil]))
(deftest char-sequence-handling
(are [result f args] (let [[^CharSequence s & more] args]
(= result (apply f (StringBuffer. s) more)))
"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. "-")]
"\\\\ \\$" s/re-quote-replacement ["\\ $"]
"Pow" s/capitalize ["POW"]
"BOOM" s/upper-case ["boom"]
"whimper" s/lower-case ["whimPER"]
["foo" "bar"] s/split ["foo-bar" #"-"]
"calvino" s/trim [" calvino "]
"calvino " s/triml [" calvino "]
" calvino" s/trimr [" calvino "]
"the end" s/trim-newline ["the end\r\n\r\r\n"]
true s/blank? [" "]
["a" "b"] s/split-lines ["a\nb"]
"fa la la" s/escape ["fo lo lo" {\o \a}]))
clojure/clojurescript
(ns clojure.string-test
(:require [cljs.test :as test
:refer-macros [deftest is testing]]
[clojure.test.check :as tc]
[clojure.test.check.clojure-test :refer-macros [defspec]]
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :as prop :include-macros true]
[clojure.string :as s]))
(testing "Testing string trim"
(is (= "foo " (s/triml " foo ")))
(is (= "" (s/triml " ")))
(is (= " foo" (s/trimr " foo ")))
(is (= "" (s/trimr " ")))
(is (= "foo" (s/trim " foo \r\n"))))
(deftest char-sequence-handling
(are [result f args] (let [[^CharSequence s & more] args]
(= result (apply f (StringBuffer. s) more)))
"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. "-")]
"Pow" s/capitalize ["POW"]
"BOOM" s/upper-case ["boom"]
"whimper" s/lower-case ["whimPER"]
["foo" "bar"] s/split ["foo-bar" #"-"]
"calvino" s/trim [" calvino "]
"calvino " s/triml [" calvino "]
" calvino" s/trimr [" calvino "]
"the end" s/trim-newline ["the end\r\n\r\r\n"]
true s/blank? [" "]
["a" "b"] s/split-lines ["a\nb"]
"fa la la" s/escape ["fo lo lo" {\o \a}]))
)
arcadia-unity/Arcadia
(ns clojure.test-clojure.string
(:require [clojure.string :as s])
(:use clojure.test))
(deftest t-trimr
(is (= " foo" (s/trimr " foo ")))
(is (= "" (s/trimr " ")))
(is (= "bar" (s/trimr "bar\t \u2002"))))
(deftest nil-handling
(are [f args] (thrown? Exception (apply f args)) ;;; NullPointerException
s/reverse [nil]
s/replace [nil #"foo" "bar"]
s/replace-first [nil #"foo" "bar"]
;;;s/re-quote-replacement [nil] ;;; CLR no-op
s/capitalize [nil]
s/upper-case [nil]
s/lower-case [nil]
s/split [nil #"-"]
s/split [nil #"-" 1]
s/trim [nil]
s/triml [nil]
s/trimr [nil]
s/trim-newline [nil]))
;(deftest char-sequence-handling ;;; This tests StringBuffer : CharSequence -- irrelevant for ClojureCLR
; (are [result f args] (let [[^String s & more] args] ;;; CharSequence
; (= result (apply f (StringBuffer. s) more)))
; "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. "-")]
; "\\\\ \\$" s/re-quote-replacement ["\\ $"]
; "Pow" s/capitalize ["POW"]
; "BOOM" s/upper-case ["boom"]
; "whimper" s/lower-case ["whimPER"]
; ["foo" "bar"] s/split ["foo-bar" #"-"]
; "calvino" s/trim [" calvino "]
; "calvino " s/triml [" calvino "]
; " calvino" s/trimr [" calvino "]
; "the end" s/trim-newline ["the end\r\n\r\r\n"]
; true s/blank? [" "]
; ["a" "b"] s/split-lines ["a\nb"]
; "fa la la" s/escape ["fo lo lo" {\o \a}]))
clojure/clojure-clr
(ns clojure.test-clojure.string
(:require [clojure.string :as s])
(:use clojure.test))
(deftest t-trimr
(is (= " foo" (s/trimr " foo ")))
(is (= "" (s/trimr " ")))
(is (= "bar" (s/trimr "bar\t \u2002"))))
(deftest nil-handling
(are [f args] (thrown? Exception (apply f args)) ;;; NullPointerException
s/reverse [nil]
s/replace [nil #"foo" "bar"]
s/replace-first [nil #"foo" "bar"]
;;;s/re-quote-replacement [nil] ;;; CLR no-op
s/capitalize [nil]
s/upper-case [nil]
s/lower-case [nil]
s/split [nil #"-"]
s/split [nil #"-" 1]
s/trim [nil]
s/triml [nil]
s/trimr [nil]
s/trim-newline [nil]))
;(deftest char-sequence-handling ;;; This tests StringBuffer : CharSequence -- irrelevant for ClojureCLR
; (are [result f args] (let [[^String s & more] args] ;;; CharSequence
; (= result (apply f (StringBuffer. s) more)))
; "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. "-")]
; "\\\\ \\$" s/re-quote-replacement ["\\ $"]
; "Pow" s/capitalize ["POW"]
; "BOOM" s/upper-case ["boom"]
; "whimper" s/lower-case ["whimPER"]
; ["foo" "bar"] s/split ["foo-bar" #"-"]
; "calvino" s/trim [" calvino "]
; "calvino " s/triml [" calvino "]
; " calvino" s/trimr [" calvino "]
; "the end" s/trim-newline ["the end\r\n\r\r\n"]
; true s/blank? [" "]
; ["a" "b"] s/split-lines ["a\nb"]
; "fa la la" s/escape ["fo lo lo" {\o \a}]))
nasser/magic
(ns clojure.test-clojure.string
(:require [clojure.string :as s])
(:use clojure.test))
(deftest t-trimr
(is (= " foo" (s/trimr " foo ")))
(is (= "" (s/trimr " ")))
(is (= "bar" (s/trimr "bar\t \u2002"))))
(deftest nil-handling
(are [f args] (thrown? Exception (apply f args)) ;;; NullPointerException
s/reverse [nil]
s/replace [nil #"foo" "bar"]
s/replace-first [nil #"foo" "bar"]
;;;s/re-quote-replacement [nil] ;;; CLR no-op
s/capitalize [nil]
s/upper-case [nil]
s/lower-case [nil]
s/split [nil #"-"]
s/split [nil #"-" 1]
s/trim [nil]
s/triml [nil]
s/trimr [nil]
s/trim-newline [nil]))
;(deftest char-sequence-handling ;;; This tests StringBuffer : CharSequence -- irrelevant for ClojureCLR
; (are [result f args] (let [[^String s & more] args] ;;; CharSequence
; (= result (apply f (StringBuffer. s) more)))
; "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. "-")]
; "\\\\ \\$" s/re-quote-replacement ["\\ $"]
; "Pow" s/capitalize ["POW"]
; "BOOM" s/upper-case ["boom"]
; "whimper" s/lower-case ["whimPER"]
; ["foo" "bar"] s/split ["foo-bar" #"-"]
; "calvino" s/trim [" calvino "]
; "calvino " s/triml [" calvino "]
; " calvino" s/trimr [" calvino "]
; "the end" s/trim-newline ["the end\r\n\r\r\n"]
; true s/blank? [" "]
; ["a" "b"] s/split-lines ["a\nb"]
; "fa la la" s/escape ["fo lo lo" {\o \a}]))