/*

CLASS {NATIVE_String_functions|_Android}, NATIVE, BYTES, BITWISE :

IMPORT: {String_functions} .

CONST STR:
	

	NATIVE_import_string_functions = @
	""

	NATIVE_Path_sep = "    RESULT = java.io.File.separator;"
	
	NATIVE_Char = "RESULT = " #QU #QU " + (char)X_I;"
	
	NATIVE_Ord = "RESULT = (int)((X_Ch + (char)0).charAt(0));"
	
	NATIVE_Upper = "RESULT = X_S.toUpperCase();"
	
	NATIVE_Lower = "RESULT = X_S.toLowerCase();"
	
	NATIVE_Trim = "RESULT = X_S.trim();"
	
	NATIVE_TrimL = "RESULT := TrimLeft(X_S);"
    
    NATIVE_TrimR = "RESULT := TrimRight(X_S);"
    
    NATIVE_Split = "Do_split_string(X_Dest, X_S, X_By);"
    
    NATIVE_Repeat = @
	"StringBuilder sb = new StringBuilder(X_What.length() * X_Count);"
	"for (int i = 0; i < X_Count; i++) sb.append(X_What);"
	"RESULT = sb.toString();"     

    
    NATIVE_Bytes_to_ascii = @
    "    RESULT = new String(X_B.ToArray(), " #QU "US-ASCII" #QU ");"
	
	NATIVE_Bytes_to_utf8 = @
	"    RESULT = new String(X_B.ToArray(), " #QU "UTF-8" #QU ");"
	
	NATIVE_Bytes_to_utf7 = ""
	
	NATIVE_Bytes_to_utf16 = @
	"    RESULT = new String(X_B.ToArray(), " #QU "UTF-16" #QU ");"
	
	NATIVE_Bytes_to_utf16_big = @
	"    RESULT = new String(X_B.ToArray(), " #QU "UTF-16BE" #QU ");"
	
	NATIVE_Bytes_to_utf32 = @
	"" 
	
	NATIVE_Bytes_to_utf32_big = @
	""
    
    NATIVE_Bytes_from_ascii = @
    "    byte[] buffer = X_S.getBytes(" #QU "US-ASCII" #QU ");"
    "    X_D.Clear();"
    "    X_D.Reallocate(buffer.length);"
    "    for (int i = 0; i < buffer.length; i++)"
    "        X_D.Set_item(i, buffer[i]);"
    
    NATIVE_Bytes_from_utf8 = @
	"    byte[] buffer = X_S.getBytes(" #QU "UTF-8" #QU ");"
    "    X_D.Clear();"
    "    X_D.Reallocate(buffer.length);"
    "    for (int i = 0; i < buffer.length; i++)"
    "        X_D.Set_item(i, buffer[i]);"
	
 	NATIVE_Bytes_from_utf7 = ""
    
    NATIVE_Bytes_from_utf16 = @
    "    byte[] buffer = X_S.getBytes(" #QU "UTF-16" #QU ");"
    "    int start = 0;"
    "    if (buffer.length >= 2 && buffer[0] == (byte)0xFE &&"
    "       buffer[1] == (byte)0xFF) start = 2;"
    "    X_D.Clear();"
    "    X_D.Reallocate(buffer.length - start);"
    "    for (int i = 0; i < buffer.length - start; i++)"
    "        X_D.Set_item(i, buffer[i + start]);" 
    
    NATIVE_Bytes_from_utf16_big_endian = @
	"    byte[] buffer = X_S.getBytes(" #QU "UTF-16BE" #QU ");"
    "    int start = 0;"
    "    if (buffer.length > 2 && (int)buffer[0] == (byte)0xFF &&"
    "       buffer[1] == (byte)0xFE) start = 2;"
    "    X_D.Clear();"
    "    X_D.Reallocate(buffer.length - start);"
    "    for (int i = 0; i < buffer.length - start; i++)"
    "        X_D.Set_item(i, buffer[i + start]);"
    
    NATIVE_Bytes_from_utf32 = ""
    
    NATIVE_Bytes_from_utf32_big_endian = ""
    
    NATIVE_Unicode16_to_ANSI = "" 
    
	NATIVE_Oem_to_string = "" // "X_S.setStrings(1, X_S.getStrings(0));" 
	
	NATIVE_Ansi_bytes_to_utf8 = "" 
    .
    

FUN Trim_right_string(STR S|tring_to_trim) ==> STR :
    FOR i IN [S.Len-1 DOWNTO 0] :
        CASE S.[i] > " " ? RESULT = S.[0 TO i] ==> ;
    ;
    RESULT = "" .

FUN Trim_left_string(STR S|tring_to_trim) ==> STR :
    FOR i IN [0 TO S.Len-1] :
        CASE S.[i] > " " ? RESULT = S.[i TO *] ==> ;
    ;
    RESULT = "" .
    
FUN Trim_string(STR S|tring_to_trim) ==> STR :
	RESULT = S.TrimR.TrimL .

FUN Split_string_native(
STR Dest|ination_buffer[], STR S|tring_to_trim, STR By|_separator)
    :
    Dest[].Clear
    INT from|_position = 0
    FOR i IN [0 TO S.Len - By.Len] :
        CASE from <= i && S.[i TO i + By.Len - 1] == By ?
             Dest[] << S.[from TO i-1]
             from = i + By.Len ;
    ;
    CASE from < S.Len ? Dest[] << S.[from TO *] ; .
    
FUN Get_inner_encoding
|_of_strings_in_the_environment ==> {String_functions}.{encoding}
	:= 'UTF8' .

FUN Is_encoding_supported({encoding} E|ncoding) ==> BOOL : 
    CASE E ?
    ['DEFAULT', 'ASCII', 'UTF8', 'UTF16', 'UTF16_BIG']: RESULT = TRUE
    ['UTF7', 'UTF32', 'UTF32_BIG']: RESULT = FALSE ; .
     
FUN Get_bytes_from_default(
	BYTE D|estination[], STR S|ource_string ), NATIVE
	: NATIVE NATIVE_Bytes_from_ascii .
	
	
END
*/

