File: string_19.f90

package info (click to toggle)
lfortran 0.45.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 46,332 kB
  • sloc: cpp: 137,068; f90: 51,260; python: 6,444; ansic: 4,277; yacc: 2,285; fortran: 806; sh: 524; makefile: 30; javascript: 15
file content (103 lines) | stat: -rw-r--r-- 2,803 bytes parent folder | download
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
module string_19_stdlib_string_type
implicit none

type :: string_type
    sequence
    character(len=:), allocatable :: raw
end type string_type

interface len
    module procedure :: len_string
end interface len

interface char
    module procedure :: char_string
end interface char

contains

elemental function len_string(string) result(length)
    type(string_type), intent(in) :: string
    integer :: length

end function len_string

pure function char_string(string) result(character_string)
    type(string_type), intent(in) :: string
    character(len=len(string)) :: character_string

end function char_string

end module

module string_19_stdlib_strings
use string_19_stdlib_string_type
implicit none

interface padl
    module procedure :: padl_char_default
    module procedure :: padl_char_pad_with
end interface padl

contains

    pure function compute_lps(string) result(lps_array)
        character(len=*), intent(in) :: string
        integer :: lps_array(len(string))
    end function compute_lps

    function compute_lps_use(string) result(l)
        character(len=*), intent(in) :: string
        integer :: l
        print *, compute_lps(string)
    end function compute_lps_use

    function compute_lps_use1(string) result(l)
        type(string_type), intent(in) :: string
        integer :: l
        print *, char(string)
    end function compute_lps_use1

    pure function padl_string_default(string, output_length) result(res)
        type(string_type), intent(in) :: string
        integer, intent(in) :: output_length
        type(string_type) :: res

        res = string_type(padl(char(string), output_length, " "))

    end function padl_string_default

    pure function padl_string_pad_with(string, output_length, pad_with) result(res)
        type(string_type), intent(in) :: string
        integer, intent(in) :: output_length
        character(len=1), intent(in) :: pad_with
        type(string_type) :: res

        res = string_type(padl(char(string), output_length, pad_with))

    end function padl_string_pad_with

    pure function padl_char_default(string, output_length) result(res)
        character(len=*), intent(in) :: string
        integer, intent(in) :: output_length
        character(len=len(string)) :: res

        res = padl(string, output_length, " ")

    end function padl_char_default

    pure function padl_char_pad_with(string, output_length, pad_with) result(res)
        character(len=*), intent(in) :: string
        integer, intent(in) :: output_length
        character(len=1), intent(in) :: pad_with
        character(len=max(len(string), output_length)) :: res
        integer :: string_length

    end function padl_char_pad_with

end module

program stdlib_strings_use
use string_19_stdlib_strings
implicit none
end program