(budg): Create the capital/city name from the d_name field instead of

hard coding the strings.

(plurize): New.
This commit is contained in:
Ron Koenderink 2005-11-13 21:23:44 +00:00
parent 2f1b7cd2a3
commit fdcbb5912d
3 changed files with 33 additions and 6 deletions

View file

@ -51,3 +51,29 @@ iesplur(int n)
{
return n == 1 ? "y" : "ies";
}
/*
* Change suffix of BUF to English plural if N > 1.
* Best effort, not 100% accurate English.
* Array BUF[MAX_LEN] contains a zero-terminated string.
* If there's not enough space for changed suffix, it is truncated.
*/
char *
plurize(char *buf, int max_len, int n)
{
if (!strlen(buf) || n <= 1)
return buf;
switch(buf[strlen(buf) - 1]) {
case 'y':
buf[strlen(buf) -1] = '\0';
strncat(buf, "ies", max_len - 1);
break;
case 's':
strncat(buf, "es", max_len - 1);
break;
default:
strncat(buf, "s", max_len - 1);
}
return buf;
}