kabc Library API Documentation

RToken.cpp

00001 /*
00002     
00003     libvcard - vCard parsing library for vCard version 3.0
00004 
00005     Copyright (C) 1999 Rik Hemsley rik@kde.org
00006 
00007   Permission is hereby granted, free of charge, to any person obtaining a copy
00008   of this software and associated documentation files (the "Software"), to
00009   deal in the Software without restriction, including without limitation the
00010   rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00011   sell copies of the Software, and to permit persons to whom the Software is
00012   furnished to do so, subject to the following conditions:
00013 
00014   The above copyright notice and this permission notice shall be included in
00015   all copies or substantial portions of the Software.
00016 
00017   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00020   AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00021   ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00022   WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023 */
00024 
00025 #include <string.h>
00026 #include <stddef.h>
00027 #include <qcstring.h>
00028 #include <qstrlist.h>
00029 
00030 namespace VCARD
00031 {
00032 
00033     Q_UINT32
00034 RTokenise(const char * str, const char * delim, QStrList & l)
00035 {
00036     // FIXME no stderr !
00037     l.clear();
00038     
00039     if (!delim || !str || strlen(delim) == 0 || strlen(str) == 0) return 0;
00040     
00041     char * len = (char *)(str + strlen(str));   // End of string.
00042     
00043     register char * rstart = new char[strlen(str) + 1];
00044     register char * r = rstart;
00045     
00046     
00047     register const char * i = str;  // Cursor.
00048     
00049     while (i <= len) {
00050 
00051         if (*i == '\\') { // Escaped chars go straight through.
00052             *r++ = *i++;
00053             if (i <= len)
00054                 *r++ = *i++;
00055             continue;
00056         }
00057         
00058         if (strchr(delim, *i) != 0) {
00059             // We hit a delimiter. If we have some text, make a new token.
00060             // This has the effect that multiple delimiters are collapsed.
00061                         // cs: We mustn't collapse multiple delimiters, otherwise we
00062                         // lose empty fields.
00063             *r = '\0';
00064 //          if (r != rstart) {
00065                 l.append(rstart);
00066 //          }
00067             r = rstart;
00068             ++i;
00069             continue;
00070         }
00071         
00072         *r++ = *i++;
00073     }
00074 
00075     // Catch last token
00076 //  if (r != rstart) {
00077         *r = '\0';
00078         l.append(rstart);
00079 //  }
00080     
00081     r = 0;
00082     
00083     delete [] rstart;
00084 
00085     return l.count();
00086 }
00087 
00088 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:22:08 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001