| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

soundexn

#include "sflstr.h"
char *
soundexn (
    const char *string, int size, Bool fold)

Synopsis

Calculates the SOUNDEX code for the string. Returns the address of a static area that holds the code. This area is overwritten by each call to the soundex function. The SOUNDEX encoding converts letters to uppercase, and translates each letter according to this table: A0 B1 C2 D3 E0 F1 G2 H0 I0 J2 K2 L4 M5 N5 O0 P1 Q2 R6 S2 T3 U0 V1 W0 X2 Y0 Z2. Non-letters are ignored, letters that translate to zero, and multiple occurences of the same value are also ignored. This function returns a N-letter encoding: the first letter of the string followed by the first N-1 significant digits. N may not be greater than SOUNDEX_MAX (100). If the fold argument is true, includes the first letter in the calculated digits, else starts with the second letter.

Source Code - (sflstr.c)

{
#   define SOUNDEX_MAX  100
#   define SOUNDEX_TABLE                           "00000000000000000000000000000000"         "00000000000000000000000000000000"         "00123012002245501262301020200000"         "00123012002245501262301020200000"         "00000000000000000000000000000000"         "00000000000000000000000000000000"         "00000000000000000000000000000000"         "00000000000000000000000000000000"

    static char
       *soundex_table = SOUNDEX_TABLE,  /*  ASCII-SOUNDEX conversion         */
        soundex_code [SOUNDEX_MAX + 1]; /*  Letter + 3 digits                */
    int
        index;
    char
        last_value = 0,
        this_value;

    ASSERT (string);
    ASSERT (size > 0 && size <= SOUNDEX_MAX);

    /*  Initialise the soundex code to a string of zeroes                    */
    memset (soundex_code, '0', size);
    soundex_code [size] = '\0';

    soundex_code [0] = toupper (*string);
    last_value = fold? 0: soundex_table [(byte) *string];
    index = 1;                          /*  Store results at [index]         */
    while (*string)
      {
        this_value = soundex_table [(byte) *string++];
        if (this_value == last_value    /*  Ignore doubles                   */
        ||  this_value == '0')          /*    and 'quiet' letters            */
          {
            last_value = this_value;
            continue;
          }
        last_value = this_value;
        soundex_code [index++] = this_value;
        if (index == size)              /*  Up to size result characters     */
            break;
      }
    return (soundex_code);
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation