aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
Diffstat (limited to 'host')
-rw-r--r--host/include/uhd/rfnoc/constants.hpp6
-rw-r--r--host/lib/rfnoc/block_id.cpp6
-rw-r--r--host/tests/block_id_test.cpp1
3 files changed, 9 insertions, 4 deletions
diff --git a/host/include/uhd/rfnoc/constants.hpp b/host/include/uhd/rfnoc/constants.hpp
index 68833430c..fdcc40d99 100644
--- a/host/include/uhd/rfnoc/constants.hpp
+++ b/host/include/uhd/rfnoc/constants.hpp
@@ -89,7 +89,11 @@ static const size_t MAX_NUM_PORTS = 16;
// Regular expressions
static const std::string VALID_BLOCKNAME_REGEX = "[A-Za-z][A-Za-z0-9_]*";
+static const std::string DEVICE_NUMBER_REGEX = R"-((?:(\d+)/)?)-";
+static const std::string BLOCK_COUNTER_REGEX = R"-((?:#(\d+))?)-";
static const std::string VALID_BLOCKID_REGEX =
- "(?:(\\d+)(?:/))?([A-Za-z][A-Za-z0-9_]*)(?:(?:#)(\\d\\d?))?";
+ DEVICE_NUMBER_REGEX + "(" + VALID_BLOCKNAME_REGEX + ")" + BLOCK_COUNTER_REGEX;
+static const std::string MATCH_BLOCKID_REGEX =
+ DEVICE_NUMBER_REGEX + "(" + VALID_BLOCKNAME_REGEX + ")?" + BLOCK_COUNTER_REGEX;
}} /* namespace uhd::rfnoc */
diff --git a/host/lib/rfnoc/block_id.cpp b/host/lib/rfnoc/block_id.cpp
index 85c8a7e75..da14632b2 100644
--- a/host/lib/rfnoc/block_id.cpp
+++ b/host/lib/rfnoc/block_id.cpp
@@ -42,9 +42,9 @@ bool block_id_t::is_valid_blockname(const std::string& block_name)
return std::regex_match(block_name, std::regex(VALID_BLOCKNAME_REGEX));
}
-bool block_id_t::is_valid_block_id(const std::string& block_name)
+bool block_id_t::is_valid_block_id(const std::string& block_id)
{
- return std::regex_match(block_name, std::regex(VALID_BLOCKID_REGEX));
+ return std::regex_match(block_id, std::regex(VALID_BLOCKID_REGEX));
}
std::string block_id_t::to_string() const
@@ -66,7 +66,7 @@ bool block_id_t::match(const std::string& block_str)
{
std::cmatch matches;
if (not std::regex_match(
- block_str.c_str(), matches, std::regex(VALID_BLOCKID_REGEX))) {
+ block_str.c_str(), matches, std::regex(MATCH_BLOCKID_REGEX))) {
return false;
}
try {
diff --git a/host/tests/block_id_test.cpp b/host/tests/block_id_test.cpp
index 11c9d7123..cf819300a 100644
--- a/host/tests/block_id_test.cpp
+++ b/host/tests/block_id_test.cpp
@@ -29,6 +29,7 @@ BOOST_AUTO_TEST_CASE(test_block_id)
BOOST_CHECK(block_id_t::is_valid_block_id("0/Filter_Foo#1"));
BOOST_CHECK(not block_id_t::is_valid_block_id("x/FilterFoo#1"));
BOOST_CHECK(not block_id_t::is_valid_block_id("0/FilterFoo#x"));
+ BOOST_CHECK(not block_id_t::is_valid_block_id("0/#1"));
BOOST_REQUIRE_THROW(block_id_t invalid_block_id("0Filter/1"), uhd::value_error);