1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (c) 1983-2001 Kevin Rosenberg
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License (version 2) as
9 ** published by the Free Software Foundation.
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
16 ** You should have received a copy of the GNU General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ******************************************************************************/
22 #include "ctsupport.h"
26 * str_skip_head Skip leading characters of string
29 * shortened = str_skip_head (str, charlist)
30 * OUT shortened Start of shortened string
31 * IN char *str String to have beginning skipped
32 * IN char *charlist List of characters to skip over
35 * This routine returns the position in a string (str) of the
36 * first character that is not in an specified string of characters
42 str_skip_head (const char* str, const char* const charlist)
46 while (*p && (strchr (charlist, *p) != NULL))
49 return (const_cast<char*>(p));
53 str_skip_head (const char* str, char* charlist)
57 while (*p && (strchr (charlist, *p) != NULL))
60 return (const_cast<char*>(p));
65 * str_lower Convert a string to lower case
68 * str = str_lower (str)
69 * char *str String to be converted
77 while (*p) { /* while (*p != EOS) */
86 * str_rm_tail Remove characters from end of string
89 * str = str_rm_tail (str, charlist)
90 * char *str String to have end removed
91 k * char *charlist List of characters to remove from string
97 str_rm_tail (char *str, const char* const charlist)
101 for (i = strlen(str) - 1; i >= 0; i--)
102 if (strchr (charlist, str[i]) != NULL)
105 break; /* found non-specified char, all done */
111 * str_wrm_tail Remove white space from end of string
114 * str = str_wrm_tail (str)
115 * char *str String to have white space removed
120 str_wrm_tail (char *str)
122 return (str_rm_tail(str, "\b\t\n\r"));
126 * str_upper Convert a string to upper case
129 * str = str_upper (str)
130 * char *str String to be converted
138 while (*p) { /* while (*s != EOS) */
154 printf ("Test program for str_skip_head\n");
156 printf ("Enter string that will have its head skipped -- ");
158 printf ("Enter list of characters to be skipped -- ");
162 skip = str_skip_head (str, clist);
164 printf ("Shortened string = '%s'\n", skip);