translate.c~

MudOSa4DGD/mudlib/dgd/sfun/translate.c~ · 849 B

From the archive MudOSa4DGD-30.06.98.tar.gz

Download the archive   « Back to the archive contents

/*
 * translate.c
 *
 * SFUN: translate a string using a mapping as dictionary
 *
 * Taken from VikingMUD
 * Modified for DGD by Frank Schmidt
 *
 */

#ifndef __AUTO             /* outside auto object */


string transl(string a, mapping d) {
  return d[a] ? d[a] : a;
}


#else                      /* inside auto object */


static varargs string translate(string arg, mapping dict, int intext) {
  if (intext) {
    /* on non-word basis */
    string *org, *sub;
    int i;

    org = map_indices(dict);
    sub = map_values(dict);
    for (i = sizeof(org); --i >= 0; ) {
      arg = replace_string(arg, org[i], sub[i]);
    }
  }
  else {
    /* on word by word basis (fastest) */
    arg = big_implode(map_array(big_explode(arg, " "),
			    "transl", SIMUL_EFUN, dict),
		  " ");
  }

  /* return translated string */
  return arg;
}


#endif

Site Stats

Snippets: 1791
Codebases: 571