Skip to content

Commit

Permalink
support for LF line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sbcgua committed Aug 12, 2018
1 parent bfbd51c commit e7076fa
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
30 changes: 27 additions & 3 deletions src/zcl_mockup_loader.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ class ZCL_MOCKUP_LOADER definition
public section.

types:
tt_string type table of string .
tt_string type standard table of string with default key.
types:
begin of ty_store,
name type char40,
tabkey type abap_compname,
data type ref to data,
end of ty_store .
types:
tt_store type table of ty_store with key name .
tt_store type standard table of ty_store with key name .
types:
begin of ty_filter,
name type string,
Expand Down Expand Up @@ -230,13 +230,37 @@ private section.
!E_DATA type ANY
raising
CX_STATIC_CHECK .
class-methods BREAK_TO_LINES
importing
!I_TEXT type STRING
returning
value(RT_TAB) type TT_STRING .
ENDCLASS.



CLASS ZCL_MOCKUP_LOADER IMPLEMENTATION.


method break_to_lines.
data:
l_found type i,
l_break type string value cl_abap_char_utilities=>cr_lf.

" Detect line break
l_found = find( val = i_text sub = cl_abap_char_utilities=>cr_lf ).
if l_found < 0.
l_found = find( val = i_text sub = cl_abap_char_utilities=>form_feed ).
if l_found >= 0.
l_break = cl_abap_char_utilities=>form_feed.
endif.
endif.

split i_text at l_break into table rt_tab.

endmethod.


method BUILD_FILTER.
data dy_templ type ref to cl_abap_tabledescr.
data dy_type type ref to cl_abap_typedescr.
Expand Down Expand Up @@ -731,7 +755,7 @@ method parse_data.
endif.

" Read and process header line
split i_rawdata at cl_abap_char_utilities=>cr_lf into table lt_lines.
lt_lines = break_to_lines( i_rawdata ).
read table lt_lines into ls_line index 1.
if sy-subrc <> 0.
lcx_error=>raise( msg = 'No header line found in the file' code = 'NH' ). "#EC NOTEXT
Expand Down
20 changes: 20 additions & 0 deletions src/zcl_mockup_loader.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class lcl_test_mockup_loader definition for testing
private section.
constants c_tab like cl_abap_char_utilities=>horizontal_tab value cl_abap_char_utilities=>horizontal_tab.
constants c_crlf like cl_abap_char_utilities=>cr_lf value cl_abap_char_utilities=>cr_lf.
constants c_lf like cl_abap_char_utilities=>form_feed value cl_abap_char_utilities=>form_feed.

data o type ref to zcl_mockup_loader. "class under test

Expand All @@ -134,6 +135,7 @@ class lcl_test_mockup_loader definition for testing
methods integrated_test for testing.
methods source_redirect_test for testing.
methods utf16_encoding for testing.
methods break_to_lines for testing.

methods parse_data for testing.
methods parse_field for testing.
Expand Down Expand Up @@ -383,6 +385,24 @@ class lcl_test_mockup_loader implementation.

endmethod. "utf16_encoding

**********************************************************************
* Break to lines, line break detection
**********************************************************************
method break_to_lines.
data:
lt_act type string_table,
lt_exp type string_table.

append 'line1' to lt_exp.
append 'line2' to lt_exp.

lt_act = zcl_mockup_loader=>break_to_lines( 'line1' && c_crlf && 'line2' ).
assert_equals( act = lt_act exp = lt_exp ).
lt_act = zcl_mockup_loader=>break_to_lines( 'line1' && c_lf && 'line2' ).
assert_equals( act = lt_act exp = lt_exp ).

endmethod. " break_to_lines

**********************************************************************
* Test of data parser - dummy data is supplied to the tested method
**********************************************************************
Expand Down
7 changes: 6 additions & 1 deletion src/zcl_mockup_loader.clas.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@
<UNICODE>X</UNICODE>
<WITH_UNIT_TESTS>X</WITH_UNIT_TESTS>
</VSEOCLASS>
<TPOOL/>
<DESCRIPTIONS>
<SEOCOMPOTX>
<CLSNAME>ZCL_MOCKUP_LOADER</CLSNAME>
<CMPNAME>AT_STORE</CMPNAME>
<LANGU>E</LANGU>
<DESCRIPT>Store table</DESCRIPT>
</SEOCOMPOTX>
<SEOCOMPOTX>
<CLSNAME>ZCL_MOCKUP_LOADER</CLSNAME>
<CMPNAME>BREAK_TO_LINES</CMPNAME>
<LANGU>E</LANGU>
<DESCRIPT>Break string into lines</DESCRIPT>
</SEOCOMPOTX>
<SEOCOMPOTX>
<CLSNAME>ZCL_MOCKUP_LOADER</CLSNAME>
<CMPNAME>BUILD_FILTER</CMPNAME>
Expand Down
1 change: 0 additions & 1 deletion src/zmockup_loader_example.prog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<FIXPT>X</FIXPT>
<UCCHECK>X</UCCHECK>
</PROGDIR>
<DYNPROS/>
<TPOOL>
<item>
<ID>R</ID>
Expand Down
1 change: 0 additions & 1 deletion src/zmockup_loader_switch_source.prog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<FIXPT>X</FIXPT>
<UCCHECK>X</UCCHECK>
</PROGDIR>
<DYNPROS/>
<TPOOL>
<item>
<ID>R</ID>
Expand Down

0 comments on commit e7076fa

Please sign in to comment.