ryoakg
12/1/2016 - 1:22 AM

exchange-symbol-notation.clj

(require '[clojure.string :as str])

(defn- split-camel-case [x]
  (-> x
      (str/replace #"([a-z])([A-Z])" "$1\n$2")
      (str/split #"\n")))


;;; camel-case => kebab-case
(-> "getDataSchemeSpecificParts"
    split-camel-case
    (->> (str/join "-"))
    str/lower-case)
;; => "get-data-scheme-specific-parts"

;;; camel-case => snake-case
(-> "getDataSchemeSpecificParts"
    split-camel-case
    (->> (str/join "_"))
    str/lower-case)
;; => "get_data_scheme_specific_parts"


;;; kebab-case => camel-case(1)
(-> "get-data-scheme-specific-parts"
    (str/split #"-")
    (->> (map str/capitalize)
         str/join))
;; => "GetDataSchemeSpecificParts"


;;; kebab-case => camel-case(2)
(let [[x & xs] (-> "get-data-scheme-specific-parts"
                   (str/split #"-"))]
  (->> (map str/capitalize xs)
       (cons x)
       str/join))
;; => "getDataSchemeSpecificParts"