Skip to content
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

v2.2.0 added comment lines #4

Merged
merged 3 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Legend
+ : added
- : removed

v2.2.0, 2018-11-09
------------------
+ comment lines

v2.1.0, 2018-11-08
------------------
+ field name mapping feature (rename fields on-the-fly)
Expand Down
29 changes: 24 additions & 5 deletions zcl_text2tab_parser.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public section.
!I_PATTERN type ANY " target structure or table
!I_AMOUNT_FORMAT type CHAR2 optional
!I_DATE_FORMAT type CHAR4 optional
i_begin_comment TYPE clike OPTIONAL
returning
value(RO_PARSER) type ref to ZCL_TEXT2TAB_PARSER
raising
Expand Down Expand Up @@ -56,6 +57,7 @@ private section.
data MV_CURRENT_FIELD type STRING .
data MV_LINE_INDEX type SY-TABIX .
data MV_IS_TYPELESS type ABAP_BOOL .
data MV_BEGIN_COMMENT type char1.

methods PARSE_TYPEFULL
importing
Expand Down Expand Up @@ -160,6 +162,7 @@ private section.
class-methods BREAK_TO_LINES
importing
!I_TEXT type STRING
i_begin_comment TYPE char1
returning
value(RT_TAB) type STRING_TABLE .
ENDCLASS.
Expand Down Expand Up @@ -201,10 +204,11 @@ method APPLY_CONV_EXIT.
endmethod. "apply_conv_exit


method BREAK_TO_LINES.
method break_to_lines.
data:
l_found type i,
l_break type string value c_crlf.
l_found type i,
l_break type string value c_crlf.
field-symbols: <line> type string.

" Detect line break
l_found = find( val = i_text sub = c_crlf ).
Expand All @@ -217,6 +221,19 @@ method BREAK_TO_LINES.

split i_text at l_break into table rt_tab.

if i_begin_comment <> space.
loop at rt_tab assigning <line>.
try.
if <line>+0(1) = i_begin_comment.
delete rt_tab index sy-tabix.
endif.
catch cx_sy_range_out_of_bounds.
" if the row only consist of a linefeed. Some text editors add always a line feed at the end of the document
delete rt_tab index sy-tabix.
endtry.
endloop.
endif.

endmethod.


Expand All @@ -239,6 +256,8 @@ method CREATE.
ro_parser->mv_date_format = i_date_format.
endif.

ro_parser->mv_begin_comment = i_begin_comment.

endmethod. "create


Expand Down Expand Up @@ -800,7 +819,7 @@ method PARSE_TYPEFULL.
raise_error( msg = 'Container type does not fit pattern' code = 'TE' ). "#EC NOTEXT
endif.

lt_data = break_to_lines( i_data ).
lt_data = break_to_lines( i_text = i_data i_begin_comment = mv_begin_comment ).

" Read and process header line
if i_has_head = abap_true.
Expand Down Expand Up @@ -835,7 +854,7 @@ endmethod. "parse_typefull
data lt_map type int4_table.
field-symbols <f> like line of e_head_fields.

lt_data = break_to_lines( i_data ).
lt_data = break_to_lines( i_text = i_data i_begin_comment = mv_begin_comment ).

" Read and process header line
parse_head_line(
Expand Down
15 changes: 13 additions & 2 deletions zcl_text2tab_parser.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,20 @@ class lcl_text2tab_parser_test implementation.
append 'line1' to lt_exp.
append 'line2' to lt_exp.

lt_act = zcl_text2tab_parser=>break_to_lines( 'line1' && c_crlf && 'line2' ).
lt_act = zcl_text2tab_parser=>break_to_lines( i_text = 'line1' && c_crlf && 'line2'
i_begin_comment = space ).
cl_abap_unit_assert=>assert_equals( act = lt_act exp = lt_exp ).
lt_act = zcl_text2tab_parser=>break_to_lines( 'line1' && c_lf && 'line2' ).
lt_act = zcl_text2tab_parser=>break_to_lines( i_text = 'line1' && c_lf && 'line2'
i_begin_comment = space ).
cl_abap_unit_assert=>assert_equals( act = lt_act exp = lt_exp ).

" with comment line
clear lt_exp.
append 'not a comment 1' to lt_exp.
append 'not a comment 2' to lt_exp.
lt_act = zcl_text2tab_parser=>break_to_lines( i_text =
'*a comment' && c_lf && 'not a comment 1' && c_lf && 'not a comment 2' && c_lf
&& cl_abap_char_utilities=>newline i_begin_comment = '*' ).
cl_abap_unit_assert=>assert_equals( act = lt_act exp = lt_exp ).

endmethod. " break_to_lines.
Expand Down
2 changes: 1 addition & 1 deletion zcl_text2tab_parser.clas.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
sbcgua marked this conversation as resolved.
Show resolved Hide resolved
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
Expand Down
2 changes: 1 addition & 1 deletion zcl_text2tab_serializer.clas.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
Expand Down
2 changes: 1 addition & 1 deletion zcl_text2tab_utils.clas.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
Expand Down
2 changes: 1 addition & 1 deletion zcx_text2tab_error.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ENDCLASS.
CLASS ZCX_TEXT2TAB_ERROR IMPLEMENTATION.


method CONSTRUCTOR.
method CONSTRUCTOR ##ADT_SUPPRESS_GENERATION.
CALL METHOD SUPER->CONSTRUCTOR
EXPORTING
PREVIOUS = PREVIOUS
Expand Down
2 changes: 1 addition & 1 deletion zcx_text2tab_error.clas.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
Expand Down
9 changes: 1 addition & 8 deletions ztext2tab_example.prog.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_PROG" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
Expand All @@ -11,13 +11,6 @@
<FIXPT>X</FIXPT>
<UCCHECK>X</UCCHECK>
</PROGDIR>
<TPOOL>
<item>
<ID>R</ID>
<ENTRY>Table parser</ENTRY>
<LENGTH>12</LENGTH>
</item>
</TPOOL>
</asx:values>
</asx:abap>
</abapGit>