| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Tokenizer.cpp
Go to the documentation of this file.
1 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/src/Lib/Tokenizer.cpp,v 1.4 2008/10/27 16:41:33 marcocle Exp $
2 //==============================================================================
3 // Tokenizer.h
4 //------------------------------------------------------------------------------
5 //
6 // Package : Kernel
7 // The LHCb definition package
8 //
9 // Author : M.Frank
10 //
11 // Changes : M.Frank , 01/10/00: Initiali version
12 //
13 //==============================================================================
14 #define KERNEL_TOKENIZER_CPP
15 #include "GaudiKernel/Tokenizer.h"
16 #include "GaudiKernel/Environment.h"
17
18 #include <cstring>
19
20 // Assignment operator
21 Tokenizer::Token& Tokenizer::Token::operator=(const Token& copy) {
22 m_length=copy.m_length;
23 m_tag=copy.m_tag;
24 m_value=copy.m_value;
25 return *this;
26 }
27
28 // Resolve value from environment
29 void Tokenizer::Token::resolveValue() {
30 std::string res;
31 if ( System::resolveEnv(m_value, res).isSuccess() ) {
32 m_value = res;
33 }
34 }
35
36 // Create tokens from string
37 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 m_tokens.clear();
39 if ( valEnd == 0 ) valEnd = valBegin;
40 long start = 0;
41 Token tok;
42 do {
43 tok.make(s, start, delim, tagBegin, tagEnd, eq, valBegin, valEnd);
44 if ( tok.length() > 0 ) {
45 start += tok.length();
46 m_tokens.push_back(tok);
47 }
48 else {
49 start += s.length();
50 }
51 } while ( start < long(s.length()) );
52 if ( m_resolve ) {
53 for(Items::iterator i=m_tokens.begin(); i != m_tokens.end(); ++i) {
54 (*i).resolveValue();
55 }
56 }
57 }
58
59 // Create token from string
60 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) {
61 long lenTagBeg = ::strlen(tagBeg);
62 long lenTagEnd = ::strlen(tagEnd);
63 long lenValBeg = ::strlen(valBeg);
64 long lenValEnd = ::strlen(valEnd);
65 long lenDelim = ::strlen(delim);
66 long lenEq = ::strlen(eq);
67 long slen = s.length();
68 long start = st;
69 while(::strncmp(s.c_str()+start,delim,lenDelim)==0) start += lenDelim;
70 long posTag = (lenTagBeg>0) ? s.find(tagBeg, start) + lenTagBeg : start;
71 long posDelim = s.find(delim,posTag) > 0 ? s.find(delim,posTag) : slen;
72 long posEq = s.find(eq, posTag) > 0 ? s.find(eq, posTag) : posDelim-posTag;
73 long lenTag = (lenTagEnd>0) ? s.find(tagEnd, posTag)-posTag : (posEq>0) ? (posEq>posTag) ? posEq-posTag : posDelim-posTag : posDelim;
74 posEq = s.find(eq, posTag+lenTag+lenTagEnd)+lenEq;
75 long posVal = (lenValBeg>0) ? s.find(valBeg, posEq)+lenValBeg : posEq;
76 posDelim = (lenDelim>0) ? s.find(delim, posVal+lenValBeg) : slen;
77 long lenVal = (lenValEnd>0) ? s.find(valEnd, posVal)-posVal : ((posDelim>=0) ? posDelim : slen)-posVal;
78
79 m_tag = m_value = "";
80 // Ooops: Valid tag found:
81 if ( start >= 0 && posTag >= 0 ) {
82 m_tag = s.substr(posTag, lenTag);
83 m_length = posTag+m_tag.length()+lenTagEnd-st;
84 }
85 // Ooops: there is also a value:
86 if ( posVal >= 0 && lenVal >= 0 ) {
87 m_value = s.substr(posVal, lenVal);
88 m_length = posVal+m_value.length()+lenValEnd-st;
89 }
90 while(::strncmp(s.c_str()+start+m_length,delim,lenDelim)==0) m_length += lenDelim;
91 }
92