Skip to content

Instantly share code, notes, and snippets.

@tbatchelli
Created October 19, 2010 04:36
Show Gist options
  • Save tbatchelli/633618 to your computer and use it in GitHub Desktop.
Save tbatchelli/633618 to your computer and use it in GitHub Desktop.
(ns vmfest.util
(:import java.lang.Character))
(defn case-type [c]
(when-not (nil? c)
(if (Character/isUpperCase c) :U :L)))
(defn camel-to-clojure-style* [words current-word remaining-name last-char next-char]
(println words " " current-word " " remaining-name " " last-char " " next-char)
(let [last-char-case (case-type last-char)
next-char-case (case-type next-char)
next-step (fn [first-case-type second-case-type])]
(println {last-char-case next-char-case})
(case [last-char-case next-char-case]
[nil nil]
(conj words current-word)
([:U nil] [:L nil])
(conj words current-word) ;; we're done!
([nil :U] [nil :L])
(recur words (conj current-word next-char) (rest remaining-name) next-char (first remaining-name))
[:U :U]
(recur words (conj current-word next-char) (rest remaining-name) next-char (first remaining-name))
[:L :U]
(recur (conj words current-word) [next-char] (rest remaining-name) nil (first remaining-name))
[:U :L]
(recur (conj words (vec (butlast current-word))) [last-char next-char] (rest remaining-name) next-char (first remaining-name))
[:L :L]
(recur words (conj current-word next-char) (rest remaining-name) next-char (first remaining-name)))))
(defn camel-to-clojure-style [name]
(let [first-char (first name)
rest-of-name (rest name)]
(camel-to-clojure-style* [] [] rest-of-name nil first-char)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment