File: modules_49.f90

package info (click to toggle)
lfortran 0.59.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 56,736 kB
  • sloc: cpp: 168,052; f90: 74,272; python: 17,537; ansic: 7,705; yacc: 2,345; sh: 1,334; fortran: 895; makefile: 37; javascript: 15
file content (44 lines) | stat: -rw-r--r-- 1,237 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module modules_49_fpm_strings
implicit none

contains

pure function replace(string, charset, target_char) result(res)
    character(*), intent(in) :: string
    character(len=1), intent(in) :: charset(:), target_char
    character(len(string)) :: res
    integer :: n, m, one
    one = 1
    res = string
    do n = 1, len(string)
        ! TODO: To be fixed, after making any work for character types
        ! if (any(string(n:n) == charset)) then
        !     res(n:n) = target_char
        ! end if
        do m = lbound(charset, 1), ubound(charset, 1)
            if(string(n:n) == charset(m)) then
                res(n:n) = target_char(one:one)
                exit
            end if
        end do
    end do
end function replace

pure function to_fortran_name(string) result(res)
    character(*), intent(in) :: string
    character(len(string)) :: res
    character, parameter :: SPECIAL_CHARACTERS(*) = ['-']
    res = replace(string, SPECIAL_CHARACTERS, '_')
end function to_fortran_name

end module

program modules_49
use modules_49_fpm_strings
implicit none

character(len=40) :: name = "--gnu-gfortran-11"
print *, name, to_fortran_name(name)
if( to_fortran_name(name) /= "__gnu_gfortran_11" ) error stop

end program