Skip to content

Commit 1676331

Browse files
authored
Merge pull request #12 from sbcgua/setx
setx feature
2 parents ef6e9e7 + d578e15 commit 1676331

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ lo_map->set(
3939
iv_val = '2' ).
4040
```
4141

42+
- there is also `setx` - a more readable yet not so strict version of `set`. Can be useful for multiple sets in a raw.
43+
44+
```abap
45+
lo_map->setx( 'A:1' )->setx( |B : { '2' }| ).
46+
```
47+
4248
- implements `keys`, `values`
4349

4450
```abap

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Legend
1111
v1.0.4, 2024-06-24
1212
------------------
1313
+ to_entries - saves entries to a standard table with 2 char-like components (#11)
14+
+ setx - simplified and more readable version of set (#12)
1415

1516
v1.0.3, 2021-07-25
1617
------------------

src/zcl_abap_string_map.clas.abap

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class zcl_abap_string_map definition
4949
!iv_val type clike
5050
returning
5151
value(ro_map) type ref to zcl_abap_string_map.
52+
methods setx
53+
importing
54+
!iv_str type csequence
55+
returning
56+
value(ro_map) type ref to zcl_abap_string_map.
5257
methods size
5358
returning
5459
value(rv_size) type i.
@@ -383,6 +388,32 @@ CLASS ZCL_ABAP_STRING_MAP IMPLEMENTATION.
383388
endmethod.
384389

385390

391+
method setx.
392+
393+
data lv_key type string.
394+
data lv_val type string.
395+
396+
ro_map = me.
397+
398+
if iv_str is initial.
399+
return.
400+
endif.
401+
402+
split iv_str at ':' into lv_key lv_val.
403+
condense lv_key.
404+
condense lv_val.
405+
406+
if lv_key is initial.
407+
return.
408+
endif.
409+
410+
set(
411+
iv_key = lv_key
412+
iv_val = lv_val ).
413+
414+
endmethod.
415+
416+
386417
method size.
387418

388419
rv_size = lines( mt_entries ).

src/zcl_abap_string_map.clas.testclasses.abap

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ltcl_string_map definition
1919
methods keys_values for testing.
2020
methods case_insensitive for testing.
2121
methods set_clike for testing.
22+
methods setx for testing.
2223

2324
methods strict for testing.
2425
methods freeze for testing.
@@ -927,4 +928,27 @@ class ltcl_string_map implementation.
927928

928929
endmethod.
929930

931+
method setx.
932+
933+
data lo_cut type ref to zcl_abap_string_map.
934+
935+
lo_cut = zcl_abap_string_map=>create( ).
936+
937+
lo_cut->setx( 'a:1' ).
938+
lo_cut->setx( |b : 2| ).
939+
lo_cut->setx( ':c' ).
940+
lo_cut->setx( '' ).
941+
942+
cl_abap_unit_assert=>assert_equals(
943+
exp = 2
944+
act = lo_cut->size( ) ).
945+
cl_abap_unit_assert=>assert_equals(
946+
exp = lo_cut->get( 'a' )
947+
act = '1' ).
948+
cl_abap_unit_assert=>assert_equals(
949+
exp = lo_cut->get( 'b' )
950+
act = '2' ).
951+
952+
endmethod.
953+
930954
endclass.

0 commit comments

Comments
 (0)