Title: | Convert Strings into any Case |
---|---|
Description: | A consistent, flexible and easy to use tool to parse and convert strings into cases like snake or camel among others. |
Authors: | Malte Grosser [aut, cre] |
Maintainer: | Malte Grosser <[email protected]> |
License: | GPL-3 |
Version: | 0.11.1 |
Built: | 2024-12-14 02:49:33 UTC |
Source: | https://github.com/Tazinho/snakecase |
parsing_option
1 is needed, but some abbreviations need parsing_option
2.Internal abbreviation marker, marks abbreviations with an underscore behind.
Useful if parsing_option
1 is needed, but some abbreviations need parsing_option
2.
abbreviation_internal(string, abbreviations = NULL)
abbreviation_internal(string, abbreviations = NULL)
string |
A string (for example names of a data frame). |
abbreviations |
character with (uppercase) abbreviations. This marks
abbreviations with an underscore behind (in front of the parsing).
Useful if |
A character vector.
Malte Grosser, [email protected]
Wrappers around to_any_case()
to_snake_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_lower_camel_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_upper_camel_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_screaming_snake_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_parsed_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_mixed_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_lower_upper_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_upper_lower_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_swap_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_sentence_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_random_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_title_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "")
to_snake_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_lower_camel_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_upper_camel_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_screaming_snake_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_parsed_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_mixed_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_lower_upper_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_upper_lower_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_swap_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_sentence_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_random_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "") to_title_case(string, abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = "middle", sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "")
string |
A string (for example names of a data frame). |
abbreviations |
character. (Case insensitive) matched abbreviations are surrounded by underscores. In this way, they can get recognized by the parser. This is useful when e.g. Use this feature with care: One letter abbreviations and abbreviations next to each other are hard to read and also not easy to parse for further processing. |
sep_in |
(short for separator input) if character, is interpreted as a
regular expression (wrapped internally into |
parsing_option |
An integer that will determine the parsing_option.
|
transliterations |
A character vector (if not |
numerals |
A character specifying the alignment of numerals ( |
sep_out |
(short for separator output) String that will be used as separator. The defaults are |
unique_sep |
A string. If not |
empty_fill |
A string. If it is supplied, then each entry that matches "" will be replaced by the supplied string to this argument. |
prefix |
prefix (string). |
postfix |
postfix (string). |
A character vector according the specified parameters above.
A character vector according the specified target case.
caseconverters are vectorised over string
, sep_in
, sep_out
,
empty_fill
, prefix
and postfix
.
Malte Grosser, [email protected]
Malte Grosser, [email protected]
snakecase on github, to_any_case
for flexible high level conversion and more examples.
strings <- c("this Is a Strange_string", "AND THIS ANOTHER_One", NA) to_snake_case(strings) to_lower_camel_case(strings) to_upper_camel_case(strings) to_screaming_snake_case(strings) to_lower_upper_case(strings) to_upper_lower_case(strings) to_parsed_case(strings) to_mixed_case(strings) to_swap_case(strings) to_sentence_case(strings) to_random_case(strings) to_title_case(strings)
strings <- c("this Is a Strange_string", "AND THIS ANOTHER_One", NA) to_snake_case(strings) to_lower_camel_case(strings) to_upper_camel_case(strings) to_screaming_snake_case(strings) to_lower_upper_case(strings) to_upper_lower_case(strings) to_parsed_case(strings) to_mixed_case(strings) to_swap_case(strings) to_sentence_case(strings) to_random_case(strings) to_title_case(strings)
to_any_case()
Internal helper to test the design rules for any string and setting of to_any_case()
check_design_rule(string, sep_in = NULL, transliterations = NULL, sep_out = NULL, prefix = "", postfix = "", unique_sep = NULL, empty_fill = NULL, parsing_option = 1)
check_design_rule(string, sep_in = NULL, transliterations = NULL, sep_out = NULL, prefix = "", postfix = "", unique_sep = NULL, empty_fill = NULL, parsing_option = 1)
string |
A string (for example names of a data frame). |
sep_in |
String that will be wrapped internally into |
transliterations |
A character vector (if not |
sep_out |
String that will be used as separator. The defaults are |
prefix |
prefix (string). |
postfix |
postfix (string). |
unique_sep |
A string. If it is supplied, then duplicated names will get a suffix integer in the order of their appearance. The suffix is separated by the supplied string to this argument. |
empty_fill |
A string. If it is supplied, then each entry that matches "" will be replaced by the supplied string to this argument. |
parsing_option |
An integer that will determine the parsing_option.
|
A character vector separated by underscores, containing the parsed string.
Malte Grosser, [email protected]
Mainly for usage within to_parsed_case_internal
parse1_pat_cap_smalls(string) parse2_pat_digits(string) parse3_pat_caps(string) parse4_pat_cap(string) parse5_pat_non_alnums(string) parse6_mark_digits(string) parse7_pat_caps_smalls(string) parse8_pat_smalls_after_non_alnums(string)
parse1_pat_cap_smalls(string) parse2_pat_digits(string) parse3_pat_caps(string) parse4_pat_cap(string) parse5_pat_non_alnums(string) parse6_mark_digits(string) parse7_pat_caps_smalls(string) parse8_pat_smalls_after_non_alnums(string)
string |
A string. |
A partly parsed character vector.
Malte Grosser, [email protected]
Internal function that replaces regex matches with underscores
preprocess_internal(string, sep_in)
preprocess_internal(string, sep_in)
string |
A string. |
sep_in |
(short for separator input) A regex supplied as a character (if not |
A character containing the parsed string.
Malte Grosser, [email protected]
Internal helper for "lower_upper", "upper_lower". This helper returns a logical vector with TRUE for the first and every second string of those which contain an alphabetic character
relevant(string)
relevant(string)
string |
A string (for example names of a data frame). |
A logical vector.
Malte Grosser, [email protected]
Internal helper to replace special characters.
replace_special_characters_internal(string, transliterations, case)
replace_special_characters_internal(string, transliterations, case)
string |
A string (for example names of a data frame). |
transliterations |
A character vector (if not |
case |
Length one character, from the input options of |
A character vector.
Malte Grosser, [email protected]
Function to convert strings to any case
to_any_case(string, case = c("snake", "small_camel", "big_camel", "screaming_snake", "parsed", "mixed", "lower_upper", "upper_lower", "swap", "all_caps", "lower_camel", "upper_camel", "internal_parsing", "none", "flip", "sentence", "random", "title"), abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = c("middle", "left", "right", "asis", "tight"), sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "")
to_any_case(string, case = c("snake", "small_camel", "big_camel", "screaming_snake", "parsed", "mixed", "lower_upper", "upper_lower", "swap", "all_caps", "lower_camel", "upper_camel", "internal_parsing", "none", "flip", "sentence", "random", "title"), abbreviations = NULL, sep_in = "[^[:alnum:]]", parsing_option = 1, transliterations = NULL, numerals = c("middle", "left", "right", "asis", "tight"), sep_out = NULL, unique_sep = NULL, empty_fill = NULL, prefix = "", postfix = "")
string |
A string (for example names of a data frame). |
case |
The desired target case, provided as one of the following:
There are five "special" cases available:
|
abbreviations |
character. (Case insensitive) matched abbreviations are surrounded by underscores. In this way, they can get recognized by the parser. This is useful when e.g. Use this feature with care: One letter abbreviations and abbreviations next to each other are hard to read and also not easy to parse for further processing. |
sep_in |
(short for separator input) if character, is interpreted as a
regular expression (wrapped internally into |
parsing_option |
An integer that will determine the parsing_option.
|
transliterations |
A character vector (if not |
numerals |
A character specifying the alignment of numerals ( |
sep_out |
(short for separator output) String that will be used as separator. The defaults are |
unique_sep |
A string. If not |
empty_fill |
A string. If it is supplied, then each entry that matches "" will be replaced by the supplied string to this argument. |
prefix |
prefix (string). |
postfix |
postfix (string). |
A character vector according the specified parameters above.
to_any_case()
is vectorised over string
, sep_in
, sep_out
,
empty_fill
, prefix
and postfix
.
Malte Grosser, [email protected]
snakecase on github or
caseconverter
for some handy shortcuts.
### abbreviations to_snake_case(c("HHcity", "newUSElections"), abbreviations = c("HH", "US")) to_upper_camel_case("succesfullGMBH", abbreviations = "GmbH") to_title_case("succesfullGMBH", abbreviations = "GmbH") ### sep_in (input separator) string <- "R.St\u00FCdio: v.1.0.143" to_any_case(string) to_any_case(string, sep_in = ":|\\.") to_any_case(string, sep_in = ":|(?<!\\d)\\.") ### parsing_option # the default option makes no sense in this setting to_parsed_case("HAMBURGcity", parsing_option = 1) # so the second parsing option is the way to address this example to_parsed_case("HAMBURGcity", parsing_option = 2) # By default (option 1) characters are converted after non alpha numeric characters. # To suppress this behaviour add a minus to the parsing_option to_upper_camel_case("lookBehindThe.dot", parsing_option = -1) # For some exotic cases parsing option 3 might be of interest to_parsed_case("PARSingOption3", parsing_option = 3) # There may be reasons to suppress the parsing to_any_case("HAMBURGcity", parsing_option = 0) ### transliterations to_any_case("\u00E4ngstlicher Has\u00EA", transliterations = c("german", "Latin-ASCII")) ### case strings <- c("this Is a Strange_string", "AND THIS ANOTHER_One") to_any_case(strings, case = "snake") to_any_case(strings, case = "lower_camel") # same as "small_camel" to_any_case(strings, case = "upper_camel") # same as "big_camel" to_any_case(strings, case = "all_caps") # same as "screaming_snake" to_any_case(strings, case = "lower_upper") to_any_case(strings, case = "upper_lower") to_any_case(strings, case = "sentence") to_any_case(strings, case = "title") to_any_case(strings, case = "parsed") to_any_case(strings, case = "mixed") to_any_case(strings, case = "swap") to_any_case(strings, case = "random") to_any_case(strings, case = "none") to_any_case(strings, case = "internal_parsing") ### numerals to_snake_case("species42value 23month 7-8", numerals = "asis") to_snake_case("species42value 23month 7-8", numerals = "left") to_snake_case("species42value 23month 7-8", numerals = "right") to_snake_case("species42value 23month 7-8", numerals = "middle") to_snake_case("species42value 23month 7-8", numerals = "tight") ### sep_out (output separator) string <- c("lowerCamelCase", "ALL_CAPS", "I-DontKNOWWhat_thisCASE_is") to_snake_case(string, sep_out = ".") to_mixed_case(string, sep_out = " ") to_screaming_snake_case(string, sep_out = "=") ### empty_fill to_any_case(c("","",""), empty_fill = c("empty", "empty", "also empty")) ### unique_sep to_any_case(c("same", "same", "same", "other"), unique_sep = c(">")) ### prefix and postfix to_upper_camel_case("some_path", sep_out = "//", prefix = "USER://", postfix = ".exe")
### abbreviations to_snake_case(c("HHcity", "newUSElections"), abbreviations = c("HH", "US")) to_upper_camel_case("succesfullGMBH", abbreviations = "GmbH") to_title_case("succesfullGMBH", abbreviations = "GmbH") ### sep_in (input separator) string <- "R.St\u00FCdio: v.1.0.143" to_any_case(string) to_any_case(string, sep_in = ":|\\.") to_any_case(string, sep_in = ":|(?<!\\d)\\.") ### parsing_option # the default option makes no sense in this setting to_parsed_case("HAMBURGcity", parsing_option = 1) # so the second parsing option is the way to address this example to_parsed_case("HAMBURGcity", parsing_option = 2) # By default (option 1) characters are converted after non alpha numeric characters. # To suppress this behaviour add a minus to the parsing_option to_upper_camel_case("lookBehindThe.dot", parsing_option = -1) # For some exotic cases parsing option 3 might be of interest to_parsed_case("PARSingOption3", parsing_option = 3) # There may be reasons to suppress the parsing to_any_case("HAMBURGcity", parsing_option = 0) ### transliterations to_any_case("\u00E4ngstlicher Has\u00EA", transliterations = c("german", "Latin-ASCII")) ### case strings <- c("this Is a Strange_string", "AND THIS ANOTHER_One") to_any_case(strings, case = "snake") to_any_case(strings, case = "lower_camel") # same as "small_camel" to_any_case(strings, case = "upper_camel") # same as "big_camel" to_any_case(strings, case = "all_caps") # same as "screaming_snake" to_any_case(strings, case = "lower_upper") to_any_case(strings, case = "upper_lower") to_any_case(strings, case = "sentence") to_any_case(strings, case = "title") to_any_case(strings, case = "parsed") to_any_case(strings, case = "mixed") to_any_case(strings, case = "swap") to_any_case(strings, case = "random") to_any_case(strings, case = "none") to_any_case(strings, case = "internal_parsing") ### numerals to_snake_case("species42value 23month 7-8", numerals = "asis") to_snake_case("species42value 23month 7-8", numerals = "left") to_snake_case("species42value 23month 7-8", numerals = "right") to_snake_case("species42value 23month 7-8", numerals = "middle") to_snake_case("species42value 23month 7-8", numerals = "tight") ### sep_out (output separator) string <- c("lowerCamelCase", "ALL_CAPS", "I-DontKNOWWhat_thisCASE_is") to_snake_case(string, sep_out = ".") to_mixed_case(string, sep_out = " ") to_screaming_snake_case(string, sep_out = "=") ### empty_fill to_any_case(c("","",""), empty_fill = c("empty", "empty", "also empty")) ### unique_sep to_any_case(c("same", "same", "same", "other"), unique_sep = c(">")) ### prefix and postfix to_upper_camel_case("some_path", sep_out = "//", prefix = "USER://", postfix = ".exe")
Internal parser, which is relevant for preprocessing, parsing and parsing options
to_parsed_case_internal(string, parsing_option = 1L, numerals, abbreviations, sep_in)
to_parsed_case_internal(string, parsing_option = 1L, numerals, abbreviations, sep_in)
string |
A string. |
parsing_option |
An integer that will determine the parsing option.
|
numerals |
A character specifying the alignment of numerals ( |
abbreviations |
A character string specifying abbreviations that should be marked to be recognized by later parsing. |
sep_in |
A character (regular expression) used to specify input separators. |
A character vector separated by underscores, containing the parsed string.
Malte Grosser, [email protected]