AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Lib] ini v0.15.1 - Basic ini string functions
Goto page Previous  1, 2, 3, 4, 5
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
alpinestars



Joined: 20 Oct 2009
Posts: 5

PostPosted: Mon Nov 30, 2009 9:13 pm    Post subject: Reply with quote

Tuncay wrote:
BUMP Razz its alive

new functions are following


Sounds excellent!
Back to top
View user's profile Send private message
alpinestars



Joined: 20 Oct 2009
Posts: 5

PostPosted: Wed Dec 16, 2009 9:21 am    Post subject: Reply with quote

Hi,

I get an error if strings are containing a "\".

my ini

Code:
[paths]
Folder\Edit\Test1=0
Test2=0


Code:
ini_getValue(ini, "paths", "Folder\Edit\Test1") returns ""
ini_getValue(ini, "paths", "Test2") returns "0"


Can you please implement the ability to use "\"?

Thx,
alpinestars
Back to top
View user's profile Send private message
Tuncay



Joined: 07 Nov 2006
Posts: 890
Location: Berlin, DE

PostPosted: Wed Dec 16, 2009 2:44 pm    Post subject: Reply with quote

From the Documentation about ini library:
Quote:
For best compatibility, the names of section and key should consist of alpha (a-z), num (0-9) and the underscore only. In general, the names are case insensitiv.


I am not sure if this change would be happen. The problem is the "\E"-part inside the string. The ini_getValue() function works with regular expression and the "\E"-string in "Folder\Edit\Test1" ends the literal string and turns regular expression on again.

From AutoHotkeys Documentation about Regular Expression:
Quote:
Escaping can be avoided by using \Q...\E. For example: \QLiteral Text\E.


I did not made a catch to this, because normally a key name does not have a backslash. If I would make a simple addition to check in function, something similiar to this:
Code:
IfInString, _Key, \
{
    StringReplace, _Key, _Key, \E, \E\Q
}

Then this could work work with your example (normally it should work with backslashes, but the character sequence "\E" is an exeption). But this would be really rarely needed and would slow down the whole function. I will experiment a bit, but dont know if this would be implemented in final release.

Another solution would be to write keynames in lowercase only (or just "Folder\edit\Test1" instead of "Folder\Edit\Test1").

I suggest for this time to make a self check and correction of this for key names containing a backslash. Here is an example:

Code:
key := "paths", "Folder\Edit\Test1"
ini_getValue(ini, "paths", lowerE(key))

lowerE(_Key)
{
    Return (InStr(_Key, "\") ? RegExReplace(_Key, "\\E", "\e") : _Key)
}


Hope this helps. Its not tested, but you should get the idea what I mean.
_________________
Download Ahk Standard Library Collection - An archive with stdlib compatible function libraries
Back to top
View user's profile Send private message
Tuncay



Joined: 07 Nov 2006
Posts: 890
Location: Berlin, DE

PostPosted: Fri Jan 15, 2010 1:40 am    Post subject: Update Reply with quote

Updated to version 0.14.

Last changes
  • CHANGE: License changed from GPL to LGPL, to allow the usage in non GPLed code.
  • DOC: Some discrepancies at the documentation corrected.
  • DOC: The documentation is created with the custom installer of NaturalDoc from majkinetor. It`s a small one html file only now.
  • CHANGE/NEW: ini_insertValue() and ini_replaceValue() have the third parameter and default handling of deleting surrounding spaces and quotes of values. This could break some scripts using these functions with quotes or spaces around the value.
  • NEW: ini_load() and ini_save() added for comfort reason. Note: They are not needed to work with the library.
  • NEW: ini_getAllValues() to get all values in one go, into new line separated list.
  • BUG: Now ini_insertKey() works as a workaround with different other function calls from library, instead of one call. I did not found one regex call to handle that correctly. This function is slower than the other functions in this library, but it should work correctly now.
  • BUG: ini_getSection() and ini_replaceSection did not get all sections without any key.
  • LIMITATION: ini_getSection() and ini_insertKey() are not working with the default Section or Key Name (by specifieng an empty string "") anymore.

_________________
Download Ahk Standard Library Collection - An archive with stdlib compatible function libraries
Back to top
View user's profile Send private message
Tuncay



Joined: 07 Nov 2006
Posts: 890
Location: Berlin, DE

PostPosted: Fri Jan 15, 2010 11:47 pm    Post subject: Update Reply with quote

Updated to version 0.15.

Last changes
  • DOC: Added missing documentation about ini_exportToGlobals().
  • NEW: Added a new parameter SectionSpaces at ini_exportToGlobals(). This may brake any script using this function. Now, it deletes at default spaces in section names.

_________________
Download Ahk Standard Library Collection - An archive with stdlib compatible function libraries
Back to top
View user's profile Send private message
Tuncay



Joined: 07 Nov 2006
Posts: 890
Location: Berlin, DE

PostPosted: Fri Feb 05, 2010 8:37 pm    Post subject: Update Reply with quote

Updated to version 0.15.1.

Last changes
  • CHANGE: Status changed from Beta to Stable.
  • BUG: Function ini_getAllValues() updated, because it returned emtpy lines between all entries.


Its a small update.
_________________
Download Ahk Standard Library Collection - An archive with stdlib compatible function libraries
Back to top
View user's profile Send private message
Morpheus



Joined: 31 Jul 2008
Posts: 98

PostPosted: Thu Feb 11, 2010 11:34 pm    Post subject: Reply with quote

The ini file that I have has comments in such as this:
# This is a comment

I added this to your script to deal with it:
KeyNames := (RegExReplace(KeyNames, "#.+?," , ""))

However, It might be a nice feature to be able to pass as a parameter a character that would mark the begining of a comment, and to not return those as sections/keys.

Other than that, thanks for the Functions. Smile
Back to top
View user's profile Send private message
Tuncay



Joined: 07 Nov 2006
Posts: 890
Location: Berlin, DE

PostPosted: Fri Feb 12, 2010 11:25 am    Post subject: Reply with quote

thanks

Currently I will not work on the source, because my main computer is down. And there are some extra files at the source which arent included in uploaded library.

Anyway, not all of the functions work correctly or the same with comments. The main intention is to get data without comments with less lines as possible. In example all functions are tried to be one regex call if possible. If you do any modification, I would like to see them. If there are any comments in script, I generally recommend to call ini_repair() first. This removes also unneded lines and spaces and makes other calls faster.

But yes, you are right. There is some work left. I will change the lines in the next weeks someday, if my computer works again.
_________________
Download Ahk Standard Library Collection - An archive with stdlib compatible function libraries
Back to top
View user's profile Send private message
Morpheus



Joined: 31 Jul 2008
Posts: 98

PostPosted: Fri Feb 12, 2010 12:40 pm    Post subject: Reply with quote

Tuncay wrote:
But yes, you are right. There is some work left. I will change the lines in the next weeks someday, if my computer works again.


No, I was wrong. Ini_Repair works perfectly! Ijust didn't read everything.

BTW: I am using Vista, and your test program reports no errors.

Thanks again. Very Happy
Back to top
View user's profile Send private message
Tuncay n-l-i mobile
Guest





PostPosted: Fri Feb 12, 2010 7:05 pm    Post subject: Reply with quote

good to hear it is working and thanks about the confirmation.
Back to top
Tuncay



Joined: 07 Nov 2006
Posts: 890
Location: Berlin, DE

PostPosted: Mon Feb 15, 2010 1:34 am    Post subject: Known BUG Reply with quote

BUG: The ini_save() routine seems to not work correctly. I dont know why, but there is a solution. Currently I cannot update the source, so sorry for that. Here is the problem and the workaround described:

Tuncay wrote:
Ok I have found the problematic part. I dont know why, but the save routine does not translate the "`n" into "`r`n", but at default it should. Before saving the file, you can replace each `r`n with `n and then all `n to `r`n. Then it should work definetely. sorry for that, i cant update the source now. tomorrow, i try to change it so it works.

or use fileappend, instead of ini_save(). but dont forget to delete prior append the file. I have checked the file, and there is a mixture of the two styles. again sorry for that

The library uses this function

Code:
ini_save(ByRef _Content, _Path = "", _convertNewLine = true, _overwrite = true)
{
    ini_buildPath(_Path)
    error := false
    If (_overwrite)
    {
        Loop, %_Path%, 0, 0
        {
            _Path := A_LoopFileLongPath
            Break
        }   
        If FileExist(_Path)
        {
            FileDelete, %_Path%
            If (ErrorLevel)
            {
                error := true
            }
        }
    }
    Else If FileExist(_Path)
    {
        error := true
    }
    If (error = false)
    {
        If (_convertNewLine)
        {
            FileAppend, %_Content%, %_Path%
        }
        Else
        {
            FileAppend, %_Content%, *%_Path%
        }
        If (ErrorLevel)
        {
            error := true
        }
    }
    ErrorLevel := error
    Return _Path
}

Ini key on new line
_________________
Download Ahk Standard Library Collection - An archive with stdlib compatible function libraries
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4, 5
Page 5 of 5

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group