Kevin Nelson Marshall
Other entries:
« Crush'in it big time.

So tonight's five minute challenge involved dealing with mixed case.

You see like most projects, as I work through improvements and additions to the fubnub idea, I also discover new issues and problems here and there. Tonight I finally got around to thinking about the fact that the templates are going to be input by...wait for it...users. Yuck.

As a developer, I continue to have this love/hate relationship with users. I love them because, well, they take what I build and actually use it (hence the name user)...but I also hate them because they have the gall to have no idea how to use what I built in just the specific way I envision it. The gall I say, the gall!

Anyway, long story short, the burden to make things 'just work' falls to me as the developer.

So getting back to the fact that templates are going to be entered by users, I realized that users might (and probably will) enter template details in all sorts of strange ways...though it would be great, I can't just assume that they'll magically enter the fields to their feeds in the same way that their feeds actually provide them.

For example, the RSS feed for this very blog (which by the way you can subscribe to right here) has a 'link' tag...now in the RSS the tag is in lower case...but in a user input template, it might be something like [' Link '] or [' LINK '] or [' LiNk '] or whatever (you get the point).

And I need to properly tie these things together regardless of how they are input (ie. I need to do what the user means, even if it's not what they actually say).

Luckily this is not a huge problem. First of all, I'm already building out a list of the fields in a template (which I use to do the actual data injection with). So all that I really had to do was loop through the list of fields, and do a replacement that up-cases all the fields. Here's the simple Perl that I'm using right now:

foreach (@$fields) {
  $field = $_;
  $template_data =~ s/(['s+)$field(s+'])/$1$field$2/gi;
}



Now if you're a salty and savvy developer, you may be thinking that technically that's not all there was to it - and you'd be right. The above code correctly upper cases fields in my user input templates, but that still doesn't mean we'll always match our feeds.

Remember in my example, my RSS feed has a link tag (a lower case 'link') and since we've just upper cased our fields we've actually made sure that we'll NEVER have a match. Yikes.

But never fear, we can fix that problem right quick as well.

We just need to make sure that we convert all tags from feeds to upper case...and since I'm also already grabbing the list of tags from our feeds (which is also used to deal with the data injection bit), it's another simple case of up-casing the values in my array (this time with the Perl uc function).

So in the end, it was a simple solution to a sticky situation. Those crazy users can feel free to get wild with case variations in templates, and things will 'just work' (well at least that part of things).

posted by Kevin Marshall on 2008-05-13 00:00:00+00


Subscribe to my RSS feed »

BotFu feed with RSS reader

BotFu feed by Email


Search All Posts »


Kevin Marshall - Who's That?

I'm just your basic programmer. I can't spell to save my life, I'm not the greatest story teller, and I often ramble on about nothing. This blog showcases all of that!

If you're bored drop me an email at info at falicon.com or view my outdated resume.


Stalk Kevin on »

bit.ly
Delicious
Digg
Disqus
Facebook
Flickr
FriendFeed
Github
Last.fm
LinkedIn
StumbleUpon
Twitter (@falicon)

Archives by Category »

(28) Code »
(8) ColdFusion »
(15) Database »
(10) Factor »
(3) Falcons »
(321) General »
(13) JavaScript »
(18) Perl »
(17) PHP »
(20) Ruby »

Archives by Month »

(1) September 2010 »
(2) August 2010 »
(3) July 2010 »
(13) June 2010 »
(8) May 2010 »
(2) April 2010 »
(2) March 2010 »
(5) January 2010 »
(2) October 2009 »
(6) August 2009 »
(11) July 2009 »
(2) May 2009 »
(3) April 2009 »
(2) March 2009 »
(7) February 2009 »
(9) January 2009 »
(14) December 2008 »
(5) November 2008 »
(12) October 2008 »
(13) September 2008 »
(16) August 2008 »
(23) July 2008 »
(20) June 2008 »
(24) May 2008 »
(23) April 2008 »
(27) March 2008 »
(28) February 2008 »
(26) January 2008 »
(7) December 2007 »

Published Works »

Beginning Amazon's SimpleDB (Apress in dev.)
Pro Active Record (Apress 2007)
Web Services with Rails (O'Reilly 2006).

Contributed To »

Ruby Cookbook (O'Reilly 2006)
SQL Cookbook (O'Reilly 2005)
Various Reviews published in Computing Reviews

Free Code I've Created »

SimpleDB library in Python 3.0



This blog is powered by KickAssCode.