Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

AHKL: IniRead/IniWrite and UTF8


  • Please log in to reply
20 replies to this topic
ruespe
  • Members
  • 567 posts
  • Last active: Dec 01 2014 07:59 PM
  • Joined: 17 Jun 2008

Also, keep in mind that whatever the solution to your (ruespe's) particular problem, Compile_AHK.exe would need to be recompiled with modifications and/or AutoHotkey_L.

Yessir, that was clear to me.

I now solved the problems... ehem... challenges :wink: and adapted Compile_AHK to AHK_L, so that it works for me now. After testing it a while, I will talk to Ladiko for an update.

dysmas
  • Members
  • 63 posts
  • Last active: Apr 06 2011 11:01 AM
  • Joined: 28 Dec 2010
Just in case ruespe would be interested in a bad but working solution :

   file1 := fileOpen("toto", "w")
   file1.write($data) 
   file1 := fileOpen("toto", "r")
   file1.Encoding := cp850                      ; cp850 ? ou 1252 ?
   data2 := file1.ReadLine()                    ; Now I have a utf-8 string which can be written to the ini file
   file1.close()
   
   file1 := fileOpen("toto", "w")
   file1.write($key) 
   file1 := fileOpen("toto", "r")
   file1.Encoding := cp850                      ; cp850 ? ou 1252 ?
   $key2 := file1.ReadLine()
   file1.close()
   
   IniWrite, %data2%, %iniFilename%, perso, %$key2%


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
cp850 is the name of an empty variable, which would probably be interpreted as "use the system default". You could probably omit the assignment entirely. If not, use "CP1252" including quotation marks.

Anyway, what's your "solution" got to do with UTF-8?

ruespe
  • Members
  • 567 posts
  • Last active: Dec 01 2014 07:59 PM
  • Joined: 17 Jun 2008
I did the workaround in Compile_AHK by
- extracting the Ini-part out of the UTF-8-script-code,
- storing it temporary as norma Ini-file,
- working with this,
- updating the script with the changes made in GUI and
- deleting the Ini-file at the end.

dysmas
  • Members
  • 63 posts
  • Last active: Apr 06 2011 11:01 AM
  • Joined: 28 Dec 2010

cp850 is the name of an empty variable, which would probably be interpreted as "use the system default". You could probably omit the assignment entirely. If not, use "CP1252" including quotation marks.

Yes you are right, sorry for that mistake.

Anyway, what's your "solution" got to do with UTF-8?


I forgot to say that my file starts with :
FileEncoding, UTF-8

A good working example will be better than a long explanation :

FileEncoding, UTF-8 
$data := "été"
file1 := fileOpen("uc.tmp", "w")
file1.write($data) 
file1 := fileOpen("uc.tmp", "r")
file1.Encoding := "cp1252"                      
$data2 := file1.ReadLine()
file1.close()
FileDelete, uc.tmp

IniWrite, %$data%, foo.ini, test, test
IniWrite, %$data2%, bar.ini, test, test

Run this and in foo.ini you find :

[test]
test=été

in bar.ini you find :

[test]
test=été




Which was the desired result.

I understand this should be done with StrPut / StrGet, but this was written before i understood that, and I didn't explore StrPut.

dysmas
  • Members
  • 63 posts
  • Last active: Apr 06 2011 11:01 AM
  • Joined: 28 Dec 2010
Some more tests lead to :
1) First I confirm that WriteIniFile works fine in UTF-16

2) If you really really need Utf-8, then here is the code to write :

ConvertUtf8(string)
{
    var := "x"
    ; Ensure capacity.
    len := StrPut(string, "UTF-8")    
    VarSetCapacity( var, len)
    ; convert the string.
    StrPut(string, &var, len, "UTF-8")
    return StrGet(&var, len, "CP1252")        
}


myvar := "étéĂŠŮθЩفשּׂ\Ουκ ελάβον Πολιν\فكّخض"
myUtf8 := ConvertUtf8(myvar)
msgbox % myUtf8
IniWrite, %myUtf8%, foo.ini, test, testB