| 1112 | // args ::= "(" [ expr ( "," expr )* ")" |
| 1113 | |
| 1114 | data_ptr ExprParser::get_var_value(const std::string &path, data_list ¶ms) |
| 1115 | { |
| 1116 | // Check if this is a pseudo function. |
| 1117 | bool is_fn = false; |
| 1118 | if (path == "count" || path == "empty" || path == "defined" || path == "addIndent" || path == "int" || |
| 1119 | path == "str" || path == "upper" || path == "lower" || path == "capitalize" || path == "dump") |
| 1120 | { |
| 1121 | is_fn = true; |
| 1122 | } |
| 1123 | |
| 1124 | try |
| 1125 | { |
| 1126 | data_ptr result; |
| 1127 | if (is_fn) |
| 1128 | { |
| 1129 | if (params.size() != 1 && path != "addIndent") |
| 1130 | { |
| 1131 | throw TemplateException("function " + path + " requires 1 parameter"); |
| 1132 | } |
| 1133 | else if (params.size() != 2 && path == "addIndent") |
| 1134 | { |
| 1135 | throw TemplateException("function " + path + " requires 2 parameters"); |
| 1136 | } |
| 1137 | |
| 1138 | if (path == "count") |
| 1139 | { |
| 1140 | result = params[0]->getlist().size(); |
| 1141 | } |
| 1142 | else if (path == "empty") |
| 1143 | { |
| 1144 | result = params[0]->empty(); |
| 1145 | } |
| 1146 | else if (path == "defined") |
| 1147 | { |
| 1148 | // TODO: handle undefined case for defined fn |
| 1149 | result = true; |
| 1150 | } |
| 1151 | else if (path == "addIndent") |
| 1152 | { |
| 1153 | std::stringstream ss(params[1]->getvalue()); |
| 1154 | if (!ss.eof()) |
| 1155 | { |
| 1156 | std::string line; |
| 1157 | std::string resultValue; |
| 1158 | int c = 0; |
| 1159 | while (std::getline(ss, line)) |
| 1160 | { |
| 1161 | ++c; |
| 1162 | if (c > 1) |
| 1163 | { |
| 1164 | resultValue += '\n'; |
| 1165 | } |
| 1166 | if (line.size() > 0 && line[0] != '\r' && line[0] != '\n') |
| 1167 | { |
| 1168 | resultValue += params[0]->getvalue() + line; |
| 1169 | } |
| 1170 | } |
| 1171 | result = resultValue; |