KBD

Keith Devens .com

Tuesday, December 2, 2008 Flag waving
The three chief virtues of a programmer are: Laziness, Impatience and Hubris. – Larry Wall (Programming Perl)

Archive: November 27, 2004

← November 26, 2004November 28, 2004 →

Daily link icon Saturday, November 27, 2004

  1. The Guy Who Invented Arrays - The Daily WTF:

    I ended up replacing TWELVE THOUSAND lines of his code with just two hundred.

    Man, that's how I felt with the code I'm working on, though it wasn't nearly that bad.

       (0) Tags: [Programming]
  2. The Comment API. I didn't know this existed until I saw a screenshot of RSS Bandit showing the ability to post a comment from within the reader and went looking for the spec.

       (0) Tags: [Programming]
  3. Ken Jennings' final episode (kottke.org). Gotta remember to watch.

       (0)
  4. Perl to Php Translation. I want to write one of these for every major language I use.

       (0) Tags: [Programming]
  5. THE ZOOMQUILT | a collaborative art project. Whoa.

       (0) Tags: [Random]
  6. Donald Sensing: Alexander - a very brief review. Heh, that's pretty bad.

       (0)

The X-Philes

The X-Philes, a list of XHTML valid sites. Via Jacques, via Sam. I'm going to ask to be added to the list.

My site isn't bulletproof because I don't strip control characters (which I should). I also deliver MIME types other than application/xhtml+xml to user agents that don't include it in their ACCEPT header, but I think that's a completely reasonable approach.

  1. Letter from Fallujah, via LGF. The more I read the more I'm convinced that it may have been a good thing we waited to take Fallujah.

       (0) Tags: [Opinions/Politics]
  2. Babalu Blog: Burlington Che Factory, via.

       (0) Tags: [Opinions/Politics]

Cross-platform arbitrary string handling?

I need to write a cross-platform C library that can handle strings in a way that makes everyone happy, from a Unix programmer who likes to deal with UTF-8 encoded char* strings to a COM programmer who needs to use BSTRs (or any of the other multitude of string types Windows has).

Essentially, the library needs to parse a data file format with string values that are UTF-8 encoded and can contain null bytes. This is library code, so I need to consume the file and pass the caller a data structure with strings he can use.

How do I make everybody happy? I could pull a BSTR[1] (except with chars instead of wchars), or I could just make every string value a struct with a length and a char*. Either way, Windows people could create a BSTR from it assuming there's some Windows routine to convert UTF-8 to UTF-16 that doesn't expect null-terminated strings. And I assume "normal" C programmers would be happy enough with a char* pointing to a bunch of bytes containing a UTF-8 encoded string that they can do whatever they want with.

Anyway, what's the best way to handle this that will make the most people happy? What would you recommend I do if I was using C++ instead?


Also, I have a separate question. I've been wondering this for a while: if you create something like a BSTR where your pointer points not to the beginning of the memory you allocated but at some index in, what will free do if you don't pass it the location at the start of that allocation? I assume it's not smart enough to know that your pointer is in the middle of block X and then free that, right? Smiley


Footnotes:
[1]: For those who don't know, BSTR is a pointer to something like struct{word_t size, wchar_t[length] chars}, where chars is null-terminated (note, two bytes of 0's because wchar_t) and the BSTR is actually a pointer to struct.chars (so you index one word back to get the length, and can treat the BSTR as a normal wchar_t null-terminated string if your string doesn't have null bytes in it

  1. Eric's Complete Guide To BSTR Semantics. Excellent.

    The Code Project's "The Complete Guide to C++ Strings", Part I - Win32 Character Encodings, and Part II - String Wrapper Classes seem to be excellent as well.

       (0) Tags: [Programming]
  2. Judy Arrays Web Page. I'm thinking of using Judy for a project. I just noticed they've updated their web site and they just released version 1.0 this September.

    Update: My goodness! Look how easy it is to do hash tables with Judy!

       (3) Tags: [Programming]
  3. LtU links to Denotational Semantics: A Methodology for Language Development, a book by David Schmidt. I've wanted to know what denotational semantics are for the longest time. So far, this book seems very readable.

       (0) Tags: [Programming]
  4. William Kristol: Regime Change at the CIA:

    Porter Goss was confirmed as director of central intelligence on September 22, 2004. That day, acting CIA director John McLaughlin said, "I know I speak for my colleagues at CIA and throughout the intelligence community in congratulating Porter Goss on his confirmation by the Senate as director of central intelligence."

    It was a gracious statement from a man who had wanted the job. But in terms of accuracy it should go down as the latest in a long line of bogus CIA assessments. McLaughlin was not speaking on behalf of many of his colleagues at the CIA when he congratulated Goss on his confirmation.

    As chairman of the House Select Committee on Intelligence for seven years, Goss had been highly critical of the agency, particularly its clandestine services. He arrived at Langley with reform of the stubborn CIA bureaucracy on his mind.

    Via Jayson at PoliPundit.

       (0) Tags: [Opinions/Politics]
  5. Oliver Tseng: It's a boy! Congrats!!

       (0)
  6. How to Fold a Shirt (.net). A whole domain devoted to that video showing how to easily fold a shirt. Via Adam.

       (0) Tags: [Random]
← November 26, 2004November 28, 2004 →
December 2008
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
28293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 6 posts

Recent comments XML

new⇒Perl 6 1.0 in March?

Doh, my mistake. I'm aware of the​relation between Parrot and Rakudo​but I'...

Keith: Dec 2, 1:03am

Free image hosting sites

Well, TinyPic has this in its​FAQ:

> Images and videos is in​your accoun...

Keith: Dec 1, 1:13am

Join a NameValueCollection into a querystring in C#

Well with a lamba expression, this​is what I came up​with:

?!code:csharp...

Gustaf Lindqvist: Nov 30, 4:38pm

Why no generic OrderedDictionary?

Check​http://www.codeproject.com/KB/recip​es/GenericOrderedDictionary.aspx?d...

Gabrielk: Nov 27, 6:57am

WhatIsMyIP.com

http://www.thesysteminfo.com is​another good alternate to​whatismp.com... I...

Kripz: Nov 26, 8:51pm

Girls, please don't get breast implants

Actually I think it's sweet when a​man loves a woman whether she's big​or n...

218.186.12.228: Nov 26, 9:40am

Generated in about 0.069s.

(Used 7 db queries)

mobile phone