Skip to content

Commit 14ad31f

Browse files
committed
skip_lines_starting_with
1 parent 0f7a41f commit 14ad31f

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

src/core/zcl_text2tab_parser.clas.abap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class zcl_text2tab_parser definition
2020
!i_amount_format type zif_text2tab=>ty_amount_format optional
2121
!i_date_format type zif_text2tab=>ty_date_format optional
2222
!i_begin_comment type zif_text2tab=>ty_begin_comment optional
23+
!i_skip_lines_starting_with type zif_text2tab=>ty_begin_comment optional
2324
!i_deep_provider type ref to zif_text2tab_deep_provider optional
2425
returning
2526
value(ro_parser) type ref to zcl_text2tab_parser
@@ -60,6 +61,7 @@ class zcl_text2tab_parser definition
6061
data mv_line_index type i.
6162
data mv_is_typeless type abap_bool.
6263
data mv_begin_comment type zif_text2tab=>ty_begin_comment.
64+
data mv_skip_lines_starting_with type zif_text2tab=>ty_begin_comment.
6365
data mt_ignore_exits type sorted table of abap_editmask with unique key table_line.
6466

6567
data mt_components type zif_text2tab=>tt_comp_descr.
@@ -244,6 +246,7 @@ CLASS ZCL_TEXT2TAB_PARSER IMPLEMENTATION.
244246
endif.
245247

246248
ro_parser->mv_begin_comment = i_begin_comment.
249+
ro_parser->mv_skip_lines_starting_with = i_skip_lines_starting_with.
247250

248251
endmethod.
249252

@@ -418,6 +421,10 @@ CLASS ZCL_TEXT2TAB_PARSER IMPLEMENTATION.
418421
raise_error( i_msg = 'Empty line cannot be parsed' i_code = 'LE' ). "#EC NOTEXT
419422
endif.
420423

424+
if mv_skip_lines_starting_with is not initial and <dataline>+0(1) = mv_skip_lines_starting_with.
425+
continue. " Skip comment lines
426+
endif.
427+
421428
parse_line(
422429
exporting
423430
i_dataline = <dataline>

src/core/zcl_text2tab_parser.clas.testclasses.abap

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class ltcl_text2tab_parser_test definition for testing
101101
methods deep_structures for testing.
102102
methods parse_corresponding for testing raising zcx_text2tab_error.
103103

104+
methods begin_comments for testing raising zcx_text2tab_error.
105+
methods line_comments for testing raising zcx_text2tab_error.
104106

105107
* ==== HELPERS ===
106108

@@ -1655,4 +1657,69 @@ class ltcl_text2tab_parser_test implementation.
16551657

16561658
endmethod.
16571659

1660+
method begin_comments.
1661+
1662+
data lv_text_orig type string.
1663+
data lt_exp type tt_dummy.
1664+
data lt_act like lt_exp.
1665+
1666+
get_dummy_data(
1667+
importing
1668+
e_dummy_tab = lt_exp
1669+
e_dummy_string = lv_text_orig ).
1670+
1671+
zcl_text2tab_parser=>create(
1672+
i_pattern = lt_act
1673+
i_begin_comment = '#'
1674+
)->parse(
1675+
exporting
1676+
i_data = |#comment{ c_crlf }{ lv_text_orig }|
1677+
importing
1678+
e_container = lt_act ).
1679+
1680+
cl_abap_unit_assert=>assert_equals(
1681+
act = lt_act
1682+
exp = lt_exp ).
1683+
1684+
zcl_text2tab_parser=>create(
1685+
i_pattern = lt_act
1686+
i_begin_comment = zif_text2tab=>c_auto_detect_by_space
1687+
)->parse(
1688+
exporting
1689+
i_data = |field descr with space\tanother one...{ c_crlf }{ lv_text_orig }|
1690+
importing
1691+
e_container = lt_act ).
1692+
1693+
cl_abap_unit_assert=>assert_equals(
1694+
act = lt_act
1695+
exp = lt_exp ).
1696+
1697+
endmethod.
1698+
1699+
method line_comments.
1700+
1701+
data lv_text_orig type string.
1702+
data lt_exp type tt_dummy.
1703+
data lt_act like lt_exp.
1704+
1705+
get_dummy_data(
1706+
importing
1707+
e_dummy_tab = lt_exp
1708+
e_dummy_string = lv_text_orig ).
1709+
1710+
zcl_text2tab_parser=>create(
1711+
i_pattern = lt_act
1712+
i_skip_lines_starting_with = '#'
1713+
)->parse(
1714+
exporting
1715+
i_data = |{ lv_text_orig }#comment| " CRLF is already at the end, no need to add
1716+
importing
1717+
e_container = lt_act ).
1718+
1719+
cl_abap_unit_assert=>assert_equals(
1720+
act = lt_act
1721+
exp = lt_exp ).
1722+
1723+
endmethod.
1724+
16581725
endclass.

0 commit comments

Comments
 (0)