]>
Commit | Line | Data |
---|---|---|
fa59b86f | 1 | /* $Id$ |
68687902 | 2 | * |
7ac48069 | 3 | * Miscellaneous string functions. |
68687902 | 4 | * |
7ac48069 | 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>. | |
68687902 | 8 | */ |
9 | ||
babbc197 | 10 | #include <mit-copyright.h> |
7ac48069 | 11 | #include <moira.h> |
0fed7e9b | 12 | |
7ac48069 | 13 | #include <ctype.h> |
68687902 | 14 | |
7ac48069 | 15 | RCSID("$Header$"); |
5eaef520 | 16 | |
68687902 | 17 | /* |
18 | * Trim whitespace off both ends of a string. | |
19 | */ | |
44d12d58 | 20 | char *strtrim(char *save) |
68687902 | 21 | { |
44d12d58 | 22 | char *t, *s; |
5eaef520 | 23 | |
24 | s = save; | |
25 | while (isspace(*s)) | |
26 | s++; | |
27 | /* skip to end of string */ | |
28 | if (*s == '\0') | |
29 | { | |
0c99b4ff | 30 | if (*save) |
31 | *save = '\0'; | |
5eaef520 | 32 | return save; |
9ca8ff13 | 33 | } |
68687902 | 34 | |
5eaef520 | 35 | for (t = s; *t; t++) |
36 | continue; | |
37 | while (t > s) | |
38 | { | |
39 | --t; | |
40 | if (!isspace(*t)) | |
41 | { | |
42 | t++; | |
43 | break; | |
68687902 | 44 | } |
45 | } | |
5eaef520 | 46 | if (*t) |
47 | *t = '\0'; | |
48 | return s; | |
68687902 | 49 | } |
77f073b6 | 50 | |
51 | ||
52 | /* Modify a string for all of the letters to be uppercase. */ | |
53 | ||
5eaef520 | 54 | char *uppercase(char *s) |
77f073b6 | 55 | { |
44d12d58 | 56 | char *p; |
77f073b6 | 57 | |
5eaef520 | 58 | for (p = s; *p; p++) |
59 | { | |
77f073b6 | 60 | if (islower(*p)) |
61 | *p = toupper(*p); | |
5eaef520 | 62 | } |
63 | return s; | |
77f073b6 | 64 | } |
bc5b5d78 | 65 | |
66 | ||
5eaef520 | 67 | char *lowercase(char *s) |
bc5b5d78 | 68 | { |
44d12d58 | 69 | char *p; |
bc5b5d78 | 70 | |
5eaef520 | 71 | for (p = s; *p; p++) |
72 | { | |
bc5b5d78 | 73 | if (isupper(*p)) |
74 | *p = tolower(*p); | |
501a4b9d | 75 | } |
5eaef520 | 76 | return s; |
501a4b9d | 77 | } |