|
12 | 12 | !>
|
13 | 13 | !> The specification of this module is available [here](../page/specs/stdlib_string_type.html).
|
14 | 14 | module stdlib_string_type
|
| 15 | + use stdlib_ascii, only: to_lower, to_upper, to_title, reverse |
| 16 | + |
15 | 17 | implicit none
|
16 | 18 | private
|
17 |
| - |
| 19 | + |
18 | 20 | 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 |
20 | 22 | public :: lgt, lge, llt, lle, char, ichar, iachar
|
21 | 23 | public :: assignment(=)
|
22 | 24 | public :: operator(>), operator(>=), operator(<), operator(<=)
|
@@ -89,6 +91,34 @@ module stdlib_string_type
|
89 | 91 | module procedure :: repeat_string
|
90 | 92 | end interface repeat
|
91 | 93 |
|
| 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 | + |
92 | 122 | !> Return the character sequence represented by the string.
|
93 | 123 | !>
|
94 | 124 | !> This method is elemental and returns a scalar character value.
|
@@ -447,6 +477,42 @@ elemental function repeat_string(string, ncopies) result(repeated_string)
|
447 | 477 | end function repeat_string
|
448 | 478 |
|
449 | 479 |
|
| 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 | + |
450 | 516 | !> Position of a sequence of character within a character sequence.
|
451 | 517 | !> In this version both character sequences are represented by a string.
|
452 | 518 | elemental function index_string_string(string, substring, back) result(pos)
|
|
0 commit comments