Skip to content

Commit 22c6c10

Browse files
committed
refac(get_json_integer_array): make a thin wrapper
Because JSON does not distinguish between real and integer numbers and reading real arrays of unknown length is for some reason easier, this commit refactors get_json_integer_array to be a thin wrapper around the new get_json_real_array.
1 parent 08bb2a0 commit 22c6c10

File tree

1 file changed

+2
-22
lines changed

1 file changed

+2
-22
lines changed

src/sourcery/sourcery_string_s.f90

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -182,35 +182,15 @@
182182
end procedure
183183

184184
module procedure get_json_integer_array
185-
character(len=:), allocatable :: raw_line
186-
real, allocatable :: real_array(:)
187-
integer i
188-
189-
call assert(key==self%get_json_key(), "string_s(get_json_integer_array): key==self%get_json_key()", key)
190-
191-
raw_line = self%string()
192-
associate(colon => index(raw_line, ":"))
193-
associate(opening_bracket => colon + index(raw_line(colon+1:), "["))
194-
associate(closing_bracket => opening_bracket + index(raw_line(opening_bracket+1:), "]"))
195-
associate(commas => count("," == [(raw_line(i:i), i=opening_bracket+1,closing_bracket-1)]))
196-
associate(num_inputs => commas + 1)
197-
allocate(real_array(num_inputs))
198-
read(raw_line(opening_bracket+1:closing_bracket-1), fmt=*) real_array
199-
value_ = int(real_array)
200-
end associate
201-
end associate
202-
end associate
203-
end associate
204-
end associate
205-
185+
value_ = int(self%get_json_real_array(key,mold=[0.]))
206186
end procedure
207187

208188
module procedure get_json_real_array
209189
character(len=:), allocatable :: raw_line
210190
real, allocatable :: real_array(:)
211191
integer i
212192

213-
call assert(key==self%get_json_key(), "string_s(get_json_real_array): key==self%get_json_key()", key)
193+
call assert(key==self%get_json_key(), "string_s(get_json_{real,integer}_array): key==self%get_json_key()", key)
214194

215195
raw_line = self%string()
216196
associate(colon => index(raw_line, ":"))

0 commit comments

Comments
 (0)