Skip to content

Commit

Permalink
feat: make conversion case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
bpapaspyros committed Oct 16, 2024
1 parent ccb64d9 commit 4a9cc3c
Showing 1 changed file with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -601,39 +601,41 @@ inline void swap(CartesianState& state1, CartesianState& state2) {
}

/**
* @brief Convert a string to a CartesianStateVariable enum
* @brief Convert a string to a CartesianStateVariable enum (case insensitive)
* @throws exceptions::InvalidStateException
* @param variable The string to convert
* @return A CartesianStateVariable enum corresponding to the input string
*/
inline state_representation::CartesianStateVariable string_to_cartesian_state_variable(const std::string& variable) {
if (variable == "position") {
std::string case_insensitive_variable;
std::transform(variable.begin(), variable.end(), std::back_inserter(case_insensitive_variable), [](unsigned char c) { return std::tolower(c); });
if (case_insensitive_variable == "position") {
return CartesianStateVariable::POSITION;
} else if (variable == "orientation") {
} else if (case_insensitive_variable == "orientation") {
return CartesianStateVariable::ORIENTATION;
} else if (variable == "pose") {
} else if (case_insensitive_variable == "pose") {
return CartesianStateVariable::POSE;
} else if (variable == "linear_velocity") {
} else if (case_insensitive_variable == "linear_velocity") {
return CartesianStateVariable::LINEAR_VELOCITY;
} else if (variable == "angular_velocity") {
} else if (case_insensitive_variable == "angular_velocity") {
return CartesianStateVariable::ANGULAR_VELOCITY;
} else if (variable == "twist") {
} else if (case_insensitive_variable == "twist") {
return CartesianStateVariable::TWIST;
} else if (variable == "linear_acceleration") {
} else if (case_insensitive_variable == "linear_acceleration") {
return CartesianStateVariable::LINEAR_ACCELERATION;
} else if (variable == "angular_acceleration") {
} else if (case_insensitive_variable == "angular_acceleration") {
return CartesianStateVariable::ANGULAR_ACCELERATION;
} else if (variable == "acceleration") {
} else if (case_insensitive_variable == "acceleration") {
return CartesianStateVariable::ACCELERATION;
} else if (variable == "force") {
} else if (case_insensitive_variable == "force") {
return CartesianStateVariable::FORCE;
} else if (variable == "torque") {
} else if (case_insensitive_variable == "torque") {
return CartesianStateVariable::TORQUE;
} else if (variable == "twist") {
} else if (case_insensitive_variable == "twist") {
return CartesianStateVariable::TWIST;
} else if (variable == "wrench") {
} else if (case_insensitive_variable == "wrench") {
return CartesianStateVariable::WRENCH;
} else if (variable == "all") {
} else if (case_insensitive_variable == "all") {
return CartesianStateVariable::ALL;
} else {
throw exceptions::InvalidStateException("Invalid Cartesian state variable: " + variable);
Expand Down

0 comments on commit 4a9cc3c

Please sign in to comment.