Creating a Custom Character Map: Example
The following code sample creates a character map similar to the standard character map except that the characters ’&’ and ’#’ are not mapped, the dash character ’-’ is deleted and the default case folding for the letter ’I’ is changed to that for Turkish. We start by checking to see if our character map is already created.
static char map_name = "our-turkic-map" ;
static char from_set = "&#-I" ;
/* ampersand, pound, delete it, lower i no dot */
static int to_set = { 0x0026, 0x0023, LKT_CHAR_DELETE, 0x0131 } ;
lpar_t mapname ; /* name of our character map */
lpar_t mapdef ; /* definition parameters for creating map */
lpar_t mapping ; /* one mapping clause in mapdef */
dvkerr_t err ; /* return status of devkit function calls */
/* create descriptor for our character map */
mapname = lpar_create_str(LPAR_STR_CHARMAP, map_name) ;
/* create only if doesn't already exist */
err = lkt_charmap_list(mapdesc, NULL) ;
if (DVKERR(err) == DVK_ERR_DBNOTFOUND) {
/* create parameter list */
mapdef = lkt_list_create();
/* fold case */
lkt_list_append(mapdef, lpar_create_int(LPAR_INT_FOLDCLASS, LKT_CCLASS_CASE));
/* fold diacritics and normalize */
lkt_list_append(mapdef,
lpar_create_int(LPAR_INT_FOLDCLASS, LKT_CCLASS_DIACRITICS));
/* map all whitespace to blank */
mapping = lpar_create_list(LPAR_LST_MAP);
lkt_list_append(mapping, lpar_create_int(LPAR_INT_FROM_CLASS,
LKT_CCLASS_WHITESPACE));
lkt_list_append(mapping, lpar_create_blk(LPAR_BLK_TO_CHARS, " ", 1));
lkt_list_append(mapdef, mapping);
/* map all punctuation to blank */
mapping = lpar_create_list(LPAR_LST_MAP);
lkt_list_append(mapping, lpar_create_int(LPAR_INT_FROM_CLASS,
LKT_CCLASS_PUNCTUATION));
lkt_list_append(mapping, lpar_create_blk(LPAR_BLK_TO_CHARS, " ", 1));
lkt_list_append(mapdef, mapping);
/* now apply our special mappings */
mapping = lpar_create_list(LPAR_LST_MAP);
lkt_list_append(mapping, lpar_create_blk(LPAR_BLK_FROM_CHARS, from_set, 4));
lkt_list_append(mapping, lpar_create_intarr(LPAR_INTARR_TO_UCODES, to_set, 4));
lkt_list_append(mapdef, mapping);
/* create the character map */
err = lkt_create_charmap(mapname, mapdef);
if (DVKERR(err)) {
/* handle error here */
}
}