[module] Ini 1.0b2 - ini-like handling of strings
Set of functions for ini-like string handling
Download/View Documentation
History
1.0 b2
- Added MakeSection function
1.0 b1
- Interface upgraded with many new functions. Existing API changed.
- Optimisation
0.1
Initial release
http://www.autohotke...ghlight=loadini
Ive added a few extra functions for my own use too.
mine was originally written for an addition to a template designed to help newcomers.
The idea being just by adding three function calls they can load and save any variables at will.
I agree they are simple enough to use, and for large data sets this isnt the way to go, but for medium size and small size it will cut the need for writting all the reads and writes.
I guess it was also brewed out of lazyness lol
Or did i completely mis interprete what you mean and was you suggesting stringsplit would be a better way to go ??
Thanks for sharing!
Its fast enough for 99% of usagees and the code is elegant. You don't need to be concerned about ultimate speed everywhere. The functionality is more important here.Ini files are so simple you should be able to parse them without regex
I intenionately avoided String functions cuz I don't see much benefit over RegEx in normal Ini files. I care about code sophistication more and leave optimisation for time critical things. IMO, its wrong to optimise everything.
Also if you cheked out the carefuly you would see that the most frequent task is done without single RegEx.
Its also faster then multiple IniReads. Low number of RegExes are used.
Again, to quote Laszlo, how far you want to go in optimisation ?
Ultimately I can provide machine code, but that is hardly the point.
This is basicly configuration automation. So you can load your entire configuration in global vars in one step instead of series of IniReads.
Its probably not suitable for special cases but again, nothing is.
Anyway the only reason I posted is because I'll be using these functions. I will modify them to suit my needs since like Skan, you prefer compact code over anything else. Thanks.
autohotkey.com/net Site Manager
Contact me by email (polyethene at autohotkey.net) or message tidbit
I had quolity laugh now
And if we talk about cryptic lets talk about Anchor
Anyway, you can argue that RegEx is cryptic, but the one there is fairly trivial, can be decifered by ppl knowing RegEx in several minutes, and basicly that is the only thing to care about in this code.
Since like Skan, you prefer compact code over anything else.My coding is nothing like Skans. I don't practice obfuscation and I know very well that "code size" has nothing to do with speed. Skan got it all wrong when short code philosophy is in question. Nevertheless, I prefer recursion instead itereation because of its ultimate elegance. I don't know if you ever programmed in Prolog, but there even the very complex tasks can be coded in 3 lines. Not obfuscation if you know rules of the language, as much as RegEx crytpic patterns are not obfuscation once you did your lessons.
RegEx... I just love that thing. It makes me happy.
I am not sure how AHK lived up so long without it, I find it ridiculous that lanugage having primarly strings as types doesn't have the most sophisticated way to handle them.
Not if I have to use 5 instead of 1 RE. 1 against 1, you are rightString functions are more elegant
Nice to hear that. I can't wait to see your update. After all, if somebody else is willing to update anything I did, especialy you, I am happy. Due to your speed concern I checked the speed of the functions, and even with very large ini files (I tested on wincmd.ini, hardly any AHK script will have that much options) to get values from 0 - 10 ms. OFC, I can imediately spot problematic places, like StringTrimLeft in 2Var when all sections are iterated.Anyway the only reason I posted is because I'll be using these functions
Then we come to idea that I force: Do I really want to spead up something that takes 10ms in worst case ? Do I really want to do that without debuger, without appropriate IDE and stuff like that. Do I really want to lose enormous amount of time to get small benefits, as currently, in AHK, i miss like 1000 libraries and I am slowely writting them as I need them. Imagine I optimise like crazy.... that would be horror.
On the other hand if somebody entusiastic enogh, like you, with your fanatic optimisation skills (not sarcastic, I learned alot from your and Laszlos optimisation skills), I can be only happy. I am more concerned currently about API that is extremely practical and easy to use in most cases.
Then if you do update them, please add the folowuing I missed - list of sections. If this is to be used with 3th party INIs keep in mind that some of the section names may not be valid variables (contain spaces, dots and sht like that).
Also, I am not sure if reverse opeerations shold be done (vars to sections) for ultimate config handling. Superfraggle did it as saveini but that way is not possible here, because first, you don't know what globals should be saved. I imagine you give a prefix of globals, and section, and it does the job, but that is not possible as you can't find out the full name of the variable. If listvars exists in some more advanced forms, that could be used... for instance listvars cfg_* but Chris doesn't wont to cooperate here so its just dreaming. Arrays will probably do good here, but again, when ?
Thx
Commenting that is somewhere on my informal todo list.if we talk about cryptic lets talk about Anchor
Actually in most cases they are, e.g. (?<=(["']))[^\1]*(?=\1\ is an optimized version of "(.*?)".RegEx crytpic patterns are not obfuscation
They're too specific for my usage now but I might post them later.I can't wait to see your update.
Well I think if you can, why not? It could just be my perfectionist nature but I don't feel comfortable releasing scripts whilst knowing they can be much improved. I'm sure Chris and other developers feel the same way.Do I really want to spead up something that takes 10ms in worst case ?
autohotkey.com/net Site Manager
Contact me by email (polyethene at autohotkey.net) or message tidbit
And updating Ini module is on my Todo list.Commenting that is somewhere on my informal todo list.
True. Optimisaion of REs is anoying even to me, the biggest fan.Actually in most cases they are, e.g. (?<=(["']))[^\1]*(?=\1\ is an optimized version of "(.*?)".
Because, it always can and you have to stop somewhere. I am sure Anchor can be lot faster and without some suspicious/problematic functions like InvalidateRect. But hey, it does the job (in 99% of cases), nobody complains.Well I think if you can, why not?
If I wanted to use uber fast code I would programm in ASM, not in AHK.
The life, the universe and everything else requires delicate measure of balanse. I am constantly updating my own. I find fairly biased for you to comment like this, knowing that your main prog environment is C# & dotNet the king of low speed. If you really want to talk to me about how things should be done, switch to ASM instead of dotNet. After all, you can't go lower then ASM... or ....It could just be my perfectionist nature but I don't feel comfortable releasing scripts whilst knowing they can be much improved.
The truth is bitter - higher level of abstraction makes code slower, yet not enough abstraction makes code fast and hard to use. Balance again.
Well, then I don't agree with you, Chris & other developers. But who cares? We definitely don't have same priorities in life. Something like dolphins and humans.I'm sure Chris and other developers feel the same way.
I see.They're too specific for my usage now but I might post them later.
It's up to the author to exercise reasonable discretion. Mine goes as far to suggest using simple string functions over cryptic overzealous regex for something as basic as INI. I never ordered you to do anything or stated anywhere that optimization was an absolute necessity. If I had that mindset I most probably would program in ASM.it always can and you have to stop somewhere
That's another common misconception. I don't use reflection and much polymorphism and inheritance so my C# apps are quite fast once compiled to CLR.I find fairly biased for you to comment like this, knowing that your main prog environment is C# & dotNet the king of low speed
For an extra five or so minutes of work I would push for quality. If I was ignorant and had low substandards I could make-do with anything, so its a question of personality I suppose.I don't agree with you, Chris & other developers. But who cares?
autohotkey.com/net Site Manager
Contact me by email (polyethene at autohotkey.net) or message tidbit
Its not common misconecption. Its a fact. I love dotNet but I know my beast. That tech will shine in few years.That's another common misconception.
Ye, its proven that C# can be as fast (and even faster) as C++ app, but only if you are programming guru and have no life other then optimising things (something like WoW episode of South Park). Even Rusinovich stated that he is scared about dotNet. So if even one of the biggest Windows gurus out there is "commonly missconcepted" what makes you think you are the one that is not ? Other then that, you don't have to measure programs running in dotNet VM. I can noticed their slow speed and large memory footprint as soon as I start them.
So you don't use framework at all ?I don't use reflection and much polymorphism and inheritance so my C# apps are quite fast once compiled to CLR.
Perhaps its 5 minutes for you. I don't beleive anything in this world is possible in 5 minutes.For an extra five or so minutes of work I would push for quality.
I think AHK REs are very fast based on personal experience and some measures.Mine goes as far to suggest using simple string functions over cryptic overzealous regex for something as basic as INI
You've just contradicted yourself.its proven that C# can be as fast (and even faster) as C++ app
I'm no .NET optimization expert (those who are often get paid a lot for it) but there are truths in both of our statements. AutoHotkey is a different story, here optimization techniques are pretty much common sense to anybody with prior programming experience, and there is nothing much that needs to be studied and learned; i.e. use commands over functions, avoid dynamic variables and expressions for simple assignments, parsing loop instead of StringSplit etc....only if you are programming guru and have no life other then optimising things
I believe anything is possible. Perhaps this reflects our contrasting philosophies on many of the issues that's been discussed.I don't beleive anything in this world is possible in 5 minutes.
Orly? From my experience and benchmarks I found that string commands outperform regex in almost any case.I think AHK REs are very fast based on personal experience and some measures.
autohotkey.com/net Site Manager
Contact me by email (polyethene at autohotkey.net) or message tidbit
/* Function: Ini_GetVars Loads variables from an INI file. Parameters: src - INI file path sec - filter variables by sections with this name pre - common variable name prefix d - separator for section name and prefix Returns: Number of variables loaded. About: Examples - Ini_GetVars("settings.ini") ; load all variables indiscriminately - Ini_GetVars("application.ini", "window") ; load variables under 'window' section - Ini_GetVars("test.ini", "", "") ; use no prefix About: License - GNU General Public License 3.0 or higher <http://www.gnu.org/licenses/gpl-3.0.txt> */ Ini_GetVars(src, sec = "", pre = "", d = "_") { local s, p, v1, v2, t, at static x = " , ,``,¬,¦,!,"",£,%,^,&,*,(,),-,=,+,{,},;,:,',~,,,<,.,>,/,\,|,,," at = %A_AutoTrim% AutoTrim, On If pre != pre .= d Loop, Read, %src% { If InStr(A_LoopReadLine, "[") = 1 { StringMid, s, A_LoopReadLine, 2, InStr(A_LoopReadLine, "]") - 2 If s contains %x% s = Else If s != s .= d } Else If !(sec != "" and sec != s) and p := InStr(A_LoopReadLine, "=") { StringLeft, v1, A_LoopReadLine, p - 1 v1 = %v1% If v1 contains %x% Continue StringTrimLeft, v2, A_LoopReadLine, p %pre%%s%%v1% = %v2% t++ } } AutoTrim, %at% Return, t }
I'll wait on you for the reverse functions lol.
autohotkey.com/net Site Manager
Contact me by email (polyethene at autohotkey.net) or message tidbit