Thursday, November 27, 2008

gcc poison pragma

Useful when you want to get rid of C calls that should not be used because they are unsafe, like strcpy or sprintf: GCC's pre-processor allows you to mark a function as poisonous, causing calls to it to become a compile time error:



#include <string.h>
#include <stdio.h>

#pragma GCC poison strcpy

int main()
{
char t[5];
strcpy(t, "A");
printf("Hello World\n");
}





cristi:~ diciu$ gcc strcpy.c
strcpy.c:10:2: error: attempt to use poisoned "strcpy"
cristi:~ diciu$

Monday, November 17, 2008

BucharestApp 1.4

I've released Version 1.4 of BucharestApp

Changelog:


    version 1.4
  • Help book

  • Rendering based on data from November 2008




    version 1.3
  • OpenLayer library off-line copy (complete off-line map)

  • Route from, to picking from map (shift-click sets from, alt-click sets to)

  • Proper resize on window resize (old version was reloading the entire document)

  • Keyboard navigation (arrow keys for navigation, plus key to zoom in, minus key to zoom out)

Friday, November 07, 2008

Diacritical insensitive comparison, string folding

One of the common problems when dealing with language containing diacritical marks is matching an improper writing of a word missing the diacritical marks.

This is especially true for Romanian, as most Romanians (myself included) don't use diacritical marks when writing in Romanian.

I'm not here to pass judgment on writing with or without diacritics. There are others much better informed on the subject.

The reality is improper use of diacritics will not disappear in the near future and the good news is that Cocoa has built-in support for dealing with this:


NSString * stringDia = [NSString stringWithString:@"Mămăligă"];
NSString * string = [NSString stringWithString:@"Mamaliga"];

int res = [stringDia compare:string options:NSDiacriticInsensitiveSearch];
NSLog(@"The strings are %@equal", res == NSOrderedSame ? @"" : @"not ");



There's even an implementation for string folding which may be worthwhile if you're building an index of place names:

CFStringFold

Discussion
Character foldings are operations that convert any of a set of characters sharing similar semantics into a single representative from that set.

You can use this function to preprocess strings that are to be compared, searched, or indexed.[..]


PS In care you were wondering: Mămăligă.