TorqueScript  0.2
stringhelpers.hpp
1 
15 #pragma once
16 
17 #include <sstream>
18 
19 #include <torquescript/storedvaluestack.hpp>
20 
21 namespace TorqueScript
22 {
23  std::string toLowerCase(const std::string& in);
24  std::string expandEscapeSequences(const std::string& in);
25 
26  static std::string resolveArrayNameFromStack(StoredValueStack& stack, std::shared_ptr<ExecutionState> state, const std::string& base, const std::size_t argumentCount)
27  {
28  std::vector<std::string> variableComponents;
29  for (unsigned int iteration = 0; iteration < argumentCount; ++iteration)
30  {
31  variableComponents.push_back(stack.popString(state));
32  }
33 
34  std::ostringstream out;
35  out << base;
36  for (auto iterator = variableComponents.rbegin(); iterator != variableComponents.rend(); ++iterator)
37  {
38  if (iterator != variableComponents.rbegin())
39  {
40  out << "_";
41  }
42  out << *iterator;
43  }
44 
45  return out.str();
46  }
47 
48  static std::string resolveArrayName(const std::string& base)
49  {
50  return base;
51  }
52 
53  template <typename... parameters>
54  static std::string resolveArrayName(const std::string& base, const int value, parameters... params)
55  {
56  return TorqueScript::resolveArrayName(base + "_" + std::to_string(value), params...);
57  }
58 
59  template <typename... parameters>
60  static std::string resolveArrayName(const std::string& base, const float value, parameters... params)
61  {
62  return TorqueScript::resolveArrayName(base + "_" + std::to_string(value), params...);
63  }
64 
65 }
Definition: ast.hpp:28