| # Gaudi Framework, version v20r2
Generated: 18 Jul 2008

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Search for |

- File List
- File Members

# Tokenizer.cpp

Go to the documentation of this file.

    00001 // $Header: /local/reps/Gaudi/GaudiKernel/src/Lib/Tokenizer.cpp,v 1.3 2004/05/17 12:26:07 mato Exp $
    00002 //==============================================================================
    00003 // Tokenizer.h
    00004 //------------------------------------------------------------------------------
    00005 //
    00006 // Package : Kernel
    00007 //             The LHCb definition package
    00008 //
    00009 // Author  : M.Frank
    00010 //
    00011 // Changes : M.Frank ,  01/10/00: Initiali version
    00012 //
    00013 //==============================================================================
    00014 #define KERNEL_TOKENIZER_CPP
    00015 #include "GaudiKernel/Tokenizer.h"
    00016 #include "GaudiKernel/Environment.h"
    00017
    00018 // Assignment operator
    00019 Tokenizer::Token& Tokenizer::Token::operator=(const Token& copy)     {
    00020   m_length=copy.m_length;
    00021   m_tag=copy.m_tag;
    00022   m_value=copy.m_value;
    00023   return *this;
    00024 }
    00025
    00026 // Resolve value from environment
    00027 void Tokenizer::Token::resolveValue()  {
    00028   std::string res;
    00029   if ( System::resolveEnv(m_value, res).isSuccess() )  {
    00030     m_value = res;
    00031   }
    00032 }
    00033
    00034 // Create tokens from string
    00035 void Tokenizer::analyse(const std::string& s, const char* delim, const char* tagBegin, const char* tagEnd, const char* eq, const char* valBegin, const char* valEnd)    {
    00036   m_tokens.clear();
    00037   if ( valEnd == 0 ) valEnd = valBegin;
    00038   long start = 0;
    00039   Token tok;
    00040   do {
    00041     tok.make(s, start, delim, tagBegin, tagEnd, eq, valBegin, valEnd);
    00042     if ( tok.length() > 0 )   {
    00043       start += tok.length();
    00044       m_tokens.push_back(tok);
    00045     }
    00046     else  {
    00047       start += s.length();
    00048     }
    00049   } while ( start < long(s.length()) );
    00050   if ( m_resolve )  {
    00051     for(Items::iterator i=m_tokens.begin(); i != m_tokens.end(); ++i)  {
    00052       (*i).resolveValue();
    00053     }
    00054   }
    00055 }
    00056
    00057 // Create token from string
    00058 void Tokenizer::Token::make(const std::string& s, long st, const char* delim, const char* tagBeg, const char* tagEnd, const char* eq, const char* valBeg, const char* valEnd)    {
    00059   long lenTagBeg   = ::strlen(tagBeg);
    00060   long lenTagEnd   = ::strlen(tagEnd);
    00061   long lenValBeg   = ::strlen(valBeg);
    00062   long lenValEnd   = ::strlen(valEnd);
    00063   long lenDelim    = ::strlen(delim);
    00064   long lenEq       = ::strlen(eq);
    00065   long slen        = s.length();
    00066   long start       = st;
    00067   while(::strncmp(s.c_str()+start,delim,lenDelim)==0) start += lenDelim;
    00068   long posTag      = (lenTagBeg>0) ? s.find(tagBeg, start) + lenTagBeg : start;
    00069   long posDelim    = s.find(delim,posTag) > 0 ? s.find(delim,posTag) : slen;
    00070   long posEq       = s.find(eq, posTag)   > 0 ? s.find(eq, posTag) : posDelim-posTag;
    00071   long lenTag      = (lenTagEnd>0)   ? s.find(tagEnd, posTag)-posTag : (posEq>0) ? (posEq>posTag) ? posEq-posTag : posDelim-posTag : posDelim;
    00072   posEq            = s.find(eq, posTag+lenTag+lenTagEnd)+lenEq;
    00073   long posVal      = (lenValBeg>0)   ? s.find(valBeg, posEq)+lenValBeg : posEq;
    00074   posDelim         = (lenDelim>0)    ? s.find(delim, posVal+lenValBeg) : slen;
    00075   long lenVal      = (lenValEnd>0)   ? s.find(valEnd, posVal)-posVal : ((posDelim>=0) ? posDelim : slen)-posVal;
    00076
    00077   m_tag = m_value  = "";
    00078   // Ooops: Valid tag found:
    00079   if ( start  >= 0 && posTag >= 0 )   {
    00080     m_tag    = s.substr(posTag, lenTag);
    00081     m_length = posTag+m_tag.length()+lenTagEnd-st;
    00082   }
    00083   // Ooops: there is also a value:
    00084   if ( posVal >= 0 && lenVal >= 0 )   {
    00085     m_value  = s.substr(posVal, lenVal);
    00086     m_length = posVal+m_value.length()+lenValEnd-st;
    00087   }
    00088   while(::strncmp(s.c_str()+start+m_length,delim,lenDelim)==0) m_length += lenDelim;
    00089 }
    00090