Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
larshp committed Jul 23, 2024
1 parent 524c69a commit 24e8853
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 9 deletions.
45 changes: 44 additions & 1 deletion cloud/zcl_abapgit_convert.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ CLASS zcl_abapgit_convert DEFINITION
EXCEPTIONS
no_assignment.

TYPES ty_char02 TYPE c LENGTH 2.
CLASS-METHODS uccp
IMPORTING
iv_uccp TYPE string
RETURNING
VALUE(rv_char) TYPE ty_char02
EXCEPTIONS
no_assignment.

PROTECTED SECTION.
PRIVATE SECTION.
CLASS-METHODS xstring_remove_bom
Expand All @@ -135,7 +144,6 @@ ENDCLASS.

CLASS zcl_abapgit_convert IMPLEMENTATION.


METHOD base64_to_xstring.

rv_xstr = cl_web_http_utility=>decode_x_base64( iv_base64 ).
Expand Down Expand Up @@ -519,4 +527,39 @@ CLASS zcl_abapgit_convert IMPLEMENTATION.
GET BIT 8 OF iv_x INTO rv_bitbyte+7(1).

ENDMETHOD.

METHOD uccp.

DATA lv_class TYPE string.
DATA lv_xstr TYPE xstring.
DATA lo_instance TYPE REF TO object.

lv_class = 'CL_ABAP_CONV_IN_CE'.

TRY.
CALL METHOD (lv_class)=>uccp
EXPORTING
uccp = iv_uccp
RECEIVING
char = rv_char.
CATCH cx_sy_dyn_call_illegal_class.
lv_xstr = iv_uccp.

CALL METHOD ('CL_ABAP_CONV_CODEPAGE')=>create_in
EXPORTING
codepage = 'UTF-16'
RECEIVING
instance = lo_instance.

* convert endianness
CONCATENATE lv_xstr+1(1) lv_xstr(1) INTO lv_xstr IN BYTE MODE.

CALL METHOD lo_instance->('IF_ABAP_CONV_IN~CONVERT')
EXPORTING
source = lv_xstr
RECEIVING
result = rv_char.
ENDTRY.

ENDMETHOD.
ENDCLASS.
2 changes: 1 addition & 1 deletion cloud/zcl_abapgit_convert.clas.locals_imp.abap
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ CLASS lcl_bcp47_language_table IMPLEMENTATION.
DATA lv_sap1 TYPE sy-langu.

IF strlen( im_sap1 ) = 4.
lv_sap1 = cl_abap_conv_in_ce=>uccp( im_sap1 ).
lv_sap1 = zcl_abapgit_convert=>uccp( im_sap1 ).
ELSEIF strlen( im_sap1 ) = 1.
lv_sap1 = im_sap1.
ENDIF.
Expand Down
45 changes: 44 additions & 1 deletion open/zcl_abapgit_convert.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ CLASS zcl_abapgit_convert DEFINITION
EXCEPTIONS
no_assignment.

TYPES ty_char02 TYPE c LENGTH 2.
CLASS-METHODS uccp
IMPORTING
iv_uccp TYPE string
RETURNING
VALUE(rv_char) TYPE ty_char02
EXCEPTIONS
no_assignment.

PROTECTED SECTION.
PRIVATE SECTION.
CLASS-METHODS xstring_remove_bom
Expand All @@ -135,7 +144,6 @@ ENDCLASS.

CLASS zcl_abapgit_convert IMPLEMENTATION.


METHOD base64_to_xstring.

rv_xstr = cl_http_utility=>decode_x_base64( iv_base64 ).
Expand Down Expand Up @@ -519,4 +527,39 @@ CLASS zcl_abapgit_convert IMPLEMENTATION.
GET BIT 8 OF iv_x INTO rv_bitbyte+7(1).

ENDMETHOD.

METHOD uccp.

DATA lv_class TYPE string.
DATA lv_xstr TYPE xstring.
DATA lo_instance TYPE REF TO object.

lv_class = 'CL_ABAP_CONV_IN_CE'.

TRY.
CALL METHOD (lv_class)=>uccp
EXPORTING
uccp = iv_uccp
RECEIVING
char = rv_char.
CATCH cx_sy_dyn_call_illegal_class.
lv_xstr = iv_uccp.

CALL METHOD ('CL_ABAP_CONV_CODEPAGE')=>create_in
EXPORTING
codepage = 'UTF-16'
RECEIVING
instance = lo_instance.

* convert endianness
CONCATENATE lv_xstr+1(1) lv_xstr(1) INTO lv_xstr IN BYTE MODE.

CALL METHOD lo_instance->('IF_ABAP_CONV_IN~CONVERT')
EXPORTING
source = lv_xstr
RECEIVING
result = rv_char.
ENDTRY.

ENDMETHOD.
ENDCLASS.
2 changes: 1 addition & 1 deletion open/zcl_abapgit_convert.clas.locals_imp.abap
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ CLASS lcl_bcp47_language_table IMPLEMENTATION.
DATA lv_sap1 TYPE sy-langu.

IF strlen( im_sap1 ) = 4.
lv_sap1 = cl_abap_conv_in_ce=>uccp( im_sap1 ).
lv_sap1 = zcl_abapgit_convert=>uccp( im_sap1 ).
ELSEIF strlen( im_sap1 ) = 1.
lv_sap1 = im_sap1.
ENDIF.
Expand Down
10 changes: 5 additions & 5 deletions open/zcl_abapgit_convert.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ CLASS ltcl_bcp47_to_sap1 IMPLEMENTATION.

METHOD english_gb.
DATA lv_to TYPE sy-langu.
lv_to = cl_abap_conv_in_ce=>uccp( 'B46E' ).
lv_to = zcl_abapgit_convert=>uccp( 'B46E' ).

assert_bcp47_to_sap1( im_from = 'en-GB'
im_to = lv_to ).
Expand All @@ -386,7 +386,7 @@ CLASS ltcl_bcp47_to_sap1 IMPLEMENTATION.

METHOD german_swiss.
DATA lv_to TYPE sy-langu.
lv_to = cl_abap_conv_in_ce=>uccp( 'B3A7' ).
lv_to = zcl_abapgit_convert=>uccp( 'B3A7' ).

assert_bcp47_to_sap1( im_from = 'de-CH'
im_to = lv_to ).
Expand All @@ -404,7 +404,7 @@ CLASS ltcl_bcp47_to_sap1 IMPLEMENTATION.

METHOD chinese_singapore.
DATA lv_to TYPE sy-langu.
lv_to = cl_abap_conv_in_ce=>uccp( 'B343' ).
lv_to = zcl_abapgit_convert=>uccp( 'B343' ).

assert_bcp47_to_sap1( im_from = 'zh-SG'
im_to = lv_to ).
Expand Down Expand Up @@ -495,7 +495,7 @@ CLASS ltcl_sap1_to_bcp47 IMPLEMENTATION.

METHOD english_gb.
DATA lv_from TYPE sy-langu.
lv_from = cl_abap_conv_in_ce=>uccp( 'B46E' ).
lv_from = zcl_abapgit_convert=>uccp( 'B46E' ).

assert_sap1_to_bcp47( im_from = lv_from
im_to = 'en-GB' ).
Expand All @@ -508,7 +508,7 @@ CLASS ltcl_sap1_to_bcp47 IMPLEMENTATION.

METHOD chinese_singapore.
DATA lv_from TYPE sy-langu.
lv_from = cl_abap_conv_in_ce=>uccp( 'B343' ).
lv_from = zcl_abapgit_convert=>uccp( 'B343' ).

assert_sap1_to_bcp47( im_from = lv_from
im_to = 'zh-SG' ).
Expand Down

0 comments on commit 24e8853

Please sign in to comment.