1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (c) 1983-2009 Kevin Rosenberg
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License (version 2) as
7 ** published by the Free Software Foundation.
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU General Public License for more details.
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 ******************************************************************************/
20 #include "ctsupport.h"
24 * str_skip_head Skip leading characters of string
27 * shortened = str_skip_head (str, charlist)
28 * OUT shortened Start of shortened string
29 * IN char *str String to have beginning skipped
30 * IN char *charlist List of characters to skip over
33 * This routine returns the position in a string (str) of the
34 * first character that is not in an specified string of characters
40 str_skip_head (const char* str, const char* const charlist)
44 while (*p && (strchr (charlist, *p) != NULL))
47 return (const_cast<char*>(p));
51 str_skip_head (const char* str, char* charlist)
55 while (*p && (strchr (charlist, *p) != NULL))
58 return (const_cast<char*>(p));
63 * str_lower Convert a string to lower case
66 * str = str_lower (str)
67 * char *str String to be converted
75 while (*p) { /* while (*p != EOS) */
84 * str_rm_tail Remove characters from end of string
87 * str = str_rm_tail (str, charlist)
88 * char *str String to have end removed
89 k * char *charlist List of characters to remove from string
95 str_rm_tail (char *str, const char* const charlist)
99 for (i = strlen(str) - 1; i >= 0; i--)
100 if (strchr (charlist, str[i]) != NULL)
103 break; /* found non-specified char, all done */
109 * str_wrm_tail Remove white space from end of string
112 * str = str_wrm_tail (str)
113 * char *str String to have white space removed
118 str_wrm_tail (char *str)
120 return (str_rm_tail(str, "\b\t\n\r"));
124 * str_upper Convert a string to upper case
127 * str = str_upper (str)
128 * char *str String to be converted
136 while (*p) { /* while (*s != EOS) */
152 printf ("Test program for str_skip_head\n");
154 printf ("Enter string that will have its head skipped -- ");
156 printf ("Enter list of characters to be skipped -- ");
160 skip = str_skip_head (str, clist);
162 printf ("Shortened string = '%s'\n", skip);