Skip to content

Commit c063898

Browse files
committed
feat(string_t): operator(.cat.) for array operand
1 parent 6f2b22e commit c063898

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

src/sourcery/sourcery_string_m.f90

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module sourcery_string_m
55
private
66
public :: string_t
77
public :: array_of_strings
8-
public :: concatenate_elements
8+
public :: operator(.cat.) ! element-wise concatenation operator
99

1010
type, extends(characterizable_t) :: string_t
1111
private
@@ -55,14 +55,17 @@ elemental module function from_real(x) result(string)
5555

5656
end interface
5757

58-
interface
58+
interface operator(.cat.)
5959

6060
pure module function concatenate_elements(strings) result(concatenated_strings)
6161
implicit none
6262
type(string_t), intent(in) :: strings(:)
6363
type(string_t) concatenated_strings
6464
end function
6565

66+
end interface
67+
68+
interface
6669
pure module function as_character(self) result(raw_string)
6770
implicit none
6871
class(string_t), intent(in) :: self

src/sourcery_m.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module sourcery_m
55
use sourcery_bin_m, only : bin_t
66
use sourcery_formats_m, only : csv, cscv, separated_values
77
use sourcery_file_m, only : file_t
8-
use sourcery_string_m, only : string_t
8+
use sourcery_string_m, only : string_t, operator(.cat.)
99
use sourcery_test_result_m, only : test_result_t
1010
use sourcery_test_m, only : test_t
1111
use sourcery_user_defined_collectives_m, only : co_all

test/string_test.f90

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module string_test_m
2-
use sourcery_m, only : test_t, test_result_t, string_t
2+
use sourcery_m, only : test_t, test_result_t, string_t, operator(.cat.)
33
implicit none
44

55
private
@@ -23,19 +23,20 @@ function results() result(test_results)
2323

2424
test_results = [ &
2525
test_result_t("is_allocated() result .true. if & only if the string_t component(s) is/are allocated", check_allocation()), &
26-
test_result_t("extracting a key string from a colon-separated key/value pair", extracts_key()), &
27-
test_result_t("extracting a real value from a colon-separated key/value pair", extracts_real_value()), &
28-
test_result_t("extracting a string value from a colon-separated key/value pair", extracts_string_value()), &
29-
test_result_t("extracting a logical value from a colon-separated key/value pair", extracts_logical_value()), &
30-
test_result_t("extracting an integer array value from a colon-separated key/value pair", extracts_integer_array_value()), &
31-
test_result_t("extracting an integer value from a colon-separated key/value pair", extracts_integer_value()), &
3226
test_result_t('supporting operator(==) for string_t and character operands', supports_equivalence_operator()), &
3327
test_result_t('supporting operator(/=) for string_t and character operands', supports_non_equivalence_operator()), &
28+
test_result_t('supporting operator(//) for string_t and character operands', supports_concatenation_operator()), &
3429
test_result_t('assigning a string_t object to a character variable', assigns_string_t_to_character()), &
3530
test_result_t('assigning a character variable to a string_t object', assigns_character_to_string_t()), &
36-
test_result_t('supporting operator(//) for string_t and character operands', supports_concatenation_operator()), &
3731
test_result_t('constructing from a default integer', constructs_from_default_integer()), &
3832
test_result_t('constructing from a real value', constructs_from_real()), &
33+
test_result_t('supporting unary operator(.cat.) for array arguments', concatenates_elements()), &
34+
test_result_t("extracting a key string from a colon-separated key/value pair", extracts_key()), &
35+
test_result_t("extracting a real value from a colon-separated key/value pair", extracts_real_value()), &
36+
test_result_t("extracting a string value from a colon-separated key/value pair", extracts_string_value()), &
37+
test_result_t("extracting a logical value from a colon-separated key/value pair", extracts_logical_value()), &
38+
test_result_t("extracting an integer array value from a colon-separated key/value pair", extracts_integer_array_value()), &
39+
test_result_t("extracting an integer value from a colon-separated key/value pair", extracts_integer_value()), &
3940
test_result_t('extracting a file base name', extracts_file_base_name()), &
4041
test_result_t('extracting a file name extension', extracts_file_name_extension()) &
4142
]
@@ -182,4 +183,11 @@ function extracts_file_name_extension() result(passed)
182183
end associate
183184
end function
184185

186+
function concatenates_elements() result(passed)
187+
logical passed
188+
associate(elements => [string_t("foo"), string_t("bar")])
189+
passed = .cat. elements == "foobar"
190+
end associate
191+
end function
192+
185193
end module string_test_m

0 commit comments

Comments
 (0)