Skip to content

Commit a3a3d0d

Browse files
Simplify config pair parser using StringRef::split
1 parent 4b273cd commit a3a3d0d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

offload/unittests/Conformance/include/mathtest/CommandLine.hpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,19 @@ template <> class parser<TestConfigsArg> : public basic_parser<TestConfigsArg> {
6363
Val.Explicit.clear();
6464

6565
for (StringRef Pair : Pairs) {
66-
size_t Pos = Pair.find(':');
67-
if (Pos == StringRef::npos)
66+
llvm::SmallVector<StringRef, 2> Parts;
67+
Pair.split(Parts, ':');
68+
69+
if (Parts.size() != 2)
6870
return O.error("Expected '<provider>:<platform>', got '" + Pair + "'");
6971

70-
StringRef Provider = Pair.take_front(Pos);
71-
StringRef Platform = Pair.drop_front(Pos + 1);
72+
StringRef Provider = Parts[0].trim();
73+
StringRef Platform = Parts[1].trim();
74+
75+
if (Provider.empty() || Platform.empty())
76+
return O.error("Provider and platform must not be empty in '" + Pair +
77+
"'");
78+
7279
mathtest::TestConfig Config = {Provider.str(), Platform.str()};
7380
if (!isAllowed(Config))
7481
return O.error("Invalid pair '" + Pair + "'");

0 commit comments

Comments
 (0)