Skip to content

Commit e6e04f0

Browse files
Merge pull request #63 from sebastianpech/issue-61
Add support for quoted names with spaces
2 parents 631d758 + 5c3d435 commit e6e04f0

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "AbaqusReader"
22
uuid = "bc6b9049-e460-56d6-94b4-a597b2c0390d"
33
authors = ["Jukka Aho <ahojukka5@gmail.com>"]
4-
version = "0.2.4"
4+
version = "0.2.5"
55

66
[deps]
77
Nullables = "4d1e1d77-625e-5b40-9113-a560ec7a8ecd"

src/parse_mesh.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ end
178178
function parse_section(model, lines, key, idx_start, idx_end, ::Union{Type{Val{:NSET}},
179179
Type{Val{:ELSET}}})
180180
data = Int[]
181-
set_regex_string = Dict(:NSET => r"NSET=([\w\-\_]+)"i,
182-
:ELSET => r"ELSET=([\w\-\_]+)"i)
181+
set_regex_string = Dict(:NSET => r"((?<=NSET=)([\w\-\_]+)|(?<=NSET=\")([\w\-\_\ ]+)(?=\"))"i,
182+
:ELSET => r"((?<=ELSET=)([\w\-\_]+)|(?<=ELSET=\")([\w\-\_\ ]+)(?=\"))"i)
183183
selected_set = key == :NSET ? "node_sets" : "element_sets"
184184
definition = lines[idx_start]
185185
regex_string = set_regex_string[key]

test/test_parse_mesh.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,31 @@ end
108108
mesh = abaqus_read_mesh(fn)
109109
@test length(mesh["nodes"]) == 116
110110
end
111+
112+
@testset "Set names" begin
113+
data = """*Nset, nset=Without quotes
114+
1,2,3
115+
*Nset, nset="With quotes"
116+
3,4,5
117+
*Nset, nset="With wrong quotes
118+
1,2,3
119+
*Elset, elset=Without quotes
120+
1,2,3
121+
*Elset, elset="With quotes"
122+
3,4,5
123+
*Elset, elset="With wrong quotes
124+
1,2,3
125+
"""
126+
data = split(data, "\n")
127+
model = Dict{String, Any}()
128+
model["node_sets"] = Dict{String, Vector{Int}}()
129+
model["element_sets"] = Dict{String, Vector{Int}}()
130+
@test parse_section(model, data, :NSET, 1, 2, Val{:NSET}) == [1,2,3]
131+
@test parse_section(model, data, :NSET, 3, 4, Val{:NSET}) == [3,4,5]
132+
@test_throws ErrorException parse_section(model, data, :NSET, 5, 6, Val{:NSET})
133+
@test keys(model["node_sets"]) == Set(["Without", "With quotes"])
134+
@test parse_section(model, data, :ELSET, 7, 8, Val{:ELSET}) == [1,2,3]
135+
@test parse_section(model, data, :ELSET, 9, 10, Val{:ELSET}) == [3,4,5]
136+
@test_throws ErrorException parse_section(model, data, :ELSET, 11, 12, Val{:NSET})
137+
@test keys(model["element_sets"]) == Set(["Without", "With quotes"])
138+
end

0 commit comments

Comments
 (0)