]> andersk Git - moira.git/blob - lib/strs.c
fix bugs in parsing the optional port number, introduced in the mrgdb
[moira.git] / lib / strs.c
1 /* $Id$
2  *
3  * Miscellaneous string functions.
4  *
5  * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
6  * For copying and distribution information, please see the file
7  * <mit-copyright.h>.
8  */
9
10 #include <mit-copyright.h>
11 #include <moira.h>
12
13 #include <ctype.h>
14
15 RCSID("$Header$");
16
17 /*
18  * Trim whitespace off both ends of a string.
19  */
20 char *strtrim(char *save)
21 {
22   char *t, *s;
23
24   s = save;
25   while (isspace(*s))
26     s++;
27   /* skip to end of string */
28   if (*s == '\0')
29     {
30       if (*save)
31         *save = '\0';
32       return save;
33     }
34
35   for (t = s; *t; t++)
36     continue;
37   while (t > s)
38     {
39       --t;
40       if (!isspace(*t))
41         {
42           t++;
43           break;
44         }
45     }
46   if (*t)
47     *t = '\0';
48   return s;
49 }
50
51
52 /* Modify a string for all of the letters to be uppercase. */
53
54 char *uppercase(char *s)
55 {
56   char *p;
57
58   for (p = s; *p; p++)
59     {
60       if (islower(*p))
61         *p = toupper(*p);
62     }
63   return s;
64 }
65
66
67 char *lowercase(char *s)
68 {
69   char *p;
70
71   for (p = s; *p; p++)
72     {
73       if (isupper(*p))
74         *p = tolower(*p);
75     }
76   return s;
77 }
This page took 0.308667 seconds and 5 git commands to generate.