145{
146 std::vector<std::string> argv;
147 argv.insert(argv.begin(), args.begin(), args.end());
148
149 if (argv.size() != 3)
150 {
151 exp.errors.emplace_back(
152 "enumerate error: Expected 3 arguments ${enumerate prefix first_index last_index} in '" +
153 n->fullpath() + "'",
154 n);
155 return n->val();
156 }
157
158 const auto & prefix = argv[0];
159 std::array<int, 2> index;
161 {
162 const auto & arg = argv[i + 1];
163 if (arg.empty() || arg.find_first_not_of("0123456789") != std::string::npos)
164 {
165 exp.errors.emplace_back(
"enumerate error: index '" + arg +
166 "' is not a non-negative integer in '" + n->fullpath() + "'",
167 n);
168 return n->val();
169 }
170 index[i] = MooseUtils::convert<int>(arg);
171 }
172
173 if (index[1] < index[0])
174 {
175 exp.errors.emplace_back(
"enumerate error: last index " + argv[2] +
176 " is smaller than first index " + argv[1] + " in '" +
177 n->fullpath() + "'",
178 n);
179 return n->val();
180 }
181
182 std::vector<std::string> names;
183 for (
const auto i :
make_range(index[0], index[1] + 1))
184 names.push_back(prefix +
std::to_string(i));
185
187}
std::string stringJoin(const std::vector< std::string > &values, const std::string &separator=" ")
Concatenates value into a single string separated by separator.
IntRange< T > make_range(T beg, T end)