Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *&---------------------------------------------------------------------*
- *& Report ZZ_TEST_REPLACE_IRREGULAR
- *&---------------------------------------------------------------------*
- *& In runtime terms:
- *& Using a precompiled regular expression repeatedly,
- *& equals using the same regular expression STRING repeatedly
- *& (shows that there is an internal buffering of the last regex)
- *&---------------------------------------------------------------------*
- report zz_test_replace_irregular.
- parameters: p_num type i default 1000,
- p_len type i default 100,
- p_seed type i default 14527.
- start-of-selection.
- perform start.
- * ---
- form start.
- data: lt_text type stringtab,
- lv_text type string.
- field-symbols: <lv_text> type string.
- perform make_sample using p_num p_len p_seed
- changing lt_text.
- loop at lt_text assigning <lv_text>.
- lv_text = <lv_text>.
- perform replace1 using '.' lv_text.
- lv_text = <lv_text>.
- perform replace2 using '.' lv_text.
- endloop.
- endform. "start
- * ---
- form replace1 using iv_default type char01
- changing cv_text type csequence.
- statics: sv_pattern type string.
- if sv_pattern is initial.
- perform get_pattern changing sv_pattern.
- endif.
- replace all occurrences of regex sv_pattern in cv_text with iv_default.
- endform. "replace1
- *
- form get_pattern changing cv_pattern type string.
- data: lv_allowed_char type string.
- call function 'RSKC_ALLOWED_CHAR_GET'
- importing
- e_allowed_char = lv_allowed_char.
- concatenate '([^' lv_allowed_char '])' into cv_pattern.
- endform. "get_pattern
- * ---
- form replace2 using iv_default type char01
- changing cv_text type csequence.
- statics: so_regex type ref to cl_abap_regex.
- data: lv_pattern type string.
- if so_regex is initial.
- perform get_pattern changing lv_pattern.
- create object so_regex
- exporting
- pattern = lv_pattern.
- endif.
- replace all occurrences of regex so_regex in cv_text with iv_default.
- endform. "replace2
- *
- form make_sample using iv_num type i
- iv_len type i
- iv_seed type i
- changing ct_text type stringtab.
- data:
- lo_ran type ref to cl_abap_random_int,
- lv_x type x length 2,
- lv_c type c,
- lv_seed type i,
- lv_text type string.
- lo_ran = cl_abap_random_int=>create( min = 32 max = 255 seed = iv_seed ).
- do iv_num times.
- clear lv_text.
- do iv_len times.
- lv_x = lo_ran->get_next( ).
- lv_c = cl_abap_conv_in_ce=>uccp( lv_x ).
- concatenate lv_text lv_c into lv_text respecting blanks.
- enddo.
- append lv_text to ct_text.
- enddo.
- endform. "make_sample
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement