13 #define KERNEL_TOKENIZER_CPP
14 #include "GaudiKernel/Tokenizer.h"
15 #include "GaudiKernel/Environment.h"
36 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) {
38 if ( valEnd == 0 ) valEnd = valBegin;
42 tok.
make(s, start, delim, tagBegin, tagEnd, eq, valBegin, valEnd);
50 }
while ( start <
long(s.length()) );
59 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) {
60 long lenTagBeg = ::strlen(tagBeg);
61 long lenTagEnd = ::strlen(tagEnd);
62 long lenValBeg = ::strlen(valBeg);
63 long lenValEnd = ::strlen(valEnd);
64 long lenDelim = ::strlen(delim);
65 long lenEq = ::strlen(eq);
66 long slen = s.length();
68 while(::strncmp(s.c_str()+
start,delim,lenDelim)==0) start += lenDelim;
69 long posTag = (lenTagBeg>0) ? s.find(tagBeg, start) + lenTagBeg :
start;
70 long posDelim = s.find(delim,posTag) > 0 ? s.find(delim,posTag) : slen;
71 long posEq = s.find(eq, posTag) > 0 ? s.find(eq, posTag) : posDelim-posTag;
72 long lenTag = (lenTagEnd>0) ? s.find(tagEnd, posTag)-posTag : (posEq>0) ? (posEq>posTag) ? posEq-posTag : posDelim-posTag : posDelim;
73 posEq = s.find(eq, posTag+lenTag+lenTagEnd)+lenEq;
74 long posVal = (lenValBeg>0) ? s.find(valBeg, posEq)+lenValBeg : posEq;
75 posDelim = (lenDelim>0) ? s.find(delim, posVal+lenValBeg) : slen;
76 long lenVal = (lenValEnd>0) ? s.find(valEnd, posVal)-posVal : ((posDelim>=0) ? posDelim : slen)-posVal;
80 if ( start >= 0 && posTag >= 0 ) {
81 m_tag = s.substr(posTag, lenTag);
82 m_length = posTag+m_tag.length()+lenTagEnd-st;
85 if ( posVal >= 0 && lenVal >= 0 ) {
86 m_value = s.substr(posVal, lenVal);
87 m_length = posVal+m_value.length()+lenValEnd-st;
90 if (start + m_length >=
long(s.size())) {
94 while(::strncmp(s.c_str()+start+m_length,delim,lenDelim)==0) {
96 if (start + m_length >=
long(s.size())) {
Token & operator=(const Token ©)
Assignment operator.
std::string m_value
Value variable.
void resolveValue()
Resolve value from environment.
Definition of the sub-class Token.
long length() const
Total token length.
void analyse(const std::string &s, const char *delim, const char *tagBegin, const char *tagEnd, const char *eq, const char *valBegin, const char *valEnd)
Analyse tokens from string.
bool m_resolve
Flag to resolve environment.
void make(const std::string &s, long st, const char *delim, const char *tagBegin, const char *tagEnd, const char *eq, const char *valBegin, const char *valEnd)
Create token from string.
Items m_tokens
Assigned tokens within string.
long m_length
Toke length.
std::string m_tag
Tag variable.
GAUDI_API StatusCode resolveEnv(const std::string &var, std::string &res, int recusions=124)