Today I went back to working on the blogging app because it obviously needs to be in good enough shape to actually write about it for the book. I got to the part I've been putting off for a long time, namely parsing comments. You know, you have to parse out naughty HTML and things you don't bad people inserting into your page.
That means regular expressions, the quasi-language that has been around for decades for the purpose of manipulating text. I hate it. I mean really, really despise it. For some reason, it's something that has never clicked in my head.
I finally found the matching pattern for what I wanted to pull out and manipulate, only to have it not work in code. After much banging my head and posting a question to StackOverflow, I realized that I wasn't escaping the string or designating it as a string literal. In other words, in C#, you precede the string with an @ to say, "Hey, those back slashes are really supposed to be backslashes, not things escaping other characters." I felt like an ass. It's one of those things I don't use enough to remember how to do it right.
But whatever, I got it done. The biggest surprise, after several hours of work, is that I actually ended up unintentionally rewriting a portion of the forum code that has pissed me off literally for a decade now. It's one-third as long, easier to read, and undoubtedly performs better. At some point I'll have to roll it backward into the forum. (For the nerds, it was code to make sure that HTML tags were properly nested and closed.)
The time is late, the book isn't any more written than it was Friday, but I feel generally accomplished.
No comments yet.