summaryrefslogtreecommitdiffstats
path: root/game/client/config/gamepad_axis.cc
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-09-11 13:48:31 +0500
committeruntodesu <kirill@untode.su>2025-09-11 13:48:31 +0500
commitaaed751bf4430bf4b9b30cef532b8753b9f639ce (patch)
tree16bc751c272ba27ad53ec48dbdd3a6d9e6a8d4c2 /game/client/config/gamepad_axis.cc
parent96bd73ae020ecca1f94698744c77498a89ad19f7 (diff)
downloadvoxelius-aaed751bf4430bf4b9b30cef532b8753b9f639ce.tar.bz2
voxelius-aaed751bf4430bf4b9b30cef532b8753b9f639ce.zip
Replace most of C strings with string_view
Diffstat (limited to 'game/client/config/gamepad_axis.cc')
-rw-r--r--game/client/config/gamepad_axis.cc19
1 files changed, 10 insertions, 9 deletions
diff --git a/game/client/config/gamepad_axis.cc b/game/client/config/gamepad_axis.cc
index a82de81..8ae74be 100644
--- a/game/client/config/gamepad_axis.cc
+++ b/game/client/config/gamepad_axis.cc
@@ -6,9 +6,9 @@
#include "client/io/gamepad.hh"
-constexpr static const char* UNKNOWN_AXIS_NAME = "UNKNOWN";
+constexpr static std::string_view UNKNOWN_AXIS_NAME = "UNKNOWN";
-static const std::pair<int, const char*> axis_names[] = {
+static const std::pair<int, std::string_view> axis_names[] = {
{ GLFW_GAMEPAD_AXIS_LEFT_X, "LEFT_X" },
{ GLFW_GAMEPAD_AXIS_LEFT_Y, "LEFT_Y" },
{ GLFW_GAMEPAD_AXIS_RIGHT_X, "RIGHT_X" },
@@ -17,7 +17,7 @@ static const std::pair<int, const char*> axis_names[] = {
{ GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, "RIGHT_TRIG" },
};
-static const char* get_axis_name(int axis)
+static std::string_view get_axis_name(int axis)
{
for(const auto& it : axis_names) {
if(it.first != axis) {
@@ -42,19 +42,20 @@ config::GamepadAxis::GamepadAxis(int axis, bool inverted)
m_full_string = std::format("{}:{}", m_name, m_inverted ? 1U : 0U);
}
-const char* config::GamepadAxis::get(void) const
+std::string_view config::GamepadAxis::get(void) const
{
- return m_full_string.c_str();
+ return m_full_string;
}
-void config::GamepadAxis::set(const char* value)
+void config::GamepadAxis::set(std::string_view value)
{
char new_name[64];
unsigned int new_invert;
+ std::string value_str(value);
- if(2 == std::sscanf(value, "%63[^:]:%u", new_name, &new_invert)) {
+ if(2 == std::sscanf(value_str.c_str(), "%63[^:]:%u", new_name, &new_invert)) {
for(const auto& it : axis_names) {
- if(!std::strcmp(it.second, new_name)) {
+ if(0 == it.second.compare(new_name)) {
m_inverted = new_invert;
m_gamepad_axis = it.first;
m_name = get_axis_name(m_gamepad_axis);
@@ -108,7 +109,7 @@ float config::GamepadAxis::get_value(const GLFWgamepadstate& state, float deadzo
return 0.0f;
}
-const char* config::GamepadAxis::get_name(void) const
+std::string_view config::GamepadAxis::get_name(void) const
{
return m_name;
}