Add a method for casting into byte string or unicode depending on python version

This commit is contained in:
Guillermo Vaya 2013-10-03 23:38:30 +02:00
parent 9ea153fd7e
commit 25bf3dec42
2 changed files with 11 additions and 1 deletions

View File

@ -177,6 +177,12 @@
"Return second item from `coll`"
(get coll 1))
(defn string [x]
"Cast x as current string implementation"
(if-python2
(unicode x)
(str x)))
(defn string? [x]
"Return True if x is a string"
(if-python2
@ -218,5 +224,5 @@
"even?" "filter" "float?" "inc"
"instance?" "integer?" "iterable?" "iterate" "iterator?" "neg?"
"none?" "nth" "numeric?" "odd?" "pos?" "remove" "repeat"
"repeatedly" "second" "string?" "take" "take_nth" "take_while"
"repeatedly" "second" "string" "string?" "take" "take_nth" "take_while"
"zero?"])

View File

@ -779,3 +779,7 @@
"Evaluate an empty list to a []"
(assert (= () [])))
(defn test-string []
(assert (string? (string "a")))
(assert (string? (string 1)))
(assert (= u"unicode" (string "unicode"))))