Something smarter than string.format for user-defined patterns?
-
In my Virtual HTTP plugin I have patterns that could be specified to dynamically compose HTTP URLs based on current values. So, if you enter
http://myip/color?v=%s
it gets replaced with the current color. It's very handy when having more parameters, or if your parameter is in a different position.
The problem is that from time to time, there are users with legitimate
%
in their URLs (since it's the escape char in URLs, after all) and this is causing weird behavior or crash.So, I want to find something smarter to support both.
Any hints here is appreciated. -
In my Virtual HTTP plugin I have patterns that could be specified to dynamically compose HTTP URLs based on current values. So, if you enter
http://myip/color?v=%s
it gets replaced with the current color. It's very handy when having more parameters, or if your parameter is in a different position.
The problem is that from time to time, there are users with legitimate
%
in their URLs (since it's the escape char in URLs, after all) and this is causing weird behavior or crash.So, I want to find something smarter to support both.
Any hints here is appreciated.From here:
It says:
"The solution is to either use multiple patterns and write some custom logic, use a regular expression library like lrexlib or Lua PCRE, or use LPeg [3]. LPeg is a powerful text parsing library for Lua based on Parsing Expression Grammar [4]. It offers functions to create and combine patterns in Lua code, and also a language somewhat like Lua patterns or regular expressions to conveniently create small parsers."
Also, haven't looked deeper, but I found this: