XrdOucTokenizer.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                    X r d O u c T o k e n i z e r . c c                     */
00004 /*                                                                            */
00005 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
00006 /*       All Rights Reserved. See XrdInfo.cc for complete License Terms       */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC03-76-SFO0515 with the Deprtment of Energy               */
00009 /******************************************************************************/
00010 
00011 //       $Id: XrdOucTokenizer.cc 22437 2008-03-04 14:35:16Z rdm $
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 /*                                A t t a c h                                 */
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 /*                               G e t L i n e                                */
00037 /******************************************************************************/
00038   
00039 char *XrdOucTokenizer::GetLine()
00040 {
00041    char *bp;
00042 
00043 // Check if end of buffer has been reached.
00044 //
00045    if (*buff == '\0') return (char *)NULL;
00046 
00047 // Find the next record in the buffer
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 // Find the end of the record
00057 //
00058    if (notabs)
00059             while(*bp && *bp != '\n') {if (*bp == '\t') *bp = ' '; bp++;}
00060        else while(*bp && *bp != '\n') bp++;
00061 
00062 // Set the end of the line
00063 //
00064    if (*bp) {*bp = '\0'; buff = bp+1;}
00065       else buff = bp;
00066 
00067 // All done
00068 //
00069    token = 0;
00070    return tnext;
00071 }
00072 
00073 /******************************************************************************/
00074 /*                              G e t T o k e n                               */
00075 /******************************************************************************/
00076   
00077 char *XrdOucTokenizer::GetToken(char **rest, int lowcase)
00078 {
00079 
00080      // Skip to the first non-blank character.
00081      //
00082      while (*tnext && *tnext == ' ') tnext++;
00083      if (!*tnext) return (char *)NULL;
00084      token = tnext;
00085 
00086      // Find the end of the token.
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      // Check if remaining line is to be returned
00094      //
00095      if (rest)
00096         {while (*tnext && *tnext == ' ') tnext++;
00097          *rest = tnext;
00098         }
00099 
00100      // All done here.
00101      //
00102      return token;
00103 }
00104 
00105 /******************************************************************************/
00106 /*                              R e t T o k e n                               */
00107 /******************************************************************************/
00108   
00109 void XrdOucTokenizer::RetToken()
00110 {
00111      // Backup one token, we can only back up once
00112      //
00113      if (token)
00114         {if (*tnext) *(tnext-1) = ' ';
00115          tnext = token;
00116          token = 0;
00117         }
00118 }

Generated on Tue Jul 5 14:46:57 2011 for ROOT_528-00b_version by  doxygen 1.5.1