Skip to content

Commit d669034

Browse files
mrossinektbabej
authored andcommitted
Make case sensitivity of skipPartial optional
1 parent a17aa67 commit d669034

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/Datetime.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ bool Datetime::initializeDayName (Pig& pig)
15051505
std::string token;
15061506
for (int day = 0; day <= 7; ++day) // Deliberate <= so that 'sunday' is either 0 or 7.
15071507
{
1508-
if (pig.skipPartial (dayNames[day % 7], token) &&
1508+
if (pig.skipPartial (dayNames[day % 7], token, true) &&
15091509
token.length () >= static_cast <std::string::size_type> (Datetime::minimumMatchLength))
15101510
{
15111511
auto following = pig.peek ();
@@ -1548,7 +1548,7 @@ bool Datetime::initializeMonthName (Pig& pig)
15481548
std::string token;
15491549
for (int month = 0; month < 12; ++month)
15501550
{
1551-
if (pig.skipPartial (monthNames[month], token) &&
1551+
if (pig.skipPartial (monthNames[month], token, true) &&
15521552
token.length () >= static_cast <std::string::size_type> (Datetime::minimumMatchLength))
15531553
{
15541554
auto following = pig.peek ();

src/Pig.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,15 @@ bool Pig::skipLiteral (const std::string& literal)
103103
}
104104

105105
////////////////////////////////////////////////////////////////////////////////
106-
bool Pig::skipPartial (const std::string& reference, std::string& result)
106+
bool Pig::skipPartial (const std::string& reference, std::string& result,
107+
bool ignore_case)
107108
{
108109
// Walk the common substring.
109110
auto pos = 0;
110111
while (reference[pos] &&
111112
(*_text)[_cursor + pos] &&
112-
reference[pos] == tolower((*_text)[_cursor + pos]))
113+
((reference[pos] == (*_text)[_cursor + pos] && !ignore_case) ||
114+
(reference[pos] == tolower((*_text)[_cursor + pos]) && ignore_case)))
113115
++pos;
114116

115117
if (pos > 0)

src/Pig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Pig
4040
bool skipN (const int quantity = 1);
4141
bool skipWS ();
4242
bool skipLiteral (const std::string&);
43-
bool skipPartial (const std::string&, std::string&);
43+
bool skipPartial (const std::string&, std::string&, bool ignore_case = false);
4444

4545
bool getUntil (int, std::string&);
4646
bool getUntilWS (std::string&);

0 commit comments

Comments
 (0)