22/10/2010

First Char to Upper: Regex Vs Function


REPORT ZADN_SAMPLE.

*----------------------------------------------------------------------*
* -> CLASS cl_regex_vs_Function DEFINITION
*----------------------------------------------------------------------*
CLASS cl_regex_vs_function DEFINITION.

PUBLIC SECTION.

METHODS : first_char_to_upper_regex IMPORTING p_text TYPE char50,
first_char_to_upper_function IMPORTING p_text TYPE char50.

PRIVATE SECTION.

DATA : v_input_text TYPE c LENGTH 50,
v_match TYPE match_result.

DATA : it_matches TYPE match_result_tab.

ENDCLASS. "cl_regex_vs_Function DEFINITION


*----------------------------------------------------------------------*
* -> CLASS cl_regex_vs_Function IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS cl_regex_vs_function IMPLEMENTATION.

METHOD first_char_to_upper_regex.

me->v_input_text = p_text.

WRITE / me->v_input_text.

FIND ALL OCCURRENCES OF REGEX '\<[[:lower:]]' IN me->v_input_text RESULTS me->it_matches.

LOOP AT me->it_matches INTO me->v_match.

TRANSLATE me->v_input_text+me->v_match-offset(1) TO UPPER CASE.

ENDLOOP.

WRITE / me->v_input_text.

CLEAR : me->v_input_text,
me->v_match.

REFRESH me->it_matches.

ENDMETHOD. "first_char_to_upper_regex

METHOD first_char_to_upper_function.

me->v_input_text = p_text.

WRITE / me->v_input_text.

CALL FUNCTION 'ISP_CONVERT_FIRSTCHARS_TOUPPER'
EXPORTING
input_string = me->v_input_text
separators = ' -.,;:'
IMPORTING
output_string = me->v_input_text.

WRITE / me->v_input_text.

CLEAR : me->v_input_text.

ENDMETHOD. "first_char_to_upper_function

ENDCLASS. "cl_regex_vs_Function IMPLEMENTATION

************************************************************************
************************************************************************
* *
* PROGRAM FLOW LOGIC *
* *
************************************************************************

PARAMETERS : pa_text TYPE char50.

START-OF-SELECTION.

DATA : o_cl_regex_vs_function TYPE REF TO cl_regex_vs_function.

CREATE OBJECT o_cl_regex_vs_function.

IF o_cl_regex_vs_function IS BOUND.

o_cl_regex_vs_function->first_char_to_upper_regex( pa_text ).

ULINE.

o_cl_regex_vs_function->first_char_to_upper_function( pa_text ).

ENDIF.

Nenhum comentário:

Postar um comentário