Simon's Radio Pingback Client: A Small Code Review

So, I'm sitting here doing a database upgrade and while I was waiting for a ton of data to finish replicating I was looking over the implementation of Simon's PingBack Client for Radio and noticed that in his pingbackSuite.checkPost method he has a support function called extractLinks that does a lot of manual string parsing that could very easily be replaced with some Regex calls. Radio has Regex support via system.extensions.regex. In that library there is an extract method. The regex to find the links would be <a .*?href="?([^">\\s]*). Therefore, extractLinks could be rewritten simply like so:

on extractLinks(txtWP)
    local(txt = string(txtWP))
    local(linkMatches = nil)

    \// Extract the matches, specifying the list returned contain only the URL group
    regex.extract("<a .*?href=\"?([^\\">\\\\s]*)", @txt, @linkMatches, { 1 })


Nothin' major, but why write all that annoying parsing logic yourself, ya' know? :)

No Comments