Camel case and snake case: Difference between revisions

Added Easylang
(Add Kotlin implementation)
(Added Easylang)
 
(One intermediate revision by one other user not shown)
Line 680:
 
 
 
=={{header|EasyLang}}==
{{trans|Nim}}
<syntaxhighlight>
func$ strip s$ .
a = 1
while substr s$ a 1 = " "
a += 1
.
b = len s$
while substr s$ b 1 = " "
b -= 1
.
return substr s$ a (b - a + 1)
.
func$ toupper c$ .
c = strcode c$
if c >= 97 and c <= 122
c$ = strchar (c - 32)
.
return c$
.
func$ tolower c$ .
c = strcode c$
if c >= 65 and c <= 90
c$ = strchar (c + 32)
.
return c$
.
func isupper c$ .
c = strcode c$
if c >= 65 and c <= 90
return 1
.
.
delim$ = "_- "
func$ snakecase s$ .
s$ = strip s$
for c$ in strchars s$
if isupper c$ = 1 and prev$ <> ""
if strpos delim$ prev$ = 0
r$ &= "_"
.
r$ &= tolower c$
else
r$ &= c$
.
prev$ = c$
.
return r$
.
func$ camelcase s$ .
s$ = strip s$
prev$ = "x"
for c$ in strchars s$
if strpos delim$ prev$ <> 0
r$ &= toupper c$
elif strpos delim$ c$ = 0
r$ &= c$
.
prev$ = c$
.
return r$
.
test$[] = [ "snakeCase" "snake_case" "variable_10_case" "variable10Case" "ɛrgo rE tHis" "hurry-up-joe!" "c://my-docs/happy_Flag-Day/12.doc" " spaces " ]
print "=== To snake_case ==="
for s$ in test$[]
print s$ & " -> " & snakecase s$
.
print "\n=== To camelCase ==="
for s$ in test$[]
print s$ & " -> " & camelcase s$
.
</syntaxhighlight>
{{out}}
<pre>
=== To snake_case ===
snakeCase -> snake_case
snake_case -> snake_case
variable_10_case -> variable_10_case
variable10Case -> variable10_case
ɛrgo rE tHis -> ɛrgo r_e t_his
hurry-up-joe! -> hurry-up-joe!
c://my-docs/happy_Flag-Day/12.doc -> c://my-docs/happy_flag-day/12.doc
spaces -> spaces
 
=== To camelCase ===
snakeCase -> snakeCase
snake_case -> snakeCase
variable_10_case -> variable10Case
variable10Case -> variable10Case
ɛrgo rE tHis -> ɛrgoRETHis
hurry-up-joe! -> hurryUpJoe!
c://my-docs/happy_Flag-Day/12.doc -> c://myDocs/happyFlagDay/12.doc
spaces -> spaces
</pre>
 
=={{header|Factor}}==
Line 2,171 ⟶ 2,267:
spaces ==> spaces</pre>
 
 
=={{header|RPL}}==
« 1
'''WHILE''' DUP2 DUP SUB " " == '''REPEAT''' 1 + '''END'''
OVER DUP SIZE
'''WHILE''' DUP2 DUP SUB " " == '''REPEAT''' 1 - '''END'''
SWAP DROP SUB
» '<span style="color:blue">TRIM</span>' STO
« <span style="color:blue">TRIM</span> → s
« ""
1 s SIZE '''FOR''' j
s j DUP SUB
'''CASE'''
"- " OVER POS '''THEN'''
DROP "_" '''END'''
DUP "A" ≥ OVER "Z" ≤ AND '''THEN'''
NUM 32 + CHR
'''IF''' OVER DUP SIZE DUP SUB "_" ≠ '''THEN''' "_" SWAP + '''END'''
'''END'''
'''END'''
+
'''NEXT'''
» » '<span style="color:blue">→SNAKE</span>' STO
« <span style="color:blue">TRIM</span> → s
« "" 1 CF
1 s SIZE '''FOR''' j
s j DUP SUB
'''CASE'''
"-_ " OVER POS '''THEN'''
DROP "" 1 SF '''END'''
DUP "a" ≥ OVER "z" ≤ AND 1 FS?C AND '''THEN'''
NUM 32 - CHR '''END'''
'''END'''
+
'''NEXT'''
» » '<span style="color:blue">→CAMEL</span>' STO
« { "snakeCase" "snake_case" "variable_10_case" "variable10Case"
"εrgo rE tHis" "hurry-up-joe!" "c://my-docs/happy_Flag-Day/12.doc" " spaces " }
DUP 1 « <span style="color:blue">→SNAKE</span> » DOLIST
SWAP 1 « <span style="color:blue">→CAMEL</span> » DOLIST
» '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
2: { "snake_case" "snake_case" "variable_10_case" "variable10_case" "εrgo_r_e_t_his" "hurry_up_joe!" "c://my_docs/happy_flag_day/12.doc" "spaces" }
1: { "snakeCase" "snakeCase" "variable10Case" "variable10Case" "εrgoRETHis" "hurryUpJoe!" "c://myDocs/happyFlagDay/12.doc" "spaces" }
</pre>
 
=={{header|Scala}}==
Line 2,238 ⟶ 2,383:
 
</pre>
 
 
=={{header|V (Vlang)}}==
2,053

edits