made uppercase/lowercase easily expandable
@@ -31,6 +31,9 @@ trim = (
return $.substr(string, start, end) if start < end else ""
}
+uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+lowercase = "abcdefghijklmnopqrstuvwxyz"
+
impl @string {
is_empty: #[desc("Returns true if the string has a length of 0, false otherwise") example("
$.assert(''.is_empty())
@@ -105,12 +108,12 @@ $.assert('example'.split('') == ['e', 'x', 'a', 'm', 'p', 'l', 'e'])
},
lowercase: #[desc("Makes whole string lowercase.")]
(self) {
- dict = {A:'a',B:'b',C:'c',D:'d',E:'e',F:'f',G:'g',H:'h',I:'i',J:'j',K:'k',L:'l',M:'m',N:'n',O:'o',P:'p',Q:'q',R:'r',S:'s',T:'t',U:'u',V:'v',W:'w',X:'x',Y:'y',Z:'z'}
+ dict = @zip::new(uppercase,lowercase) as @dictionary
return ''.join(self.split('').map(el => dict.get(el, el)))
},
uppercase: #[desc("Makes whole string uppercase.")]
(self) {
- dict = {a:'A',b:'B',c:'C',d:'D',e:'E',f:'F',g:'G',h:'H',i:'I',j:'J',k:'K',l:'L',m:'M',n:'N',o:'O',p:'P',q:'Q',r:'R',s:'S',t:'T',u:'U',v:'V',w:'W',x:'X',y:'Y',z:'Z'}
+ dict = @zip::new(lowercase,uppercase) as @dictionary
return ''.join(self.split('').map(el => dict.get(el, el)))
},
is_upper: #[desc("Checks if whole string is uppercase, ignores characters that is not in the alphabet.")]
