Skip to content

setx feature #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ lo_map->set(
iv_val = '2' ).
```

- there is also `setx` - a more readable yet not so strict version of `set`. Can be useful for multiple sets in a raw.

```abap
lo_map->setx( 'A:1' )->setx( |B : { '2' }| ).
```

- implements `keys`, `values`

```abap
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Legend
v1.0.4, 2024-06-24
------------------
+ to_entries - saves entries to a standard table with 2 char-like components (#11)
+ setx - simplified and more readable version of set (#12)

v1.0.3, 2021-07-25
------------------
Expand Down
31 changes: 31 additions & 0 deletions src/zcl_abap_string_map.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class zcl_abap_string_map definition
!iv_val type clike
returning
value(ro_map) type ref to zcl_abap_string_map.
methods setx
importing
!iv_str type csequence
returning
value(ro_map) type ref to zcl_abap_string_map.
methods size
returning
value(rv_size) type i.
Expand Down Expand Up @@ -383,6 +388,32 @@ CLASS ZCL_ABAP_STRING_MAP IMPLEMENTATION.
endmethod.


method setx.

data lv_key type string.
data lv_val type string.

ro_map = me.

if iv_str is initial.
return.
endif.

split iv_str at ':' into lv_key lv_val.
condense lv_key.
condense lv_val.

if lv_key is initial.
return.
endif.

set(
iv_key = lv_key
iv_val = lv_val ).

endmethod.


method size.

rv_size = lines( mt_entries ).
Expand Down
24 changes: 24 additions & 0 deletions src/zcl_abap_string_map.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ltcl_string_map definition
methods keys_values for testing.
methods case_insensitive for testing.
methods set_clike for testing.
methods setx for testing.

methods strict for testing.
methods freeze for testing.
Expand Down Expand Up @@ -927,4 +928,27 @@ class ltcl_string_map implementation.

endmethod.

method setx.

data lo_cut type ref to zcl_abap_string_map.

lo_cut = zcl_abap_string_map=>create( ).

lo_cut->setx( 'a:1' ).
lo_cut->setx( |b : 2| ).
lo_cut->setx( ':c' ).
lo_cut->setx( '' ).

cl_abap_unit_assert=>assert_equals(
exp = 2
act = lo_cut->size( ) ).
cl_abap_unit_assert=>assert_equals(
exp = lo_cut->get( 'a' )
act = '1' ).
cl_abap_unit_assert=>assert_equals(
exp = lo_cut->get( 'b' )
act = '2' ).

endmethod.

endclass.
Loading