Skip to content

Commit

Permalink
Provide handling of empty string after stripping trailing spaces in S…
Browse files Browse the repository at this point in the history
…tringUtilities -- fixes #6
  • Loading branch information
charlestytler committed Apr 17, 2020
1 parent e656b22 commit 15b5cd4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
Binary file modified Release/com.ctytler.dcs.streamDeckPlugin
Binary file not shown.
30 changes: 16 additions & 14 deletions Sources/DcsInterface/StringUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,31 @@
#include <stdlib.h>

bool is_integer(const std::string &str) {
if (str.empty()) {
return false;
} else {
if (!str.empty()) {
// Add special handling for stripping of trailing spaces
const std::string str_trailing_spaces_stripped = str.substr(0, str.find_last_not_of(" ") + 1);
// Check if all characters are base 10 digits (0-9).
char *ptr_to_first_non_numeric_char;
strtol(str_trailing_spaces_stripped.c_str(), &ptr_to_first_non_numeric_char, 10);
return (*ptr_to_first_non_numeric_char == '\0');
if (!str_trailing_spaces_stripped.empty()) {
// Check if all characters are base 10 digits (0-9).
char *ptr_to_first_non_numeric_char;
strtol(str_trailing_spaces_stripped.c_str(), &ptr_to_first_non_numeric_char, 10);
return (*ptr_to_first_non_numeric_char == '\0');
}
}
return false;
}

bool is_number(const std::string &str) {
if (str.empty()) {
return false;
} else {
if (!str.empty()) {
// Add special handling for stripping of trailing spaces
const std::string str_trailing_spaces_stripped = str.substr(0, str.find_last_not_of(" ") + 1);
// Check if all characters can be converted to a floating point number.
char *ptr_to_first_non_numeric_char;
strtof(str_trailing_spaces_stripped.c_str(), &ptr_to_first_non_numeric_char);
return (*ptr_to_first_non_numeric_char == '\0');
if (!str_trailing_spaces_stripped.empty()) {
// Check if all characters can be converted to a floating point number.
char *ptr_to_first_non_numeric_char;
strtof(str_trailing_spaces_stripped.c_str(), &ptr_to_first_non_numeric_char);
return (*ptr_to_first_non_numeric_char == '\0');
}
}
return false;
}

bool pop_key_and_value(std::stringstream &ss,
Expand Down
Binary file modified Sources/com.ctytler.dcs.sdPlugin/dcs_interface.exe
Binary file not shown.

0 comments on commit 15b5cd4

Please sign in to comment.