Skip to content

Commit 9752d01

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

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

vpr/src/base/read_blif.cpp

Lines changed: 4 additions & 11 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,14 @@ 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.";
724-
725724
/* Must be non-empty */
726725
if (param.empty()) {
727726
return false;
728727
}
729728

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) {
729+
/* The string must match the regular expression */
730+
static const std::regex real_number_expr("[+-]?([0-9]*\\.[0-9]+)|([0-9]+\\.[0-9]*)");
731+
if (!std::regex_match(param, real_number_expr)) {
739732
return false;
740733
}
741734

0 commit comments

Comments
 (0)