|
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_lower, to_upper_ => to_upper, & |
| 16 | + to_title_ => to_title, reverse_ => reverse |
| 17 | + |
15 | 18 | implicit none |
16 | 19 | private |
17 | 20 |
|
18 | 21 | public :: string_type |
19 | 22 | public :: len, len_trim, trim, index, scan, verify, repeat, adjustr, adjustl |
20 | 23 | public :: lgt, lge, llt, lle, char, ichar, iachar |
| 24 | + public :: to_lower, to_upper, to_title, reverse |
21 | 25 | public :: assignment(=) |
22 | 26 | public :: operator(>), operator(>=), operator(<), operator(<=) |
23 | 27 | public :: operator(==), operator(/=), operator(//) |
@@ -89,6 +93,38 @@ module stdlib_string_type |
89 | 93 | module procedure :: repeat_string |
90 | 94 | end interface repeat |
91 | 95 |
|
| 96 | + !> Returns the lowercase version of the character sequence hold by the input string |
| 97 | + !> |
| 98 | + !> This method is Elemental and returns a new string_type instance which holds this |
| 99 | + !> lowercase character sequence |
| 100 | + interface to_lower |
| 101 | + module procedure :: to_lower_string |
| 102 | + end interface to_lower |
| 103 | + |
| 104 | + !> Returns the uppercase version of the character sequence hold by the input string |
| 105 | + !> |
| 106 | + !> This method is Elemental and returns a new string_type instance which holds this |
| 107 | + !> uppercase character sequence |
| 108 | + interface to_upper |
| 109 | + module procedure :: to_upper_string |
| 110 | + end interface to_upper |
| 111 | + |
| 112 | + !> Returns the titlecase version of the character sequence hold by the input string |
| 113 | + !> |
| 114 | + !> This method is Elemental and returns a new string_type instance which holds this |
| 115 | + !> titlecase character sequence |
| 116 | + interface to_title |
| 117 | + module procedure :: to_title_string |
| 118 | + end interface to_title |
| 119 | + |
| 120 | + !> Reverses the character sequence hold by the input string |
| 121 | + !> |
| 122 | + !> This method is Elemental and returns a new string_type instance which holds this |
| 123 | + !> reverse character sequence |
| 124 | + interface reverse |
| 125 | + module procedure :: reverse_string |
| 126 | + end interface reverse |
| 127 | + |
92 | 128 | !> Return the character sequence represented by the string. |
93 | 129 | !> |
94 | 130 | !> This method is elemental and returns a scalar character value. |
@@ -447,6 +483,46 @@ elemental function repeat_string(string, ncopies) result(repeated_string) |
447 | 483 | end function repeat_string |
448 | 484 |
|
449 | 485 |
|
| 486 | + !> Convert the character sequence hold by the input string to lower case |
| 487 | + elemental function to_lower_string(string) result(lowercase_string) |
| 488 | + type(string_type), intent(in) :: string |
| 489 | + type(string_type) :: lowercase_string |
| 490 | + |
| 491 | + lowercase_string%raw = to_lower_(maybe(string)) |
| 492 | + |
| 493 | + end function to_lower_string |
| 494 | + |
| 495 | + |
| 496 | + !> Convert the character sequence hold by the input string to upper case |
| 497 | + elemental function to_upper_string(string) result(uppercase_string) |
| 498 | + type(string_type), intent(in) :: string |
| 499 | + type(string_type) :: uppercase_string |
| 500 | + |
| 501 | + uppercase_string%raw = to_upper_(maybe(string)) |
| 502 | + |
| 503 | + end function to_upper_string |
| 504 | + |
| 505 | + |
| 506 | + !> Convert the character sequence hold by the input string to title case |
| 507 | + elemental function to_title_string(string) result(titlecase_string) |
| 508 | + type(string_type), intent(in) :: string |
| 509 | + type(string_type) :: titlecase_string |
| 510 | + |
| 511 | + titlecase_string%raw = to_title_(maybe(string)) |
| 512 | + |
| 513 | + end function to_title_string |
| 514 | + |
| 515 | + |
| 516 | + !> Reverse the character sequence hold by the input string |
| 517 | + elemental function reverse_string(string) result(reversed_string) |
| 518 | + type(string_type), intent(in) :: string |
| 519 | + type(string_type) :: reversed_string |
| 520 | + |
| 521 | + reversed_string%raw = reverse_(maybe(string)) |
| 522 | + |
| 523 | + end function reverse_string |
| 524 | + |
| 525 | + |
450 | 526 | !> Position of a sequence of character within a character sequence. |
451 | 527 | !> In this version both character sequences are represented by a string. |
452 | 528 | elemental function index_string_string(string, substring, back) result(pos) |
|
0 commit comments