Skip to content

Commit c717724

Browse files
committed
Merge stdlib_ascii(module):to_string(interface) to stdlib_strings(module):format_to_string(interface).
#### Works 1. merge `to_string` and `format_to_string` to `stdlib_strings`, make the name `to_string` 2. redrect the used keyword `to_string` in `stdlib_string_type` 3. add `stdlib_string_type_constructor.fypp` to avoid the ring dependence in `stdlib_strings` and `stdlib_string_type`. 4. other clean works.
1 parent e646fc5 commit c717724

16 files changed

+353
-387
lines changed

doc/specs/stdlib_ascii.md

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -212,42 +212,4 @@ program demo_reverse
212212
implicit none
213213
print'(a)', reverse("Hello, World!") ! returns "!dlroW ,olleH"
214214
end program demo_reverse
215-
```
216-
217-
### `to_string`
218-
219-
#### Status
220-
221-
Experimental
222-
223-
#### Description
224-
225-
Create a character string representing the value of the provided variable.
226-
227-
#### Syntax
228-
229-
`res = [[stdlib_ascii(module):to_string(interface)]] (string)`
230-
231-
#### Class
232-
233-
Pure function.
234-
235-
#### Argument
236-
237-
`val`: shall be an intrinsic integer or logical type. It is an `intent(in)` argument.
238-
239-
#### Result value
240-
241-
The result is an intrinsic character type.
242-
243-
#### Example
244-
245-
```fortran
246-
program demo_string_value
247-
use stdlib_ascii, only : to_string
248-
implicit none
249-
print'(a)', to_string(-3) ! returns "-3"
250-
print'(a)', to_string(.true.) ! returns "T"
251-
print'(a)', to_string(42) ! returns "42"
252-
end program demo_string_value
253-
```
215+
```

doc/specs/stdlib_strings.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ end program demo_count
436436
```
437437

438438
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -->
439-
### `format_to_string`
439+
### `to_string`
440440

441441
#### Description
442442

@@ -445,15 +445,15 @@ Input a wrong `format` that cause the internal-IO to fail, the result value is a
445445

446446
#### Syntax
447447

448-
`format_to_string = [[stdlib_strings(module):format_to_string(interface)]] (value [, format])`
448+
`string = [[stdlib_strings(module):to_string(interface)]] (value [, format])`
449449

450450
#### Status
451451

452452
Experimental
453453

454454
#### Class
455455

456-
Pure function
456+
Pure function.
457457

458458
#### Argument
459459

@@ -464,38 +464,38 @@ Pure function
464464

465465
#### Result value
466466

467-
The result is an allocatable length `character` scalar with up to 512 `character` length.
467+
The result is an allocatable length `character` scalar with up to 128 cached `character` length.
468468

469469
#### Example
470470

471471
```fortran
472-
program demo_format_to_string
473-
use :: stdlib_strings, only: format_to_string
472+
program demo_to_string
473+
use :: stdlib_strings, only: to_string
474474
implicit none
475475
476-
print *, 'format_to_string(complex) : '
477-
print *, format_to_string((1, 1)) ! (1.00000000,1.00000000)
478-
print *, format_to_string((1, 1), '(F6.2)') ! ( 1.00, 1.00)
479-
print *, format_to_string((1000, 1), '(ES0.2)'), format_to_string((1000, 1), '(SP,F6.3)') ! (1.00E+3,1.00)(******,+1.000)
476+
print *, 'to_string(complex) : '
477+
print *, to_string((1, 1)) ! (1.00000000,1.00000000)
478+
print *, to_string((1, 1), '(F6.2)') ! ( 1.00, 1.00)
479+
print *, to_string((1000, 1), '(ES0.2)'), to_string((1000, 1), '(SP,F6.3)') ! (1.00E+3,1.00)(******,+1.000)
480480
!! Too narrow formatter for real number
481481
!! Normal demonstration(`******` from Fortran Standard)
482482
483-
print *, 'format_to_string(integer) : '
484-
print *, format_to_string(1) ! 1
485-
print *, format_to_string(1, '(I4)') ! 1
486-
print *, format_to_string(1, '(I0.4)'), format_to_string(2, '(B4)') ! 0001 10
483+
print *, 'to_string(integer) : '
484+
print *, to_string(1) ! 1
485+
print *, to_string(1, '(I4)') ! 1
486+
print *, to_string(1, '(I0.4)'), to_string(2, '(B4)') ! 0001 10
487487
488-
print *, 'format_to_string(real) : '
489-
print *, format_to_string(1.) ! 1.00000000
490-
print *, format_to_string(1., '(F6.2)') ! 1.00
491-
print *, format_to_string(1., '(SP,ES9.2)'), format_to_string(1, '(F7.3)') ! +1.00E+00[*]
492-
!! 1 wrong demonstration(`*` from `format_to_string`)
488+
print *, 'to_string(real) : '
489+
print *, to_string(1.) ! 1.00000000
490+
print *, to_string(1., '(F6.2)') ! 1.00
491+
print *, to_string(1., '(SP,ES9.2)'), to_string(1, '(F7.3)') ! +1.00E+00[*]
492+
!! 1 wrong demonstration(`*` from `to_string`)
493493
494-
print *, 'format_to_string(logical) : '
495-
print *, format_to_string(.true.) ! T
496-
print *, format_to_string(.true., '(L2)') ! T
497-
print *, format_to_string(.true., 'L2'), format_to_string(.false., '(I5)') ! [*][*]
498-
!! 2 wrong demonstrations(`*` from `format_to_string`)
494+
print *, 'to_string(logical) : '
495+
print *, to_string(.true.) ! T
496+
print *, to_string(.true., '(L2)') ! T
497+
print *, to_string(.true., 'L2'), to_string(.false., '(I5)') ! [*][*]
498+
!! 2 wrong demonstrations(`*` from `to_string`)
499499
500-
end program demo_format_to_string
500+
end program demo_to_string
501501
```

src/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ set(fppFiles
3030
stdlib_stats_distribution_PRNG.fypp
3131
stdlib_math.fypp
3232
stdlib_string_type.fypp
33-
stdlib_string_format_to_string.fypp
33+
stdlib_string_type_constructor.fypp
34+
stdlib_string_to_string.fypp
3435
stdlib_strings.fypp
3536
)
3637

src/Makefile.manual

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ SRCFYPP =\
2727
stdlib_math.fypp \
2828
stdlib_stats_distribution_PRNG.fypp \
2929
stdlib_string_type.fypp \
30+
stdlib_string_type_constructor.fypp \
3031
stdlib_strings.fypp \
31-
stdlib_string_format_to_string.fypp
32+
stdlib_string_to_string.fypp
3233

3334
SRC = f18estop.f90 \
3435
stdlib_error.f90 \
@@ -139,10 +140,13 @@ stdlib_stats_distribution_PRNG.o: \
139140
stdlib_error.o
140141
stdlib_string_type.o: stdlib_ascii.o \
141142
stdlib_kinds.o
143+
stdlib_string_type_constructor.o: stdlib_string_type.o \
144+
stdlib_string_to_string.o \
145+
stdlib_strings.o
142146
stdlib_strings.o: stdlib_ascii.o \
143147
stdlib_string_type.o \
144148
stdlib_optval.o \
145149
stdlib_kinds.o
146150
stdlib_math.o: stdlib_kinds.o
147-
stdlib_string_format_to_string.o: stdlib_strings.o
151+
stdlib_string_to_string.o: stdlib_strings.o
148152
stdlib_linalg_outer_product.o: stdlib_linalg.o

src/stdlib_ascii.fypp

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,6 @@ module stdlib_ascii
2020

2121
! Character conversion functions
2222
public :: to_lower, to_upper, to_title, to_sentence, reverse
23-
public :: to_string
24-
25-
!> Version: experimental
26-
!>
27-
!> Create a character string representing the value of the provided variable.
28-
interface to_string
29-
#:for kind in INT_KINDS
30-
module procedure :: to_string_integer_${kind}$
31-
#:endfor
32-
#:for kind in LOG_KINDS
33-
module procedure :: to_string_logical_${kind}$
34-
#:endfor
35-
end interface to_string
3623

3724
! All control characters in the ASCII table (see www.asciitable.com).
3825
character(len=1), public, parameter :: NUL = achar(int(z'00')) !! Null
@@ -362,51 +349,4 @@ contains
362349

363350
end function reverse
364351

365-
#:for kind in INT_KINDS
366-
!> Represent an integer of kind ${kind}$ as character sequence
367-
pure function to_string_integer_${kind}$(val) result(string)
368-
integer, parameter :: ik = ${kind}$
369-
integer(ik), intent(in) :: val
370-
character(len=:), allocatable :: string
371-
integer, parameter :: buffer_len = range(val)+2
372-
character(len=buffer_len) :: buffer
373-
integer :: pos
374-
integer(ik) :: n
375-
character(len=1), parameter :: numbers(0:9) = &
376-
["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
377-
378-
if (val == 0_ik) then
379-
string = numbers(0)
380-
return
381-
end if
382-
383-
n = abs(val)
384-
buffer = ""
385-
386-
pos = buffer_len + 1
387-
do while (n > 0_ik)
388-
pos = pos - 1
389-
buffer(pos:pos) = numbers(mod(n, 10_ik))
390-
n = n/10_ik
391-
end do
392-
if (val < 0_ik) then
393-
pos = pos - 1
394-
buffer(pos:pos) = '-'
395-
end if
396-
397-
string = buffer(pos:)
398-
end function to_string_integer_${kind}$
399-
#:endfor
400-
401-
#:for kind in LOG_KINDS
402-
!> Represent an logical of kind ${kind}$ as character sequence
403-
pure function to_string_logical_${kind}$(val) result(string)
404-
integer, parameter :: ik = ${kind}$
405-
logical(ik), intent(in) :: val
406-
character(len=1) :: string
407-
408-
string = merge("T", "F", val)
409-
end function to_string_logical_${kind}$
410-
#:endfor
411-
412352
end module stdlib_ascii

src/stdlib_string_format_to_string.fypp

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)