(Originally posted here)
A big problem I have had will all other Ini libraries (including the old version of EasyIni) is that their syntax is too cumbersome. The point of this library is to make it as easy as possible to R/W inis; furthermore, I wanted to make the class itself easy to read and accessible to other developers. EasyIni is currently 389 LOC.
An unexpected positive consequence of this class is that it performs exponentially faster than IniWrite operations. I posted an example below where class_EasyIni is 1162% faster than IniWrite.
My design approach was, "How can I make this as easy as possible?" The result is, you can interface with ini's using class_EasyIni objects with great ease. Thanks to custom objects, this class allows you to use the familiar, native, Object syntax.
Code: Select all
; To create an ini object, vIni := class_EasyIni("MyIni.ini") ; To interface with the object, for section, aKeysAndVals in vIni for key, val in aKeysInVals vIni[Section][key] := 1 vIni[VariableWithSectionName][VariableWithKeyName] := val ; this is typically used when you are looping through sections and keys vIni.NameOfSection.NameOfKey := val ; This syntax is the easiest, but you must know the literal section name and key name to do this. ; It is particularly useful for handling user-defined ini variables in your applications with relative ease. vIni.NameOfSection[VariableWithKeyName] := val ; This is when you know the literal section name vIni[VariableWithSectionName].key := val ; This is when you know the literal key name
Character limitations are mostly obvious:
- You cannot use newlines in section names.
- For any alphanumeric section, (i.e. "[A]") only one case is allowed. So if you tried to add section "[a]" AddSection() would fail. This is demonstrated in my 1500 sections example below.
- During my tests, I noticed that SOH (chr(1)) and A_Space (chr(32)) were written to the same section [SOH]. I am not sure why this is the case, but I don't imagine this will be a problem for most people, if any.
- I also noticed that quite a few odd character values were getting grouped together into the same sections. Whether this is a problem for anyone is doubtful, but I suspect it is possible for those who store BBCode in inis to have problems. Regardless, this class is just a fancy custom object. If there are certain problems with section names, this is likely a problem with AHK itself and not the class.
- You cannot have a section or key that starts with the text, EasyIni_ReservedFor_. I can't imagine this being a big problem.
"=" are not supported in keynames.
- Do whatever you want with values
- Keys without values are supported
- Although it is not recommended if you plan on using your inis with other applications that access the same ini, "]" in section names are supported.
- EasyIni stores ini data in a custom object. Much credit for this custom object goes to Lexikos and Rbrtryn for their work with ordered arrays. For more information, see OrderedArray. Thanks to the pre-existing work with OrderedArrays, I was able to create an object that, without much trouble, enabled me to maintain the format of the ini file. If any comment or newline is removed from your file, or if any sections or keys are re-ordered in your file as a result of using class_EasyIni, then this is a bug and you should report it to me!
Below is a test where I add every possible character value (returned from chr()) to an ini. Writing to memory took < 1 second. Writing to a file took 17seconds (3629% faster than the old class).
Creating an ini, adding and modifying sections, keys, and values, and saving.