How to resolve the algorithm Camel case and snake case step by step in the FutureBasic programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Camel case and snake case step by step in the FutureBasic programming language

Table of Contents

Problem Statement

Two common conventions for naming of computer program variables are Snake Case and Camel Case. Snake case variables are generally all lower case, with an underscore between words in the variable, as in snake_case_variable'. Camel case variables are generally lower case first (except in some Pascal conventions or with class names in many other languages), with captalization of the initial letter of the words within the variable, as in 'camelCaseVariable'. Leading underscores are not used in such variables except as part of a different naming convention, usually for special internal or system variables. White space is not permitted as part of camel case or snake case variable names.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Camel case and snake case step by step in the FutureBasic programming language

Source code in the futurebasic programming language

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

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"

  

You may also check:How to resolve the algorithm Factors of an integer step by step in the Clojure programming language
You may also check:How to resolve the algorithm Delete a file step by step in the Vedit macro language programming language
You may also check:How to resolve the algorithm Terminal control/Clear the screen step by step in the jq programming language
You may also check:How to resolve the algorithm String append step by step in the K programming language
You may also check:How to resolve the algorithm Amb step by step in the Ruby programming language