From: tvojeho <tv...@us...> - 2011-12-16 18:46:15
|
Only wanted to mention that I managed to solve this issue with [ini4j] library (http://ini4j.sourceforge.net/index.html). tvojeho *[ jEdit-users ] Reading and writing settings in ini-files<http://sourceforge.net/mailarchive/message.php?msg_id=28524885> * From: tvojeho <tvojeho@us...> - 2011-12-11 07:36 *Attachments:* Message as HTML<http://sourceforge.net/mailarchive/attachment.php?list_name=jedit-users&message_id=CAGLFXVg%3DqkNwD%2B08Ag9iaht2mXdXJhA31vSVPMUSxgLax3mp0Q%40mail.gmail.com&counter=1> Hi, I wanted to ask if anybody might have written a beanshell macro or function to be able to read and write settings in inifiles. The jedit properties do not handle the [Section] parts of the inifiles. I have been trying to rewrite some functions written for the autohotkey language but the regexes seem to go over my head. I managed to scramble together one function (ini_get, see below), but it was more trial and error than knowing what I was doing, and I was wondering if someone already has written something similar. Code: ini_get(_Content, _Section, _Key, Flags, Default) { _Section = "\\[\\s*?\\Q"+_Section+"\\E\\s*?]"; //-- Note: The regex of this function was rewritten by Mystiq. RegEx = "(?im)(?:\\n|^)\\s*"+_Section+"\\s*(?:\\n\\s*|\\n\\s*.+\\s*=\\s*.*?\\s*(?=\\n)|\\n\\s*[;#].*?(?=\\n))*\\n(\\s*\\Q"+_Key+"\\E\\s*=(.*))(?=\\n|$)"; //-- Kompilovat regex expression Pattern p = Pattern.compile(RegEx); //-- Vytvořit matcher (boolean) Matcher m = p.matcher(_Content); if(m.find()) { Section = m.group(0); Key = m.group(1); Value = m.group(2); } if(Flags.indexOf('s') != -1) return Section; else if(Flags.indexOf('v') != -1) return Value; else if(Flags == null || Flags == "" || Flags.indexOf('k') != -1) return Key; } Regards, tvojeho |