2
* str.c - string functions
6
* Copyright (C) 1996-1998 Hirotsugu Kakugawa.
9
* This file is part of the VFlib Library. This library is free
10
* software; you can redistribute it and/or modify it under the terms of
11
* the GNU Library General Public License as published by the Free
12
* Software Foundation; either version 2 of the License, or (at your
13
* option) any later version. This library is distributed in the hope
14
* that it will be useful, but WITHOUT ANY WARRANTY; without even the
15
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16
* PURPOSE. See the GNU Library General Public License for more details.
17
* You should have received a copy of the GNU Library General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35
#include <sys/types.h>
36
#include <sys/param.h>
38
#include "VFlib-3_6.h"
51
if ((p = (char*)malloc(strlen(s)+1)) == NULL){
52
vf_error = VF_ERR_NO_MEMORY;
61
vf_strcmp_ci(char *s1, char *s2)
64
if ((*s1 == '\0') && (*s2 == '\0'))
66
if ((*s1 == '\0') || (*s2 == '\0'))
68
if (tolower(*s1) != tolower(*s2))
77
vf_strncmp_ci(char *s1, char *s2, int n)
81
if ((*s1 == '\0') && (*s2 == '\0'))
83
if ((*s1 == '\0') || (*s2 == '\0'))
85
if (tolower(*s1) != tolower(*s2))
96
vf_index(char *s, char ch)
100
if ((i = vf_index_i(s, ch)) < 0)
107
vf_index_i(char *s, char ch)
112
while (s[i] != '\0'){
122
vf_rindex(char *s, char ch)
126
if ((i = vf_rindex_i(s, ch)) < 0)
133
vf_rindex_i(char *s, char ch)
151
vf_index_str_i(char *s, char *t)
160
while (s[i] != '\0'){
161
if (strncmp(&s[i], t, tlen) == 0)
170
vf_index_str(char *s, char *t)
174
if ((i = vf_index_str_i(s, t)) < 0)
181
vf_rindex_str_i(char *s, char *t)
185
if ((s == NULL) | (t == NULL))
189
i = strlen(s) - tlen;
191
if (strncmp(&s[i], t, tlen) == 0)
199
vf_rindex_str(char *s, char *t)
203
if ((i = vf_rindex_str_i(s, t)) < 0)
210
vf_parse_bool(char *s)
213
if ( (vf_strncmp_ci(s, "TRUE", 4) == 0)
214
|| (vf_strncmp_ci(s, "YES", 3) == 0)
215
|| (vf_strncmp_ci(s, "OK", 2) == 0)
216
|| (vf_strncmp_ci(s, "ON", 2) == 0)
217
|| (vf_strncmp_ci(s, "T", 1) == 0) /* lisp */
218
|| (vf_strncmp_ci(s, "#T", 2) == 0) /* scheme */
219
|| (vf_strncmp_ci(s, "1", 1) == 0) )
222
if ( (vf_strncmp_ci(s, "FALSE", 5) == 0)
223
|| (vf_strncmp_ci(s, "NO", 2) == 0)
224
|| (vf_strncmp_ci(s, "OFF", 2) == 0)
225
|| (vf_strncmp_ci(s, "NIL", 3) == 0) /* lisp */
226
|| (vf_strncmp_ci(s, "#F", 2) == 0) /* scheme */
227
|| (vf_strncmp_ci(s, "0", 1) == 0) )
231
/* Need a warning message? */
232
/* Need to specify default value? */