Skip to content

Commit

Permalink
Merge pull request #63 from sebastianpech/issue-61
Browse files Browse the repository at this point in the history
Add support for quoted names with spaces
  • Loading branch information
TeroFrondelius authored Jul 16, 2020
2 parents 631d758 + 5c3d435 commit e6e04f0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AbaqusReader"
uuid = "bc6b9049-e460-56d6-94b4-a597b2c0390d"
authors = ["Jukka Aho <[email protected]>"]
version = "0.2.4"
version = "0.2.5"

[deps]
Nullables = "4d1e1d77-625e-5b40-9113-a560ec7a8ecd"
Expand Down
4 changes: 2 additions & 2 deletions src/parse_mesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ end
function parse_section(model, lines, key, idx_start, idx_end, ::Union{Type{Val{:NSET}},
Type{Val{:ELSET}}})
data = Int[]
set_regex_string = Dict(:NSET => r"NSET=([\w\-\_]+)"i,
:ELSET => r"ELSET=([\w\-\_]+)"i)
set_regex_string = Dict(:NSET => r"((?<=NSET=)([\w\-\_]+)|(?<=NSET=\")([\w\-\_\ ]+)(?=\"))"i,
:ELSET => r"((?<=ELSET=)([\w\-\_]+)|(?<=ELSET=\")([\w\-\_\ ]+)(?=\"))"i)
selected_set = key == :NSET ? "node_sets" : "element_sets"
definition = lines[idx_start]
regex_string = set_regex_string[key]
Expand Down
28 changes: 28 additions & 0 deletions test/test_parse_mesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,31 @@ end
mesh = abaqus_read_mesh(fn)
@test length(mesh["nodes"]) == 116
end

@testset "Set names" begin
data = """*Nset, nset=Without quotes
1,2,3
*Nset, nset="With quotes"
3,4,5
*Nset, nset="With wrong quotes
1,2,3
*Elset, elset=Without quotes
1,2,3
*Elset, elset="With quotes"
3,4,5
*Elset, elset="With wrong quotes
1,2,3
"""
data = split(data, "\n")
model = Dict{String, Any}()
model["node_sets"] = Dict{String, Vector{Int}}()
model["element_sets"] = Dict{String, Vector{Int}}()
@test parse_section(model, data, :NSET, 1, 2, Val{:NSET}) == [1,2,3]
@test parse_section(model, data, :NSET, 3, 4, Val{:NSET}) == [3,4,5]
@test_throws ErrorException parse_section(model, data, :NSET, 5, 6, Val{:NSET})
@test keys(model["node_sets"]) == Set(["Without", "With quotes"])
@test parse_section(model, data, :ELSET, 7, 8, Val{:ELSET}) == [1,2,3]
@test parse_section(model, data, :ELSET, 9, 10, Val{:ELSET}) == [3,4,5]
@test_throws ErrorException parse_section(model, data, :ELSET, 11, 12, Val{:NSET})
@test keys(model["element_sets"]) == Set(["Without", "With quotes"])
end

0 comments on commit e6e04f0

Please sign in to comment.