diff --git a/src/nt/ntutils.cpp b/src/nt/ntutils.cpp index 5e244af..858163a 100644 --- a/src/nt/ntutils.cpp +++ b/src/nt/ntutils.cpp @@ -14,12 +14,15 @@ namespace epics { namespace nt { bool NTUtils::is_a(const std::string &u1, const std::string &u2) { - // remove minor for the u2 - size_t pos = u2.find_last_of('.'); - std::string su2 = (pos == string::npos) ? u2 : u2.substr(0, pos); + // remove minor for the u1 + size_t pos1 = u1.find_last_of('.'); + std::string su1 = (pos1 == string::npos) ? u1 : u1.substr(0, pos1); - // "starts with comparison" - return su2.size() <= u1.size() && u1.compare(0, su2.size(), su2) == 0; + // remove minor for the u2 + size_t pos2 = u2.find_last_of('.'); + std::string su2 = (pos2 == string::npos) ? u2 : u2.substr(0, pos2); + + return su2 == su1; } }} diff --git a/test/nt/ntutilsTest.cpp b/test/nt/ntutilsTest.cpp index cc57ddc..30ef656 100644 --- a/test/nt/ntutilsTest.cpp +++ b/test/nt/ntutilsTest.cpp @@ -24,11 +24,13 @@ void test_is_a() testOk1(!NTUtils::is_a("epics:nt/NTTable:1.0", "epics:nt/NTTable:2.0")); testOk1(!NTUtils::is_a("epics:nt/NTTable:2.0", "epics:nt/NTTable:1.0")); testOk1(!NTUtils::is_a("epics:nt/NTTable:1.3", "epics:nt/NTTable:2.3")); + testOk1(!NTUtils::is_a("epics:nt/NTTable:1.0", "epics:nt/NTTable:11.0")); + testOk1(!NTUtils::is_a("epics:nt/NTTable:11.0", "epics:nt/NTTable:1.0")); testOk1(!NTUtils::is_a("epics:nt/NTTable:1.0", "epics:nt/NTMatrix:1.0")); } MAIN(testNTUtils) { - testPlan(8); + testPlan(10); test_is_a(); return testDone(); }