00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 const char *XrdOucTokenizerCVSID = "$Id: XrdOucTokenizer.cc 22437 2008-03-04 14:35:16Z rdm $";
00014
00015 #ifndef WIN32
00016 #include <unistd.h>
00017 #endif
00018 #include <ctype.h>
00019 #include <stdlib.h>
00020
00021 #include "XrdOuc/XrdOucTokenizer.hh"
00022
00023
00024
00025
00026
00027 void XrdOucTokenizer::Attach(char *bp)
00028 {
00029 buff = bp;
00030 token = 0;
00031 tnext = (char *)"";
00032 notabs = 0;
00033 }
00034
00035
00036
00037
00038
00039 char *XrdOucTokenizer::GetLine()
00040 {
00041 char *bp;
00042
00043
00044
00045 if (*buff == '\0') return (char *)NULL;
00046
00047
00048
00049 bp = buff;
00050 if (notabs)
00051 while(*bp && (*bp == ' ' || *bp == '\t')) bp++;
00052 else while(*bp && *bp == ' ' ) bp++;
00053
00054 tnext = bp;
00055
00056
00057
00058 if (notabs)
00059 while(*bp && *bp != '\n') {if (*bp == '\t') *bp = ' '; bp++;}
00060 else while(*bp && *bp != '\n') bp++;
00061
00062
00063
00064 if (*bp) {*bp = '\0'; buff = bp+1;}
00065 else buff = bp;
00066
00067
00068
00069 token = 0;
00070 return tnext;
00071 }
00072
00073
00074
00075
00076
00077 char *XrdOucTokenizer::GetToken(char **rest, int lowcase)
00078 {
00079
00080
00081
00082 while (*tnext && *tnext == ' ') tnext++;
00083 if (!*tnext) return (char *)NULL;
00084 token = tnext;
00085
00086
00087
00088 if (lowcase) while (*tnext && *tnext != ' ')
00089 {*tnext = (char)tolower((int)*tnext); tnext++;}
00090 else while (*tnext && *tnext != ' ') {tnext++;}
00091 if (*tnext) {*tnext = '\0'; tnext++;}
00092
00093
00094
00095 if (rest)
00096 {while (*tnext && *tnext == ' ') tnext++;
00097 *rest = tnext;
00098 }
00099
00100
00101
00102 return token;
00103 }
00104
00105
00106
00107
00108
00109 void XrdOucTokenizer::RetToken()
00110 {
00111
00112
00113 if (token)
00114 {if (*tnext) *(tnext-1) = ' ';
00115 tnext = token;
00116 token = 0;
00117 }
00118 }