Skip to content

Commit a193149

Browse files
committed
Fixed the regex to extract the application name.
1 parent 4202251 commit a193149

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

include/cppcommandline.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,11 @@ class Parser
454454
{
455455
mCommand = argv[0];
456456
std::cmatch m;
457-
if(std::regex_match(mCommand.c_str(), m, std::regex("([^\\\\\\/]+$)")))
457+
if(std::regex_search(mCommand.c_str(), m, std::regex("[^\\\\\\/]+$")))
458458
{
459-
mAppName = m[1];
459+
mAppName = m[0];
460460

461-
if(std::regex_match(mAppName.c_str(), std::regex("\\.exe$")))
461+
if(std::regex_search(mAppName.c_str(), std::regex("\\.exe$")))
462462
mAppName.erase(mAppName.size() - 4, 4);
463463
}
464464
}

test/cppcommandlinetest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ void CppCommandLineTest::parse()
286286
QCOMPARE(value, std::string("value"));
287287
QCOMPARE(iValue, -10);
288288
QCOMPARE(dValue, 5.5);
289+
QCOMPARE(parser.command(), std::string("./app"));
290+
QCOMPARE(parser.applicationName(), std::string("app"));
289291
}
290292

291293
{

0 commit comments

Comments
 (0)