URLizer in c++
Posted by Kelvin on 30 Sep 2004 at 05:03 pm | Tagged as: programming
I recently converted my URLizer WordPress plugin to C++.
Initially, I used the Boost.regex package available at http://www.boost.org/libs/regex/doc/index.html. I required the latest release because it had support for text replacement. Then, I found it didn't support lookbehind, only lookahead. Argh. Ugly and inefficient as it was, I worked around it with a 3-pass approach:
- Replace the lookbehind pattern with some arbitary string like '@@@'.
- Match/replace what you need to match.
- Restore the replaced lookbehind pattern.
Yes, I know it sucks. But it is relatively simple to write. Anyway, there is another way which requires much more work but less replacements, but this margin is too thin to contain it. 🙂
I am checking out http://www.pcre.org as an alternative. Supports lookbehind, but not replacing. *sigh* There's another package called PCRS which is an add-on for substitutions, but I can't get it compiling on my VS6 environment yet. The biggest plus of PCRE is that it isn't written in fancy C++ in all its glory (templates, traits, etc), which means PCRE probably ports pretty well.
Comments Off on URLizer in c++