AutoHotkey Community

It is currently May 27th, 2012, 8:25 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: February 5th, 2012, 8:37 am 
When writing a INI file manually, it's troublesome that the file encoding has to be specified to UTF-16.

This demonstrates the problem.
Code:
FileEncoding, UTF-8
IniFile := A_ScriptDir "\test.ini"
FileDelete, % IniFile
FileAppend,
   (Ltrim
      [Section]
      Key=Hi
   )
   , % IniFile
IniRead, OutputVar, % IniFile, Section, Key
msgbox % OutputVar      ;yields Error
IniWrite, Hello, % IniFile, Section, Key
Run, % IniFile
I know it's already been discussed. AHKL: IniRead/IniWrite and UTF8. However, it would be more non-programmer friendly if UTF-8 is natively supported.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 5th, 2012, 9:00 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
As I explained in that thread, the functionality of IniRead and IniWrite is implemented by Windows, not AutoHotkey. UTF-8 support will not be added.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 5th, 2012, 7:12 pm 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3330
Location: Simi Valley, CA
I can see the value of this wish and would like to encourage guest (or another interested party) to write an alternative to GetPrivateProfileString/WritePrivateProfileString that is aware of the file's encoding (and the script's codepage).


As a work around, you may have your script create a temporary copy of your ini file with utf-16 encoding, and use that for iniread/iniwrite until your script is ready to close, then you can convert the entire file back to utf-8 for storage.
Code:
IfNotExist, my.ini.tmp
{
   FileRead, my_ini_blob, *P65001 my.ini
   FileAppend, % my_ini_blob, my.ini.tmp, UTF-16-RAW
}
; the rest of the script uses my.ini.tmp for ini operations
; ... script goes here ...
; when the script is ready to close, do this:
FileRead, my_ini_blob, *P1200 my.ini.tmp
FileDelete, my.ini
FileAppend, % my_ini_blob, my.ini, UTF-8-RAW
FileDelete, my.ini.tmp

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group