Insert Chars
May 22, 2020 21:30:20 GMT 1
Post by alexfish on May 22, 2020 21:30:20 GMT 1
Hi Peter
here trying to split a string using two MID$ functions
the concat a 3rd string
the result = "" NULL string
yet function will print the results
any ideas
BR
Alex
here trying to split a string using two MID$ functions
the concat a 3rd string
the result = "" NULL string
yet function will print the results
any ideas
GLOBAL A$ , B$ TYPE STRING
FUNCTION next_utf8_char(unsigned char *utf8, int *codepoint ,int * ps) TYPE unsigned char *
LOCAL seqlen=0 TYPE int
LOCAL p = utf8 TYPE unsigned char *
'0xxxxxxx
IF NOT(utf8[0] & 0x80) THEN
*codepoint = (wchar_t) utf8[0];
seqlen = 1
'110xxxxx
ELIF (utf8[0] & 0xE0) == 0xC0 THEN
*codepoint = (int)(((utf8[0] & 0x1F) << 6) | (utf8[1] & 0x3F))
seqlen = 2
ELIF (utf8[0] & 0xF0) == 0xE0 THEN
*codepoint = (int)(((utf8[0] & 0x0F) << 12) | ((utf8[1] & 0x3F) << 6) | (utf8[2] & 0x3F))
seqlen = 3
ELSE
RETURN NULL
END IF
*ps = seqlen
INCR p , seqlen
RETURN p
END FUNCTION
' ==============================================================================
SUB utf_Info( const char *s)
LOCAL character,ptr,cdp TYPE int
LOCAL ss TYPE unsigned char *
ss = (unsigned char *)s
WHILE (ss ) DO
ss = next_utf8_char(ss, &character, &cdp)
IF (ss == NULL) THEN
BREAK
END IF
PRINT "char :", ptr , ":" , cdp
' printf ("char : %d : %d\n", ptr , cdp);
INCR ptr
WEND
END SUB
' ==============================================================================
FUNCTION GetPostition( char * s,int pos) TYPE int
LOCAL character,ptr,cdp,ps TYPE int
LOCAL ss TYPE unsigned char *
ss = (unsigned char *)s
WHILE ss DO
ss = next_utf8_char(ss, &character, &cdp)
IF (ss == NULL) THEN
RETURN ps
END IF
IF ptr == pos THEN
RETURN ps
BREAK
END IF
INCR ps,cdp
INCR ptr
WEND
RETURN ps
END FUNCTION
' ==============================================================================
FUNCTION InsertChars( STRING C$,int pos ,STRING ch$) TYPE STRING
PRINT "THIS " , C$
LOCAL x TYPE int
LOCAL AB$ TYPE STRING
AB$= C$
LOCAL CP$ TYPE STRING
CP$ = AB$
LOCAL r$ TYPE STRING
LOCAL sp$ TYPE STRING
x= GetPostition(AB$,pos)
PRINT x
sp$ = MID$(AB$,1,x)
PRINT "Left " , sp$
r$ = MID$(CP$,x+1)
PRINT "Right :", r$
C$ = sp$ & ch$ & r$
PRINT "RESULT :" , C$
RETURN C$
END FUNCTION
' ==============================================================================
DECLARE hello[] = {'H','e','j',',',' ', 0xf0, 0x9f,0x98,0x81,0} TYPE char
LOCAL AA$ ,BB$ TYPE STRING
AA$ = hello
PRINT "String : " , AA$
A$ = InsertChars(AA$,3,"€")
PRINT "Return :" , A$
BR
Alex