Camel case and snake case: Difference between revisions

Content added Content deleted
(Added Easylang)
No edit summary
 
Line 1,669: Line 1,669:
c://my-docs/happy_Flag-Day/12.doc → c://myDocs/happyFlagDay/12.doc
c://my-docs/happy_Flag-Day/12.doc → c://myDocs/happyFlagDay/12.doc
spaces → spaces
spaces → spaces
</pre>

=={{header|OmniMark}}==
<syntaxhighlight lang="omnimark">
define stream function to_snake_case (value stream txt) as
local stream ls
open ls as buffer
repeat scan txt
match white-space* value-end
; "trailing whitespace may be ignored"
match value-start white-space*
; "leading ... whitespace may be ignored"
match (lc | digit) => char1 uc => char2
put ls '%x(char1)_%lx(char2)'
match ('_' | space | "-" | '.')
; normalise to underscore and lowercase letter
put ls '_'
match any => char
; all other characters are lowercase
put ls '%lx(char)'
again
close ls
return ls

define stream function toCamelCase (value stream txt) as
local stream ls
open ls as buffer
repeat scan txt
match white-space* value-end
; "trailing whitespace may be ignored"
match value-start white-space* letter+ => word1
; "leading ... whitespace may be ignored"
put ls word1
match ('_' | space | "-" | '.') any => makeUpper
; consume dividing underscore, space, hyphen or full stop
put ls '%ux(makeUpper)'
match ([digit] letter) => chars
; a letter preceded by a numeral should be uppercase
put ls '%ux(chars)'
match any => char
; all other characters are lowercase
put ls '%lx(char)'
again
close ls
return ls

process
local stream ls variable initial {"snakeCase", "snake_case",
"variable_10_case", "variable10Case",
"ɛrgo rE tHis", "hurry-up-joe!", "c://my-docs/happy_Flag-Day/12.doc",
" spaces "}
output 'to_snake_case%n'
output '=============%n'
repeat over ls
output ls || ' => ' || to_snake_case(ls) || '%n'
again
output '%n'
output 'toCamelCase%n'
output '===========%n'
repeat over ls
output ls || ' => ' || toCamelCase(ls) || '%n'
again
</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

toCamelCase
===========
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/12Doc
spaces => spaces
</pre>
</pre>