/[winpt]/trunk/Src/wptUtil.cpp
ViewVC logotype

Diff of /trunk/Src/wptUtil.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 60 by twoaday, Wed Nov 2 14:35:48 2005 UTC revision 214 by twoaday, Sun May 14 18:40:36 2006 UTC
# Line 17  Line 17 
17   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
18   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19   */   */
20    
21  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
22  #include <config.h>  #include <config.h>
23  #endif  #endif
24    
25  #include <string.h>  #include <string.h>
26  #include <string.h>  #include <stdlib.h>
27  #include <stdio.h>  #include <stdio.h>
28  #include <ctype.h>  #include <ctype.h>
29    
30  /* code taken from glibc-2.2.1/sysdeps/generic/strsep.c */  /* code taken from glibc-2.2.1/sysdeps/generic/strsep.c */
31  extern "C" char*  char*
32  strsep (char **stringp, const char *delim)  strsep (char **stringp, const char *delim)
33  {  {
34      char *begin, *end;      char *begin, *end;
# Line 68  strsep (char **stringp, const char *deli Line 69  strsep (char **stringp, const char *deli
69    
70    
71  /* Like strstr but this version is case in-sentensive. */  /* Like strstr but this version is case in-sentensive. */
72  extern "C" const char *  const char *
73  stristr (const char *buf, const char *sub)  stristr (const char *buf, const char *sub)
74  {  {
75      const char *t, *s ;      const char *t, *s ;
# Line 88  stristr (const char *buf, const char *su Line 89  stristr (const char *buf, const char *su
89      return NULL ;      return NULL ;
90  }  }
91    
92    
93    /* Check if the email address @email only contain valid characters.
94       Return 0 on success. */
95    int
96    check_email_address (const char *email)
97    {
98        const char *allowed = "@._-%+;";
99        size_t i;
100    
101        if (!strchr (email, '@'))
102            return -1;
103        for (i=0; i < strlen (email); i++) {
104            if (isdigit (email[i]) || isalpha (email[i])
105                || strchr (allowed, email[i]))
106                continue;
107            else
108                return -1;
109        }
110        return 0;
111    }
112    
113    
114    /* Return a substring of @str from the position @begin
115       to position @end. */
116    char*
117    substr (const char *str, unsigned int begin, unsigned int end)
118    {    
119        char *p;
120        size_t i, pos;
121    
122        if (end > strlen (str) || begin > strlen (str) || (end-begin) < 0)
123            return NULL;
124    
125        /*p = new char[end-begin+1]; XXX: fixme*/
126        p = (char*)calloc (1, end-begin+1);
127        if (!p)
128            abort ();
129    
130        for (i = begin, pos=0; i < end; i++)
131            p[pos++] = str[i];
132        p[pos] = '\0';
133        return p;
134    }

Legend:
Removed from v.60  
changed lines
  Added in v.214

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26