Skip to content

Commit

Permalink
Update generate_polished_names to remove more special chars
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRoniOne committed Nov 25, 2023
1 parent 10b9962 commit e3b05d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/polish_names.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ struct Style{T} end

Style(s::Symbol) = Style{s}()

const SPECIAL_CHARS = r"[\s\-\.\_\/\:\\\*\?\"\>\<\|]"

"""
polish_names!(table::CleanTable; style::Symbol=:snake_case)
Expand Down Expand Up @@ -48,7 +50,7 @@ function generate_polished_names(names, ::Style{:snake_case})

for name in names
new_name = _sanitize_snake_case(
join(split(_replace_uppers(String(name)), r"[\s\-.]"; keepempty=false), "_")
join(split(_replace_uppers(String(name)), SPECIAL_CHARS; keepempty=false), "_")
)
push!(new_names, new_name)
end
Expand All @@ -61,7 +63,7 @@ function generate_polished_names(names, ::Style{:camelCase})

for name in names
new_name = lowercasefirst(
join(uppercasefirst.(split(String(name), r"[\s\-._]"; keepempty=false)), "")
join(uppercasefirst.(split(String(name), SPECIAL_CHARS; keepempty=false)), "")
)
push!(new_names, new_name)
end
Expand Down
4 changes: 4 additions & 0 deletions test/test_polish_names.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ using DataFrames: DataFrame
" _aName with_loTsOfProblems",
" _aName with_loTsOfProblems",
" _aName with_loTsOfProblems_1",
" _aName with_loTsOfProblems_1_a/b",
];
style=:snake_case,
) == Vector{Symbol}([
:a_name_with_lo_ts_of_problems,
:a_name_with_lo_ts_of_problems_1,
:a_name_with_lo_ts_of_problems_1_1,
:a_name_with_lo_ts_of_problems_1_a_b,
])

@test generate_polished_names(
Expand All @@ -46,13 +48,15 @@ using DataFrames: DataFrame
" _aName with_loTsOfProblems",
" _aName with_loTsOfProblems_1",
" _aNameABC with_loTsOfProblemsDEF",
" _aNameABC with_loTsOfProblemsDEF_a/b",
];
style=:camelCase,
) == Vector{Symbol}([
:aNameWithLoTsOfProblems,
:aNameWithLoTsOfProblems_1,
:aNameWithLoTsOfProblems1,
:aNameABCWithLoTsOfProblemsDEF,
:aNameABCWithLoTsOfProblemsDEFAB,
])

let err = nothing
Expand Down

0 comments on commit e3b05d3

Please sign in to comment.