su 1.12.10

sofia-sip/string0.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of the Sofia-SIP package
00003  *
00004  * Copyright (C) 2005 Nokia Corporation.
00005  *
00006  * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation; either version 2.1 of
00011  * the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00021  * 02110-1301 USA
00022  *
00023  */
00024 
00025 #ifndef STRING0_H
00026 
00027 #define STRING0_H
00028 
00038 #ifndef SU_CONFIG_H
00039 #include <sofia-sip/su_config.h>
00040 #endif
00041 
00042 #include <string.h>
00043 
00044 SOFIA_BEGIN_DECLS
00045 
00046 su_inline int str0cmp(char const *a, char const *b)
00047 {
00048   if (a == NULL) a = "";
00049   if (b == NULL) b = "";
00050   return strcmp(a, b);
00051 }
00052 
00053 su_inline int str0ncmp(char const *a, char const *b, size_t n)
00054 {
00055   if (a == NULL) a = "";
00056   if (b == NULL) b = "";
00057   return strncmp(a, b, n);
00058 }
00059 
00060 su_inline int str0casecmp(char const *a, char const *b)
00061 {
00062   if (a == NULL) a = "";
00063   if (b == NULL) b = "";
00064   return strcasecmp(a, b);
00065 }
00066 
00067 su_inline int str0ncasecmp(char const *a, char const *b, size_t n)
00068 {
00069   if (a == NULL) a = "";
00070   if (b == NULL) b = "";
00071   return strncasecmp(a, b, n);
00072 }
00073 
00074 #if !SU_HAVE_INLINE
00075 SOFIAPUBFUN size_t strnspn(char const *s, size_t size, char const *term);
00076 SOFIAPUBFUN size_t strncspn(char const *s, size_t ssize, char const *reject);
00077 #else
00078 su_inline size_t strnspn(char const *s, size_t ssize, char const *term)
00079 {
00080   size_t n;
00081   size_t tsize = strlen(term);
00082 
00083   if (tsize == 0) {
00084     return 0;
00085   }
00086   else if (tsize == 1) {
00087     char c, t = term[0];
00088     for (n = 0; n < ssize && (c = s[n]) && c == t; n++)
00089       ;
00090   }
00091   else if (tsize == 2) {
00092     char c, t1 = term[0], t2 = term[1];
00093     for (n = 0; n < ssize && (c = s[n]) && (c == t1 || c == t2); n++)
00094       ;
00095   }
00096   else {
00097     size_t i;
00098     char c, t1 = term[0], t2 = term[1];
00099     for (n = 0; n < ssize && (c = s[n]) && (c == t1 || c == t2); n++) {
00100       for (i = 2; i < tsize; i++)
00101         if (c == term[i])
00102           return n;
00103     }
00104   }
00105 
00106   return n;
00107 }
00108 
00109 su_inline size_t strncspn(char const *s, size_t ssize, char const *reject)
00110 {
00111   size_t n;
00112   size_t rsize = strlen(reject);
00113 
00114   if (rsize == 0) {
00115     for (n = 0; n < ssize && s[n]; n++)
00116       ;
00117   }
00118   else if (rsize == 1) {
00119     char c, rej = reject[0];
00120     for (n = 0; n < ssize && (c = s[n]) && c != rej; n++)
00121       ;
00122   }
00123   else if (rsize == 2) {
00124     char c, rej1 = reject[0], rej2 = reject[1];
00125     for (n = 0; n < ssize && (c = s[n]) && c != rej1 && c != rej2; n++)
00126       ;
00127   }
00128   else {
00129     size_t i;
00130     char c, rej1 = reject[0], rej2 = reject[1];
00131     for (n = 0; n < ssize && (c = s[n]) && c != rej1 && c != rej2; n++) {
00132       for (i = 2; i < rsize; i++)
00133         if (c == reject[i])
00134           return n;
00135     }
00136   }
00137 
00138   return n;
00139 }
00140 
00141 #endif
00142 
00143 SOFIA_END_DECLS
00144 
00145 #endif /* !STRING0_H */
 All Data Structures Files Functions Variables Typedefs Enumerator Defines

Sofia-SIP 1.12.10 - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.