ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/utils.C
(Generate patch)

Comparing deliantra/server/common/utils.C (file contents):
Revision 1.90 by root, Thu Oct 15 21:09:32 2009 UTC vs.
Revision 1.91 by root, Tue Oct 20 05:57:08 2009 UTC

408 { 408 {
409 result[resultlen++] = *src++; 409 result[resultlen++] = *src++;
410 } 410 }
411 } 411 }
412 result[resultlen] = '\0'; 412 result[resultlen] = '\0';
413}
414
415/**
416 * Taking a string as an argument, mutate it into a string that looks like a list.
417 * a 'list' for the purposes here, is a string of items, seperated by commas, except
418 * for the last entry, which has an 'and' before it, and a full stop (period) after it.
419 * This function will also strip all trailing non alphanumeric characters.
420 * It does not insert an oxford comma.
421 */
422void
423make_list_like (char *input)
424{
425 char *p, tmp[MAX_BUF];
426 int i;
427
428 if (!input || strlen (input) > MAX_BUF - 5)
429 return;
430 /* bad stuff would happen if we continued here, the -5 is to make space for ' and ' */
431
432 strncpy (tmp, input, MAX_BUF - 5);
433 /*trim all trailing commas, spaces etc. */
434 for (i = strlen (tmp); !isalnum (tmp[i]) && i >= 0; i--)
435 tmp[i] = '\0';
436
437 strcat (tmp, ".");
438
439 p = strrchr (tmp, ',');
440 if (p)
441 {
442 *p = '\0';
443 strcpy (input, tmp);
444 p++;
445 strcat (input, " and");
446 strcat (input, p);
447 }
448 else
449 strcpy (input, tmp);
450
451 return;
452} 413}
453 414
454/******************************************************************************/ 415/******************************************************************************/
455 416
456/* Checks a player-provided string which will become the msg property of 417/* Checks a player-provided string which will become the msg property of

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines