You might want to include this in camel-case.lisp or contrib. It's barely tested so far though.
(defun simplified-camel-case-to-lisp (camel-string) "We don't want + and * all over the place." (declare (string camel-string)) (let ((*print-pretty* nil)) (with-output-to-string (result) (loop for c across camel-string with last-was-lowercase when (and last-was-lowercase (upper-case-p c)) do (princ "-" result) if (lower-case-p c) do (setf last-was-lowercase t) else do (setf last-was-lowercase nil) do (princ (char-upcase c) result)))))
Leslie
On Wed, Aug 5, 2009 at 10:08 AM, Leslie P. Polzersky@viridian-project.de wrote:
You might want to include this in camel-case.lisp or contrib. It's barely tested so far though.
I have added the simplified-camel-case-to-lisp function and made a testcase that shows how it differs to the ordinary camel-case-to-lisp (below) For the speed hungry, it seems a bit faster than the ordinary camel-case-to-lisp (performance test also in a new testcase).
Thanks a lot, Henrik
(test json-object-camel-case (with-decoder-simple-list-semantics (let ((*json-symbols-package* (find-package :keyword))) (is (equalp '((:hello-key . "hej") (:*hi-starts-with-upper-case . "tjena") (:+json+-all-capitals . "totae majusculae") (:+two-words+ . "duo verba") (:camel-case--*mixed--+4-parts+ . "partes miscella quatuor")) (decode-json-from-string " { "helloKey" : "hej" , "HiStartsWithUpperCase" : "tjena", "JSONAllCapitals": "totae majusculae", "TWO_WORDS": "duo verba", "camelCase_Mixed_4_PARTS": "partes miscella quatuor" }"))))))
(test json-object-simplified-camel-case ;; Compare this with json-object-camel-case above (with-decoder-simple-list-semantics (let ((*json-symbols-package* (find-package :keyword)) (*json-identifier-name-to-lisp* #'simplified-camel-case-to-lisp)) (is (equalp '((:hello-key . "hej") (:hi-starts-with-upper-case . "tjena") (:jsonall-capitals . "totae majusculae") (:two_words . "duo verba") (:camel-case_mixed_4_parts . "partes miscella quatuor")) (decode-json-from-string " { "helloKey" : "hej" , "HiStartsWithUpperCase" : "tjena", "JSONAllCapitals": "totae majusculae", "TWO_WORDS": "duo verba", "camelCase_Mixed_4_PARTS": "partes miscella quatuor" }"))))))