Skip to content

Commit

Permalink
move common string cases to their own file
Browse files Browse the repository at this point in the history
  • Loading branch information
acxz committed Jun 15, 2024
1 parent e9a0f86 commit f189e47
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 36 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ that allows users to
- **validate** strings on string cases
- **convert** between string cases

Comes with various common prebuilt string cases. See
[end of `src/stringcases.jl` file](https://github.com/acxz/StringCases.jl/blob/4a1e508ef24033e87ec301f7438e05eddc7eab63/src/stringcases.jl#L336)
Comes with various common prebuilt string cases. See the
[`src/commonstringcases.jl`](https://github.com/acxz/StringCases.jl/blob/main/src/stringcases.jl)
file.

## Add Package
In Julia REPL:
Expand Down Expand Up @@ -72,7 +73,7 @@ camel_case_acro = PatternStringCase(
# Convert a string from our newly defined string case, camel_case_acro, to a
# common string case already defined in StringCases.jl (StringCases.PASCAL_CASE)
# For more string cases provided out of the box, take a look at the end of the
# `src/stringcases.jl` file
# `src/commonstringcases.jl` file

StringCases.convert("stringCasesFTW!", camel_case_acro, StringCases.PASCAL_CASE)
# Output: "StringCasesFtw!"
Expand Down Expand Up @@ -155,7 +156,7 @@ StringCases.convert("string.Cases-_FTW!", camel_case_punc, StringCases.SNAKE_CAS
# Output: "string_cases_ftw"
```

For more examples see
For more examples see the
[`test/runtests.jl`](https://github.com/acxz/StringCases.jl/blob/main/test/runtests.jl)
file.

Expand Down
1 change: 1 addition & 0 deletions src/StringCases.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module StringCases

include("stringcases.jl")
include("commonstringcases.jl")

export AbstractStringCase, DelimiterStringCase, PatternStringCase

Expand Down
33 changes: 33 additions & 0 deletions src/commonstringcases.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Delimiter String Cases
const TITLE_CASE = DelimiterStringCase("Title Case", lowercase, titlecase, titlecase, " ")
const LENIENT_TITLE_CASE =
DelimiterStringCase("LEnient Title Case", anycase, titlecase, titlecase, " ")
const SENTENCE_CASE =
DelimiterStringCase("Sentence case", lowercase, lowercase, uppercase, " ")
const SNAKE_CASE = DelimiterStringCase("snake_case", lowercase, lowercase, lowercase, "_")
const SCREAMING_SNAKE_CASE =
DelimiterStringCase("SCREAMING_SNAKE_CASE", uppercase, uppercase, uppercase, "_")
const KEBAB_CASE = DelimiterStringCase("kebab-case", lowercase, lowercase, lowercase, "-")
const COBOL_CASE = DelimiterStringCase("COBOL-CASE", uppercase, uppercase, uppercase, "-")
const ADA_CASE = DelimiterStringCase("Ada_Case", lowercase, uppercase, uppercase, "_")
const TRAIN_CASE = DelimiterStringCase("Train-Case", lowercase, uppercase, uppercase, "-")
const SPACE_CASE = DelimiterStringCase("space case", anycase, anycase, anycase, " ")
const PATH_CASE = DelimiterStringCase("path/case", anycase, anycase, anycase, "/")
const DOT_CASE = DelimiterStringCase("dot.case", anycase, anycase, anycase, ".")

# Pattern String Cases
const FLAT_CASE = PatternStringCase("flatcase", lowercase, lowercase, lowercase)
const UPPER_FLAT_CASE = PatternStringCase("UPPERFLATCASE", uppercase, uppercase, uppercase)
const PASCAL_CASE = PatternStringCase("PascalCase", lowercase, uppercase, uppercase)
const CAMEL_CASE = PatternStringCase("camelCase", lowercase, uppercase, lowercase)
const CAMEL_TITLE_CASE =
PatternStringCase("camelTitleCase", lowercase, titlecase, lowercase)

const CAMEL_CASE_ACRO_NUM = PatternStringCase(
"camelCaseACRO123",
lowercase,
uppercase,
lowercase,
acro_all_of_token,
true,
)
32 changes: 0 additions & 32 deletions src/stringcases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -318,35 +318,3 @@ function validate(s::AbstractString, sc::AbstractStringCase)

return is_valid_str
end

# Common string cases
const TITLE_CASE = DelimiterStringCase("Title Case", lowercase, titlecase, titlecase, " ")
const LENIENT_TITLE_CASE =
DelimiterStringCase("LEnient Title Case", anycase, titlecase, titlecase, " ")
const SENTENCE_CASE =
DelimiterStringCase("Sentence case", lowercase, lowercase, uppercase, " ")
const SNAKE_CASE = DelimiterStringCase("snake_case", lowercase, lowercase, lowercase, "_")
const SCREAMING_SNAKE_CASE =
DelimiterStringCase("SCREAMING_SNAKE_CASE", uppercase, uppercase, uppercase, "_")
const KEBAB_CASE = DelimiterStringCase("kebab-case", lowercase, lowercase, lowercase, "-")
const COBOL_CASE = DelimiterStringCase("COBOL-CASE", uppercase, uppercase, uppercase, "-")
const ADA_CASE = DelimiterStringCase("Ada_Case", lowercase, uppercase, uppercase, "_")
const TRAIN_CASE = DelimiterStringCase("Train-Case", lowercase, uppercase, uppercase, "-")
const SPACE_CASE = DelimiterStringCase("space case", anycase, anycase, anycase, " ")
const PATH_CASE = DelimiterStringCase("path/case", anycase, anycase, anycase, "/")
const DOT_CASE = DelimiterStringCase("dot.case", anycase, anycase, anycase, ".")

const FLAT_CASE = PatternStringCase("flatcase", lowercase, lowercase, lowercase)
const UPPER_FLAT_CASE = PatternStringCase("UPPERFLATCASE", uppercase, uppercase, uppercase)
const PASCAL_CASE = PatternStringCase("PascalCase", lowercase, uppercase, uppercase)
const CAMEL_CASE = PatternStringCase("camelCase", lowercase, uppercase, lowercase)
const CAMEL_TITLE_CASE =
PatternStringCase("camelTitleCase", lowercase, titlecase, lowercase)
const CAMEL_CASE_ACRO_NUM = PatternStringCase(
"camelCaseACRO123",
lowercase,
uppercase,
lowercase,
acro_all_of_token,
true,
)

0 comments on commit f189e47

Please sign in to comment.