From 52b8287da1b51e6afff987ce965f329f7c15f2bc Mon Sep 17 00:00:00 2001 From: Huang-Ming Huang Date: Tue, 25 Aug 2020 17:13:05 -0500 Subject: [PATCH] move is_string_valid_name to cpp file --- libraries/chain/include/eosio/chain/name.hpp | 26 +------------------- libraries/chain/name.cpp | 26 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/libraries/chain/include/eosio/chain/name.hpp b/libraries/chain/include/eosio/chain/name.hpp index 0ce983c7307..5ed13d99db3 100644 --- a/libraries/chain/include/eosio/chain/name.hpp +++ b/libraries/chain/include/eosio/chain/name.hpp @@ -30,31 +30,7 @@ namespace eosio::chain { } // true if std::string can be converted to name - static bool is_string_valid_name(std::string_view str) - { - size_t slen = str.size(); - if( slen > 13) - return false; - - size_t len = (slen <= 12) ? slen : 12; - for( size_t i = 0; i < len; ++i ) { - char c = str[i]; - if ((c >= 'a' && c <= 'z') || (c >= '1' && c <= '5') || (c == '.')) - continue; - else - return false; - } - - if( slen == 13) { - char c = str[12]; - if ((c >= 'a' && c <= 'j') || (c >= '1' && c <= '5') || (c == '.')) - return true; - else - return false; - } - - return true; - } + bool is_string_valid_name(std::string_view str); static constexpr uint64_t string_to_uint64_t( std::string_view str ) { EOS_ASSERT(str.size() <= 13, name_type_exception, "Name is longer than 13 characters (${name}) ", ("name", std::string(str))); diff --git a/libraries/chain/name.cpp b/libraries/chain/name.cpp index bc52e83f4e6..6d35b562e6d 100644 --- a/libraries/chain/name.cpp +++ b/libraries/chain/name.cpp @@ -25,6 +25,32 @@ namespace eosio::chain { return str; } + bool is_string_valid_name(std::string_view str) + { + size_t slen = str.size(); + if( slen > 13) + return false; + + size_t len = (slen <= 12) ? slen : 12; + for( size_t i = 0; i < len; ++i ) { + char c = str[i]; + if ((c >= 'a' && c <= 'z') || (c >= '1' && c <= '5') || (c == '.')) + continue; + else + return false; + } + + if( slen == 13) { + char c = str[12]; + if ((c >= 'a' && c <= 'j') || (c >= '1' && c <= '5') || (c == '.')) + return true; + else + return false; + } + + return true; + } + } // eosio::chain namespace fc {