1.2.0 permalink Arrow_down_16x16
  • (swap-case s)
Changes upper case characters to lower case and vice-versa.
Handles Unicode supplementary characters correctly. Uses the
locale-sensitive String.toUpperCase() and String.toLowerCase()
methods.

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/str_utils2.clj:270 top

(defn ^String swap-case
  "Changes upper case characters to lower case and vice-versa.
  Handles Unicode supplementary characters correctly.  Uses the
  locale-sensitive String.toUpperCase() and String.toLowerCase()
  methods."
  [^String s]
  (let [buffer (StringBuilder. (.length s))
        ;; array to make a String from one code point
        ^"[I" array (make-array Integer/TYPE 1)]
    (docodepoints [c s]
      (aset-int array 0 c)
      (if (Character/isLowerCase c)
        ;; Character.toUpperCase is not locale-sensitive, but
        ;; String.toUpperCase is; so we use a String.
        (.append buffer (.toUpperCase (String. array 0 1)))
        (.append buffer (.toLowerCase (String. array 0 1)))))
    (.toString buffer)))
Vars in clojure.contrib.str-utils2/swap-case: aset-int defn let
Used in 0 other vars

Comments top

No comments for swap-case. Log in to add a comment.