[cl-json-devel] Contrib: simplified camel case

Henrik Hjelte henrik at evahjelte.com
Mon Aug 10 20:07:56 UTC 2009


On Wed, Aug 5, 2009 at 10:08 AM, Leslie P.
Polzer<sky at 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\"
               }"))))))




More information about the cl-json-devel mailing list