Logo Search packages:      
Sourcecode: bglibs version File versions

long str_xlate ( str s,
const char *  from,
const char *  to,
unsigned  nchars 
)

Substitute one character for another throughout the string.

Returns:
the number of substitutions made.

Definition at line 24 of file xlate.c.

References len, and s.

{
  int map[256];
  unsigned i;
  char* ptr;
  long count;
  int ch;
  for (i = 0; i < 256; ++i)
    map[i] = -1;
  for (i = 0; i < nchars; ++i)
    map[(unsigned char)from[i]] = (unsigned char)to[i];
  for (count = 0, i = 0, ptr = s->s; i < s->len; ++i, ++ptr)
    if ((ch = map[(unsigned char)*ptr]) != -1) {
      *ptr = ch;
      ++count;
    }
  return count;
}


Generated by  Doxygen 1.6.0   Back to index