Skip to content

Commit 1546ef3

Browse files
committed
added interface for to_lower, to_upper, to_title, reverse functions
1 parent b522bbb commit 1546ef3

File tree

2 files changed

+98
-2
lines changed

2 files changed

+98
-2
lines changed

src/stdlib_ascii.f90

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,36 @@ module stdlib_ascii
6464
character(len=*), public, parameter :: lowercase = letters(27:) !! a .. z
6565
character(len=*), public, parameter :: whitespace = " "//TAB//VT//CR//LF//FF !! ASCII _whitespace
6666

67+
68+
!> Convert character variable to lower case
69+
!>
70+
!> This method is pure and returns a character sequence
71+
interface to_lower
72+
module procedure :: to_lower
73+
end interface to_lower
74+
75+
!> Convert character variable to upper case
76+
!>
77+
!> This method is pure and returns a character sequence
78+
interface to_upper
79+
module procedure :: to_upper
80+
end interface to_upper
81+
82+
!> Convert character variable to title case
83+
!>
84+
!> This method is pure and returns a character sequence
85+
interface to_title
86+
module procedure :: to_title
87+
end interface to_title
88+
89+
!> Reverse the character order in the input character variable
90+
!>
91+
!> This method is pure and returns a character sequence
92+
interface reverse
93+
module procedure :: reverse
94+
end interface reverse
95+
96+
6797
contains
6898

6999
!> Checks whether `c` is an ASCII letter (A .. Z, a .. z).

src/stdlib_string_type.f90

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
!>
1313
!> The specification of this module is available [here](../page/specs/stdlib_string_type.html).
1414
module stdlib_string_type
15+
use stdlib_ascii, only: to_lower, to_upper, to_title, reverse
16+
1517
implicit none
1618
private
17-
19+
1820
public :: string_type
19-
public :: len, len_trim, trim, index, scan, verify, repeat, adjustr, adjustl
21+
public :: len, len_trim, trim, index, scan, verify, repeat, adjustr, adjustl, to_lower, to_upper, to_title, reverse
2022
public :: lgt, lge, llt, lle, char, ichar, iachar
2123
public :: assignment(=)
2224
public :: operator(>), operator(>=), operator(<), operator(<=)
@@ -89,6 +91,34 @@ module stdlib_string_type
8991
module procedure :: repeat_string
9092
end interface repeat
9193

94+
!>
95+
!>
96+
!>
97+
interface to_lower
98+
module procedure :: to_lower_string
99+
end interface to_lower
100+
101+
!>
102+
!>
103+
!>
104+
interface to_upper
105+
module procedure :: to_upper_string
106+
end interface to_upper
107+
108+
!>
109+
!>
110+
!>
111+
interface to_title
112+
module procedure :: to_title_string
113+
end interface to_title
114+
115+
!>
116+
!>
117+
!>
118+
interface reverse
119+
module procedure :: reverse_string
120+
end interface reverse
121+
92122
!> Return the character sequence represented by the string.
93123
!>
94124
!> This method is elemental and returns a scalar character value.
@@ -447,6 +477,42 @@ elemental function repeat_string(string, ncopies) result(repeated_string)
447477
end function repeat_string
448478

449479

480+
elemental function to_lower_string(string) result(lowered_string)
481+
type(string_type), intent(in) :: string
482+
type(string_type) :: lowered_string
483+
484+
lowered_string%raw = to_lower(string%raw)
485+
486+
end function to_lower_string
487+
488+
489+
elemental function to_upper_string(string) result(uppered_string)
490+
type(string_type), intent(in) :: string
491+
type(string_type) :: uppered_string
492+
493+
uppered_string%raw = to_upper(string%raw)
494+
495+
end function to_upper_string
496+
497+
498+
elemental function to_title_string(string) result(titled_string)
499+
type(string_type), intent(in) :: string
500+
type(string_type) :: titled_string
501+
502+
titled_string%raw = to_title(string%raw)
503+
504+
end function to_title_string
505+
506+
507+
elemental function reverse_string(string) result(reversed_string)
508+
type(string_type), intent(in) :: string
509+
type(string_type) :: reversed_string
510+
511+
reversed_string%raw = reverse(string%raw)
512+
513+
end function reverse_string
514+
515+
450516
!> Position of a sequence of character within a character sequence.
451517
!> In this version both character sequences are represented by a string.
452518
elemental function index_string_string(string, substring, back) result(pos)

0 commit comments

Comments
 (0)