Posts

Showing posts from March, 2010

CodeSnip problems, problems, problems

Arrgh!I've been having a lot of problems with the CodeSnip program's database update code - it's been working for some and not for others. All this has happened since I converted the program to Unicode and compiled with Delphi 2010.I'm posting this for two reasons:To try to explain to long suffering users what has been going on with program lately - it's not usually this flaky.To forewarn anyone about to fall down the same hole as I have.The problem never raised its head on my system, but did on some that don't use the Windows-1252 code page. The problem was caused by a checksum failure, which in turn was caused by the downloaded data being converted to the wrong code page before the checksum got calculated: result - bang - bad checksum.My code relies on Indy components to translate downloaded content into text - and Indy and I make different assumptions about how this should be done. And I'm not sure either of us was correct, but they are a much more exper…

Delphi Tips News

Image
There's now another new RSS feed that provides news of changes to the Delphi Tips section of DelphiDabbler.com.Subscribe.

URL Decoding revisited

Time to complete the set. So far in this series I have presented URIEncode, URIDecode and URIEncodeQueryString. So here's the missing piece of the jigsaw: URIDecodeQueryString. This routine decodes a query string that has been "query-string-encoded".If you look at URL Encoding revisited you'll see that a query string is encoded with normal URI encoding, except that space characters are encoded using '+' characters instead of '%20'.So, to decode a query string we first need to replace literal '+' characters with spaces. Because the string is still URI encoded we should replace ocurrences of '+' with '%20', not the actual space character. Once this is done we are left with a standard URI encoded string which we decode as normal. Here's the code:functionURIDecodeQueryString(constStr:string):string;beginResult:=URIDecode(ReplaceStr(Str,'+','%20'));end; The URIDecode routine was presented in my URL Decoding post.U…

URL Decoding

To complement the code of my URL Encoding post, I've now developed a URIDecode routine.It attempts to decode URIs that were percent-encoded according to RFC 3986. It also allows for some malformed percent-encoded URIs, i.e. those that contain characters outside the RFC's "unreserved" character set.Here's the code. An explanation follows.functionURIDecode(constStr:string):string;// Counts number of '%' characters in a UTF8 stringfunctionCountPercent(constS:UTF8String):Integer;varIdx:Integer;// loops thru all octets of SbeginResult:=0;forIdx:=1toLength(S)doifS[Idx]=cPercentthenInc(Result);end;varSrcUTF8:UTF8String;// input string as UTF-8SrcIdx:Integer;// index into source UTF-8 stringResUTF8:UTF8String;// output string as UTF-8ResIdx:Integer;// index into result UTF-8 stringHex:string;// hex component of % encodingChValue:Integer;// character ordinal value from a % encodingbegin// Convert input string to UTF-8SrcUTF8:=UTF8Encode(Str);// Size the decoded UT…

URL Encoding revisited

In my previous post I covered URI encoding part of a URI or URL. What I didn't cover was the almost trivial case of encoding a query string. The only difference is that spaces in a query string are converted to reserved '+' characters that are not then percent encoded.The only complication arises when the query string to be encoded already contains '+' symbols. They must be percent-encoded so they are not confused with the symbols that are used to replace spaces.In the original version of this post I completely misunderstood this and presented code that percent-encoded both literal and space-replacement '+' symbols.Unfortunately percent-encoding at this stage also encodes spaces as %20. We fix this by simply replacing each occurence of %20 with a '+' symbol. Here's the code: it's a very simple function that encodes a query string value passed as a UTF-8 string parameter:functionURIEncodeQueryString(constS:UTF8String):string;beginResult:=Rep…

CodeSnip Program and Database News

Image
I've set up a new RSS feed that helps users of the Code Snippets Online Database and the CodeSnip Snippets Repository Program keep up to date with changes and updates.Subscribe.