3 #include "StringFollower.h"
5 #include "misc/String.h"
11 std::string
StringFollower::follow(std::string path
) {
12 std::stringstream stream
;
17 while(stream
>> token
) {
18 if(token
[0] == '[') { /* list element */
19 if(token
[token
.length()-1] != ']') {
20 throw StringFollowerInvalidPathException("Expected terminating ']' at end of token");
23 Misc::String::to
<int>(token
.substr(1, token
.length()-2), number
);
25 data
= data
.to
<ParseList
>()->get_element(number
);
27 else if(token
[0] == '\'') { /* tuple element */
28 if(token
[token
.length()-1] != '\'') {
29 throw StringFollowerInvalidPathException("Expected terminating \' at end of token");
31 std::string key
= token
.substr(1, token
.length()-2);
32 data
= data
.to
<ParseTuple
>()->get_element(key
);
34 else if(token
[0] == '\"') { /* tuple element */
35 if(token
[token
.length()-1] != '\"') {
36 throw StringFollowerInvalidPathException("Expected terminating \" at end of token");
38 std::string key
= token
.substr(1, token
.length()-2);
39 data
= data
.to
<ParseTuple
>()->get_element(key
);
41 else if(token
== "lhs") { /* left side of a result */
42 data
= new ParseString(data
.to
<ParseResult
>()->get_name());
44 else if(token
== "rhs") { /* right side of a result */
45 Misc::SmartPointer
<ParseResult
> result
= data
.to
<ParseResult
>();
46 data
= result
->get_value();
49 if(!data
.is_valid()) throw StringFollowerException("NULL value in StringFollower resolution");
52 return data
.to
<ParseString
>()->get_data();
56 } // namespace Interface
57 } // namespace Aesalon