Adam Cameron
s = "abc"
s.each((c)=>{
//writeoutput(c.ucase()) // The ucase method was not found
writeOutput("#c.getClass().getName()#<br>") // java.lang.Character
writeOutput("#c.toString().ucase()#<br>") // sigh
})
writeOutput("<hr>")
a = s.split("")
c = a[1]
writeOutput("#c.ucase()#: #c.getClass().getName()#<br>") // A: java.lang.String
When using CF2021's string iteration functions, each element of the string is a java.lang.Character
, not a java.lang.String
. Ramifications: one cannot call string member functions on the char (obvs), eg: c.ucase()
. I say "obviously" because a Character is not a String, however it's NOT obvious in the context of CFML because Character is not a CFML data type, so there's no way a CFML function should return one / pass one.
I include as an example there that even Java doesn't split a string into individual Character objects. They're Strings.
I could not find a bug for this in the bugbase.
@Mark Takata (Adobe) just... why?bdw429s
05/20/2022, 10:15 PMAdam Cameron
Adam Cameron
Mark Takata (Adobe)
05/20/2022, 10:37 PMAdam Cameron
seancorfield
user=> (map class "abc")
(java.lang.Character java.lang.Character java.lang.Character)
user=> (map class (.split "abc" ""))
(java.lang.String java.lang.String java.lang.String)
user=>
seancorfield
user=> (require '[clojure.string :as str])
nil
user=> (str/upper-case \a)
"A"
user=> (map str/upper-case "abc")
("A" "B" "C")
user=> (map str/upper-case (.split "abc" ""))
("A" "B" "C")
user=>
Adam Cameron
ucase
function accepts Characters just fine (ie: change my example code to be ucase(c)
rather than c.ucase()
Adam Cameron
mithlond
05/23/2022, 3:04 PMucase
function accepts Characters"
given the docs say it accepts a string and doesn't mention accepting characters, I'd even lean towards saying "serendipitously happens to not blow up when passed Characters". If a minor update were to change it to blow up when passing a java Character object instead of a string, and there were no release notes on it, I'd not bat an eye.mithlond
05/23/2022, 3:05 PMmithlond
05/23/2022, 3:05 PMmithlond
05/23/2022, 3:06 PMAdam Cameron