StringiFor escape test.
| Type | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|
| type(string) | :: | astring | A string. |
|||
| logical | :: | test_passed(1) | List of passed tests. |
program escape
!-----------------------------------------------------------------------------------------------------------------------------------
!< StringiFor `escape` test.
!-----------------------------------------------------------------------------------------------------------------------------------
use, intrinsic :: iso_fortran_env, only : stdout => output_unit
use stringifor, only : string
!-----------------------------------------------------------------------------------------------------------------------------------
!-----------------------------------------------------------------------------------------------------------------------------------
implicit none
type(string) :: astring !< A string.
logical :: test_passed(1) !< List of passed tests.
!-----------------------------------------------------------------------------------------------------------------------------------
!-----------------------------------------------------------------------------------------------------------------------------------
test_passed = .false.
astring = '^\s \d+\s*'
write(stdout, "(A)") 'Original: "'//astring//'"'
test_passed(1) = (astring%escape(to_escape='\')//''=='^\\s \\d+\\s*')
write(stdout, "(A)") 'Escaped: "'//astring%escape(to_escape='\')//'"'
write(stdout, "(A,L1)") new_line('a')//'Are all tests passed? ', all(test_passed)
stop
!-----------------------------------------------------------------------------------------------------------------------------------
endprogram escape