Today I got into work feeling real good. I spoke about my HTML encode app recently where I used this wonderful new language I’m learning to solve a real life problem. Well I think I’m going to go at it again. This time I’m going to extend the HTML encoder to support decoding. Well let me be more specific, you see I’m just bubbling with excitement at the moment. (That may well be due to the 3 liters of coffee I just poured down my gullet.) I just noticed a frequent problem in my daily duties as a hired Java developer. (That’s not specific, I know but I promise I’m getting to the point.) I have no easy way to pull a string out of Java code back into its normal encoding. Let me elaborate. I use IntelliJ Idea, one of the best Java editors known to mankind (next to of course its close bretheren, Eclipse which is equivalent in functionality). With Idea you can copy text to your operating system clipboard (Ctrl+C on selected text from any application) and paste it into a Java string. What Idea does at this point (does Eclipse support this too?) is format it automatically for you chopping it on line breaks, and putting those little plusy things in the middle of all of the breaks.
I’ll give you an example. Here, I’ll copy a few sentences from below and paste it into Idea as a Java string then show you the results. Eg:
These are a few random sentences.
I’m putting line breaks in so you can see.
A tab character is also formatted for you.
so you can indent text all cool like this.
In Idea I start with:
String whatever = "" and I put my cursor in the double quotes before hitting Ctrl+v. I am then surprised with this:
String whatever = "These are a few random sentences.\n" +
"I'm putting line breaks in so you can see.\n" +
"\tA tab character is also formatted for you.\n" +
"\tso you can indent text all cool like this.";
Well the point is not to discuss Idea features here, (…by the way did you hear about the Ctrl+Shift+Enter feature that auto generates anonymous inner classes?) the point is to get the original string back after it’s been Idea-Java-encoded. I want to be able to copy these Java formatted strings, paste them into my new encoder/decoder I plan to develop, hit the convert button (which will soon be renamed to encode/decode), then have a nromal string value without pluses and quotes and the like. Sounds like a neat idea right? There is a problem. Introducing decoding functionality to my htmlEncoder is a complicated process. The original program is simple enough and I want to keep it simple. However, to decode an HTML string into a formatted representation presents some challenges. How far does one go? I could do a half job and just undo the escaping of whitespace and other miscellaneous entities and that would suffice for my general use but it wouldn’t be accurate. Speaking of general use, I have such general use as of yet for an HTML decoder! So what am I yammering about? It sounds like feature creep to me. While my original idea is pertinent I may jump off and implement it as I have time. Keep your eyes peeled for what I do next. By the way, if any of you Groovy experts want to jump in and beat me to the punch here feel free to post your hard work so I can claim it as mine! 😉 Thank ya’ and I’ll holla at’cha…
(Note: “holla at’cha”, slang for holler at you is considered as an informal method of greeting a person in certain urban communities. It relates in no way to the act of expressing ones anger, neither does it constitute abrasive or offensive behaviour.)