Skip to content

Commit da2881c

Browse files
committed
remove a redundant comma in doc
clean the implementation of format_string
1 parent e3829b4 commit da2881c

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

doc/specs/stdlib_strings.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ Format or transfer a integer/real/complex/logical variable as a character sequen
339339

340340
#### Syntax
341341

342-
`format_string = [[stdlib_strings(module):format_string(interface)]] (value, [, format])`
342+
`format_string = [[stdlib_strings(module):format_string(interface)]] (value[, format])`
343343

344344
#### Status
345345

src/stdlib_strings_format_string.fypp

+15-25
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#:set RIL_KINDS_TYPES = REAL_KINDS_TYPES + INT_KINDS_TYPES + LOG_KINDS_TYPES
33
submodule (stdlib_strings) stdlib_strings_format_string
44

5+
use stdlib_optval, only: optval
56
implicit none
67
integer, parameter :: buffer_len = 512
78

@@ -12,40 +13,29 @@ contains
1213
!! Format ${type}$ variable as character sequence
1314
character(len=buffer_len) :: buffer
1415
integer :: stat
15-
if(present(fmt)) then
16-
write(buffer, fmt, iostat=stat) val
17-
if(stat == 0) then
18-
string = trim(adjustl(buffer))
19-
else
20-
string = '*'
21-
!!\TODO: *?
22-
end if
16+
17+
write(buffer, optval(fmt, "g0"), iostat=stat) val
18+
if (stat == 0) then
19+
string = trim(buffer)
2320
else
24-
write(buffer, *, iostat=stat) val
25-
if(stat == 0) then
26-
string = trim(adjustl(buffer))
27-
else
28-
string = '*'
29-
!!\TODO: *?
30-
end if
21+
string = '*'
22+
!!\TODO: *?
3123
end if
24+
3225
end procedure format_string_${type[0]}$${kind}$
3326
#:endfor
3427

3528
#:for kind, type in CMPLX_KINDS_TYPES
3629
module procedure format_string_${type[0]}$${kind}$
3730
!! Format ${type}$ variable as character sequence
3831
character(len=buffer_len) :: buffer
39-
if(present(fmt)) then
40-
write(buffer, *) '('//&
41-
format_string_r${kind}$(real(val), fmt)//','// &
42-
format_string_r${kind}$(aimag(val), fmt)//')'
43-
else
44-
write(buffer, *) '('//&
45-
format_string_r${kind}$(real(val))//','// &
46-
format_string_r${kind}$(aimag(val))//')'
47-
end if
48-
string = trim(adjustl(buffer))
32+
33+
write(buffer, *) '('//&
34+
format_string_r${kind}$(val%re, fmt)//','// &
35+
format_string_r${kind}$(val%im, fmt)//')'
36+
37+
string = trim(buffer)
38+
4939
end procedure format_string_${type[0]}$${kind}$
5040
#:endfor
5141

0 commit comments

Comments
 (0)