Skip to content

Commit e01ba31

Browse files
committed
Changed EBLIF real number value validation code to use a regular expression.
Signed-off-by: Maciej Kurc <[email protected]>
1 parent 3480a0a commit e01ba31

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

vpr/src/base/read_blif.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <unordered_set>
2222
#include <cctype> //std::isdigit
2323
#include <algorithm>
24+
#include <regex>
2425

2526
#include "blifparse.hpp"
2627
#include "atom_netlist.h"
@@ -720,22 +721,15 @@ bool is_binary_param(const std::string& param) {
720721
}
721722

722723
bool is_real_param(const std::string& param) {
723-
const std::string real_chars = "0123456789.";
724724

725725
/* Must be non-empty */
726726
if (param.empty()) {
727727
return false;
728728
}
729729

730-
/* The string mustn't contain any other chars that the expected ones */
731-
for (size_t i = 0; i < param.length(); ++i) {
732-
if (real_chars.find(param[i]) == std::string::npos) {
733-
return false;
734-
}
735-
}
736-
737-
/* There must only be a single dot */
738-
if (std::count(param.begin(), param.end(), '.') != 1) {
730+
/* The string must match the regular expression */
731+
static const std::regex real_number_expr("[+-]?([0-9]*\\.[0-9]+)|([0-9]+\\.[0-9]*)");
732+
if (!std::regex_match(param, real_number_expr)) {
739733
return false;
740734
}
741735

0 commit comments

Comments
 (0)