/****************************** * QGRAMNORMALIZE * * This function 'normalizes' a string so valid q-grams can be made of it: * All characters are transformed to uppercase, and all characters * which are not letters or digits are stripped to a single space. * * qgramnormalize("Hallo, allemaal!").print(); --> "HALLO ALLEMAAL" * qgramnormalize(" '' t ' est").print(); --> [ "T EST" ] * *****************************/ str CMDqgramnormalize(str *res, str *Input) { char *input = *Input; int i, j = 0; char c, last = ' '; RETURN_NIL_IF(strNil(input), TYPE_str); *res = (str) GDKmalloc(sizeof(char) * (strlen(input) + 1)); /* normalized strings are never longer than original */ for (i = 0; input[i]; i++) { c = toupper(input[i]); if (!(('A' <= c && c <= 'Z') || ('0' <= c && c <= '9'))) c = ' '; if (c != ' ' || last != ' ') { (*res)[j++] = c; } last = c; } (*res)[j] = 0; /* strip final whitespace */ while (j > 0 && (*res)[--j] == ' ') (*res)[j] = 0; return MAL_SUCCEED; }
str soundex_impl(str *res, str *Name) { RETURN_NIL_IF(strNil(*Name), TYPE_str); *res = (str) GDKmalloc(sizeof(char) * (SoundexLen + 1)); /* calculate Key for Name */ soundex_code(*Name, *res); return MAL_SUCCEED; }
str soundex_impl(str *res, str *Name) { RETURN_NIL_IF(strNil(*Name), TYPE_str); *res = (str) GDKmalloc(sizeof(char) * (SoundexLen + 1)); if( *res == NULL) throw(MAL,"soundex", MAL_MALLOC_FAIL); /* calculate Key for Name */ soundex_code(*Name, *res); return MAL_SUCCEED; }