Skip to content

Commit

Permalink
Made more use of std::isalnum and std::isalpha (std::locale versions)
Browse files Browse the repository at this point in the history
I didn't also deploy std::isdigit since @jyrkive said he feels digit comparison is fast
and simple enough.
  • Loading branch information
Vultraz committed Feb 2, 2018
1 parent 2598497 commit 69f5d9c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/config.cpp
Expand Up @@ -202,9 +202,7 @@ bool config::valid_attribute(config_key_type name)
}

for(char c : name) {
if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_') {
// valid character.
} else {
if(!std::isalnum(c, std::locale::classic()) && c != '_') {
return false;
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/formula/tokenizer.cpp
Expand Up @@ -12,10 +12,11 @@
See the COPYING file for more details.
*/

#include <sstream>

#include "formula/tokenizer.hpp"

#include <locale>
#include <sstream>

namespace wfl
{
namespace tokenizer
Expand Down Expand Up @@ -48,7 +49,7 @@ token get_token(iterator& i1, const iterator i2) {
// check if we parse now TOKEN_IDENTIFIER or TOKEN_OPERATOR/KEYWORD based on string
if( *i1 <= 'Z' || ( *i1 >= 'a' && *it <= 'z' ) || *i1 == '_' ) {

while( i1 != i2 && ( ( *i1 >= 'a' && *i1 <= 'z' ) || *i1 == '_' || ( *i1 >= 'A' && *i1 <= 'Z' ) ) )
while(i1 != i2 && (std::isalpha(*i1, std::locale::classic()) || *i1 == '_'))
++i1;

int diff = i1 - it;
Expand Down
9 changes: 3 additions & 6 deletions src/units/types.cpp
Expand Up @@ -34,6 +34,8 @@

#include <boost/regex.hpp>

#include <locale>

static lg::log_domain log_config("config");
#define ERR_CF LOG_STREAM(err, log_config)
#define WRN_CF LOG_STREAM(warn, log_config)
Expand Down Expand Up @@ -1434,12 +1436,7 @@ void unit_type::check_id(std::string& id)

for(size_t pos = 0; pos < id.size(); ++pos) {
const char c = id[pos];
const bool valid =
c == '_' ||
c == ' ' ||
(c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9');
const bool valid = std::isalnum(c, std::locale::classic()) || c == '_' || c == ' ';

if(!valid) {
if(!gave_warning) {
Expand Down
3 changes: 2 additions & 1 deletion src/version.cpp
Expand Up @@ -18,6 +18,7 @@

#include <cassert>
#include <functional>
#include <locale>

#include <boost/algorithm/string.hpp>

Expand Down Expand Up @@ -58,7 +59,7 @@ version_info::version_info(const std::string& str)
const std::string right_side = v.substr(breakpoint_pos);
assert(right_side.empty() == false);

if((right_side[0] >= 'A' && right_side[0] <= 'Z') || (right_side[0] >= 'a' && right_side[0] <= 'z')) {
if(std::isalpha(right_side[0], std::locale::classic())) {
special_separator_ = '\0';
special_ = right_side;
}
Expand Down

0 comments on commit 69f5d9c

Please sign in to comment.