Page 1 of 1

LeftUTF8(String, Pos)

Posted: Sat May 21, 2005 6:41 pm
by oryaaaaa
Code updated For 5.20+

Code: Select all

Procedure.s LeftUTF8(Utf8.s, Utf8_index.b)
  Utf8_result.s="" : Utf8_Total.b=1
  Utf8_len=Len(Utf8)
  For Utf8_pos=1 To Utf8_len
    If Asc(Mid(Utf8, Utf8_pos, 1))<$80
      If Utf8_index=>Utf8_Total
        Utf8_result+Mid(Utf8, Utf8_pos, 1)
        Utf8_Total+1
      EndIf
    ElseIf Asc(Mid(Utf8, Utf8_pos, 1))>$C1 And Asc(Mid(Utf8, Utf8_pos, 1))<$E0
      If Utf8_index=>(Utf8_Total+1)
        Utf8_result+Mid(Utf8, Utf8_pos, 2)
        Utf8_pos+1
        Utf8_Total+2
      EndIf
    ElseIf Asc(Mid(Utf8, Utf8_pos, 1))>$DF And Asc(Mid(Utf8, Utf8_pos, 1))<$F0
      If Utf8_index=>(Utf8_Total+1)
        Utf8_result+Mid(Utf8, Utf8_pos, 3)
        Utf8_pos+2
        Utf8_Total+2
      EndIf
    Else
      If Utf8_index=>(Utf8_Total+1)
        Utf8_result+Mid(Utf8, Utf8_pos, 4)
        Utf8_pos+3
        Utf8_Total+2
      EndIf 
    EndIf 
  Next
  ProcedureReturn Utf8_result 
EndProcedure
Return UTF-8 Strings

TX

Posted: Sat May 21, 2005 7:10 pm
by Droopy
what's this function do ? :shock:

Posted: Sun May 22, 2005 3:43 am
by Xombie
Aren't UTF-8 strings wide character?

Posted: Tue May 24, 2005 11:38 am
by oryaaaaa
Oh...

UTF-8 (WideCharactor ex:Japanese, Korea, China... etc) :)

Posted: Tue May 24, 2005 2:18 pm
by zikitrake
A sample, please...

My ZikiTranslator will be more nice if I could add it Chinese and Japanese languages.

thank you!

Posted: Tue May 24, 2005 9:21 pm
by Blade
@oryaaaaa
Hi, in my system (Win2000 wich usually handles correctly japanese filenames, despite it's not a Win-J) command such as OpenFile fails when trying to load those files...
Do you have the same problem in your (I assume) Japanese Windows?
Have you found some solution?

Posted: Thu May 26, 2005 6:27 pm
by oryaaaaa
Sample Japanese
Image

Code: Select all

Procedure.s UTF8toSJIS(U2S.s)
  *u2s_out = AllocateMemory(1024) 
  l = MultiByteToWideChar_(#CP_UTF8,0,@U2S,-1,0,0) 
  l = MultiByteToWideChar_(#CP_UTF8,0,@U2S,-1,*u2s_out,l) 
  l = WideCharToMultiByte_(#CP_ACP,0,*u2s_out,-1,0,0,0,0) 
  u2s_out2.s = Space(l) 
  l = WideCharToMultiByte_(#CP_ACP,0,*u2s_out,-1,@u2s_out2,l,0,0)
  FreeMemory(*u2s_out)
  ProcedureReturn u2s_out2
EndProcedure

Procedure.s SJIStoUTF8(s2u.s)
  #CP_UTF8=65001
  *s2u_out = AllocateMemory(1024) 
  l = MultiByteToWideChar_(#CP_OEMCP,0,@s2u,-1,0,0) 
  l = MultiByteToWideChar_(#CP_OEMCP,0,@s2u,-1,*s2u_out,l) 
  l = WideCharToMultiByte_(#CP_UTF8,0,*s2u_out,-1,0,0,0,0) 
  s2u_out2.s = Space(l) 
  l = WideCharToMultiByte_(#CP_UTF8,0,*s2u_out,-1,@s2u_out2,l,0,0)
  FreeMemory(*s2u_out)
  ProcedureReturn s2u_out2
EndProcedure
kore wa SJIS denakutemo iikamo...

Posted: Mon Jun 06, 2005 7:34 am
by oryaaaaa
@blade

Code: Select all

For i=0 To 100
  String1.s=""
  For S1.b=0 To 70
    String1.s+Chr(Random(100)+64)
  Next
  If CreateFile(1,String1)
  UseFile(1)
  WriteStringN("TEST")
  CloseFile(1)
  EndIf 
  If ReadFile(1, String1)
    Debug "OK"
    ;Debug String1
    CloseFile(1)
  Else
    Debug "NG"
    ;Debug String1 
  EndIf
  DeleteFile(String1)
Next
Windows Japanese Edition (Win2000-SP4-JPN)
NG
NG
NG
NG
NG
NG
NG
OK
OK
OK
OK
NG
NG
NG
OK
NG
NG
OK
OK
NG
NG
OK
OK
NG
NG
OK
NG
NG
OK
NG
OK
OK
OK
NG
OK
NG
NG
OK
OK
OK
NG
OK
NG
NG
NG
NG
NG
NG
OK
NG
NG
NG
NG
NG
OK
NG
NG
NG
NG
OK
NG
OK
NG
NG
NG
NG
NG
NG
NG
NG
NG
OK
NG
NG
OK
NG
NG
NG
NG
NG
OK
OK
NG
NG
OK
NG
NG
OK
NG
NG
NG
NG
NG
NG
NG
NG
NG
OK
NG
NG
OK
A better test doesn't hit on.