Camel case and snake case: Difference between revisions

(Added FreeBasic)
Line 806:
Sleep</syntaxhighlight>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
 
include "NSLog.incl"
local fn snake_toCamel( s as CFStringRef ) as CFStringRef
long r,f
s = fn StringByTrimmingCharactersInSet( s, fn CFCharacterSetGetPredefined(_kCFCharacterSetWhitespace ))
for r = 1 to len(s)-2
f = instr(0, @"_- ", mid(s, r, 1))
if f <> NSNotFound
s = fn stringwithformat(@"%@%@%@", left( s, r ), ucase(mid(s,r+1,1)), mid(s,r+2))
end if
next
end fn = s
 
local fn CamelTo_snake( s as CFStringRef ) as CFStringRef
long r,f
s = fn StringByTrimmingCharactersInSet( s, fn CFCharacterSetGetPredefined(_kCFCharacterSetWhitespace ))
s = fn StringByReplacingOccurrencesOfString( s, @" ", @"_")
s = fn StringByReplacingOccurrencesOfString( s, @"-", @"_")
for r = 1 to len(s)-2
f = instr(0, @"ABCDEFGHIJKLMNOPQRSTUVWXYZ", mid(s, r, 1))
if f <> NSNotFound
if fn StringIsEqual(@"_", mid(s, r-1, 1)) then continue
s = fn stringwithformat(@"%@%@%@", left( s, r ), @"_", mid(s,r))
end if
next
s = fn stringwithformat(@"%@%@",left( s, 1), lcase(mid(s, 1)))
end fn = s
 
local fn show( s1 as CFStringRef )
CFStringRef s = @" "
CFStringRef s2 = fn snake_toCamel( s1 )
CFStringRef s3 = fn CamelTo_snake( s1 )
nslog(@" \"%@\"%@\"%@\"%@\"%@\"", s1, mid(s, len(s1)), s2, mid(s, len(s2)), s3)
end fn
 
nslog( @"%@",@"String ¬
fn snake_toCamel ¬
fn CamelTo_snake")
fn show(@"snakeCase")
fn show(@"snake_case")
fn show(@"variable_10_case")
fn show(@"variable10Case")
fn show(@"ɛrgo rE tHis")
fn show(@"hurry-up-joe!")
fn show(@"c://my-docs/happy_Flag-Day/12.doc")
fn show(@" spaces ")
 
handleevents
</syntaxhighlight>
{{out}}
<syntaxhighlight lang="futurebasic">
String fn snake_toCamel fn CamelTo_snake
"snakeCase" "snakeCase" "snake_case"
"snake_case" "snakeCase" "snake_case"
"variable_10_case" "variable10Case" "variable_10_case"
"variable10Case" "variable10Case" "variable10_case"
"ɛrgo rE tHis" "ɛrgoRETHis" "ɛrgo_r_e_t_his"
"hurry-up-joe!" "hurryUpJoe!" "hurry_up_joe!"
" spaces " "spaces" "spaces"
"c://my-docs/happy_Flag-Day/12.doc" "c://myDocs/happyFlagDay/12.doc" "c://my_docs/happy_flag_day/12.doc"
</syntaxhighlight>
=={{header|Java}}==
The output of this example reflects the authors interpretation of the task.
68

edits