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.89 by root, Mon Oct 12 14:00:57 2009 UTC vs.
Revision 1.91 by root, Tue Oct 20 05:57:08 2009 UTC

410 } 410 }
411 } 411 }
412 result[resultlen] = '\0'; 412 result[resultlen] = '\0';
413} 413}
414 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}
453
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
457 * an object for dangerous input. 418 * an object for dangerous input.
458 */ 419 */
612 memcpy (dst, src, ++len); 573 memcpy (dst, src, ++len);
613 574
614 return len; 575 return len;
615} 576}
616 577
617const char * 578char *
579vformat (const char *format, va_list ap)
580{
581 static dynbuf_text buf; buf.clear ();
582 buf.vprintf (format, ap);
583 return buf;
584}
585
586char *
618format (const char *format, ...) 587format (const char *format, ...)
619{ 588{
620 static dynbuf_text buf;
621
622 buf.clear ();
623
624 va_list ap; 589 va_list ap;
625 va_start (ap, format); 590 va_start (ap, format);
626 buf.vprintf (format, ap); 591 char *buf = vformat (format, ap);
627 va_end (ap); 592 va_end (ap);
628 593
629 return buf; 594 return buf;
630} 595}
631 596

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines