Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
VarExpander.h
1 /*
2  * VarExpander class interface
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2019, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef ELM_IO_VAREXPANDER_H_
22 #define ELM_IO_VAREXPANDER_H_
23 
24 #include <elm/string.h>
25 #include <elm/io/OutStream.h>
26 #include <elm/avl/Map.h>
27 
28 namespace elm { namespace io {
29 
30 class VarExpander: public OutStream {
31 public:
32  VarExpander();
34  inline char escape() const { return esc; }
35  inline VarExpander& escape(char e) { esc = e; return *this; }
36  inline VarExpander& resetBrace() { open = ""; close = ""; return *this; }
37  inline VarExpander& brace(char o, char c)
38  { open = open + o; close = close + c; return *this; }
39  string expand(string s);
40 
41  // OutStream overload
42  int write(const char *buffer, int size) override;
43  int write(char byte) override;
44  int flush(void) override;
45  CString lastErrorMessage(void) override;
46  bool supportsANSI() const override;
47 
48 protected:
49  virtual string resolve(string name, bool& record);
50 
51 private:
52  char esc;
53  string open, close;
55  enum {
56  COPY,
57  ESC,
58  OPEN,
59  } state;
60  char expected;
61  StringBuffer name;
62  OutStream *_out;
63 };
64 
65 class OSExpander: public VarExpander {
66 protected:
67  string resolve(string name, bool& record) override;
68 };
69 
70 string expandOSVars(string t);
71 
72 } } // elm::io
73 
74 #endif /* ELM_IO_VAREXPANDER_H_ */
elm::io::VarExpander::lastErrorMessage
CString lastErrorMessage(void) override
Definition: io_VarExpander.cpp:198
elm::avl::Map
Definition: Map.h:33
elm::io::VarExpander::supportsANSI
bool supportsANSI() const override
Definition: io_VarExpander.cpp:203
elm::StringBuffer
Definition: StringBuffer.h:18
elm::io::out
sys::SystemOutStream & out
Definition: system_SystemIO.cpp:122
elm::io::VarExpander::expand
string expand(string s)
Definition: io_VarExpander.cpp:111
elm::CString
Definition: CString.h:17
elm::io::OSExpander::resolve
string resolve(string name, bool &record) override
Definition: io_VarExpander.cpp:226
elm::io::expandOSVars
string expandOSVars(string t)
Definition: io_VarExpander.cpp:237
elm::io::VarExpander::flush
int flush(void) override
Definition: io_VarExpander.cpp:193
elm::io::VarExpander::escape
char escape() const
Definition: VarExpander.h:34
elm::io::VarExpander::VarExpander
VarExpander()
Definition: io_VarExpander.cpp:66
elm
Definition: adapter.h:26
elm::io::VarExpander::resetBrace
VarExpander & resetBrace()
Definition: VarExpander.h:36
elm::io::VarExpander::write
int write(const char *buffer, int size) override
Definition: io_VarExpander.cpp:122
elm::t::size
uint64 size
Definition: arch.h:35
elm::io::OutStream
Definition: OutStream.h:30
elm::io::VarExpander::brace
VarExpander & brace(char o, char c)
Definition: VarExpander.h:37
elm::io::VarExpander::resolve
virtual string resolve(string name, bool &record)
Definition: io_VarExpander.cpp:214
elm::io::VarExpander::escape
VarExpander & escape(char e)
Definition: VarExpander.h:35
elm::io::VarExpander
Definition: VarExpander.h:30
elm::io::OSExpander
Definition: VarExpander.h:65