-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert-text-to-uppercase-or-lowercase
35 lines (29 loc) · 1.16 KB
/
convert-text-to-uppercase-or-lowercase
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
:global strcase do={
:local toreplaceL {"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";"X"="x";"Z"="z";"Y"="y";"W"="w"};
:local toreplaceU {"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";"x"="X";"z"="Z";"y"="Y";"w"="W"};
:local toreplace $toreplaceL;
:local str $1;
:local newStr;
:local newChar;
:if ($2 = "-u") do={
:set toreplace $toreplaceU;
}
:for i from=0 to=([:len $str] - 1) do={
:local char [:pick $str $i];
:set newChar ($toreplace->$char);
:if ([:typeof $newChar] = "str") do={
:set char $newChar;
}
:set newStr ($newStr . $char);
}
:return $newStr;
}
:global tolower do={ :global strcase; return [$strcase $1]};
:global toupper do={ :global strcase; return [$strcase $1 -u]}
# ---------------------------------
# Output:
# ---------------------------------
:put [$toupper "www.goonet.com.br"]
WWW.GOONET.COM.BR
:put [$tolower "WwW.GooNeT.CoM.Br"]
www.goonet.com.br