Skip to content

Commit

Permalink
Improve _preprocess_name to replace % and # with letters
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRoniOne committed Apr 7, 2024
1 parent 222e1fb commit ebdf8bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/polish_names.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Return a vector of symbols containing new names that are unique and formated usi
"""
function generate_polished_names(names; style::Symbol=:snake_case)
names = _preprocess_name.(names)

return generate_polished_names(names, Style(style))
end

Expand Down Expand Up @@ -79,13 +79,15 @@ function generate_polished_names(names, ::Style)
end

function _preprocess_name(name)
preprocessed = normalize(String(name), stripmark=true)
preprocessed = normalize(String(name); stripmark=true)

matched = match(r"^[[:upper:]]+$", preprocessed)
matched = match(r"^[[:upper:]]+|\%|\#$", preprocessed)
if matched !== nothing
return lowercase(preprocessed)
preprocessed = lowercase(preprocessed)
end

preprocessed = replace(preprocessed, "%" => "Percent", "#" => "Number")

return preprocessed
end

Expand Down
8 changes: 8 additions & 0 deletions test/test_polish_names.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ using DataFrames: DataFrame
" _aName with_loTsOfProblems_1",
" _aName with_loTsOfProblems_1_a/b'c",
"ID",
"NOËL%",
"NOEL #",
];
style=:snake_case,
) == Vector{Symbol}([
Expand All @@ -42,6 +44,8 @@ using DataFrames: DataFrame
:a_name_with_lo_ts_of_problems_1_1,
:a_name_with_lo_ts_of_problems_1_a_b_c,
:id,
:noel_percent,
:noel_number,
])

@test generate_polished_names(
Expand All @@ -52,6 +56,8 @@ using DataFrames: DataFrame
" _aNameABC with_loTsOfProblemsDEF",
" _aNameABC with_loTsOfProblemsDEF_a/b'c",
"ID",
"NOËL%",
"NOEL #",
];
style=:camelCase,
) == Vector{Symbol}([
Expand All @@ -61,6 +67,8 @@ using DataFrames: DataFrame
:aNameABCWithLoTsOfProblemsDEF,
:aNameABCWithLoTsOfProblemsDEFABC,
:id,
:noelPercent,
:noelNumber,
])

let err = nothing
Expand Down

0 comments on commit ebdf8bb

Please sign in to comment.