Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KviCString::getToken(): add option to skip empty elements (default off) #2574

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/kvilib/core/KviCString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2657,7 +2657,7 @@ KviCString & KviCString::stripLeft(char c)
return (*this);
}

bool KviCString::getToken(KviCString & str, char sep)
bool KviCString::getToken(KviCString & str, char sep, bool skipEmpty)
{
KVI_ASSERT(str.m_ptr);
KVI_ASSERT(str.m_ptr != m_ptr);
Expand All @@ -2673,7 +2673,11 @@ bool KviCString::getToken(KviCString & str, char sep)
KviMemory::copy(str.m_ptr, m_ptr, str.m_len);
*(str.m_ptr + str.m_len) = '\0';
while(*p && (*p == sep))
{
p++;
if(!skipEmpty)
break;
}
cutLeft(p - m_ptr);
return (m_len != 0);
}
Expand All @@ -2700,14 +2704,18 @@ bool KviCString::getLine(KviCString & str)
return true;
}

KviCString KviCString::getToken(char sep)
KviCString KviCString::getToken(char sep, bool skipEmpty)
{
char * p = m_ptr;
while(*p && (*p != sep))
p++;
KviCString ret(m_ptr, p);
while(*p && (*p == sep))
{
p++;
if(!skipEmpty)
break;
}
cutLeft(p - m_ptr);
return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions src/kvilib/core/KviCString.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,10 @@ class KVILIB_API KviCString : public KviHeapObject
// and returns true if there are more tokens to extract<br>
// Does not strip initial separators!!<br>
// str can NOT be this string.
bool getToken(KviCString & str, char sep);
bool getToken(KviCString & str, char sep, bool skipEmpty = false);
// Does not strip initial separators!<br>
// Can assign also to this string.
KviCString getToken(char sep);
KviCString getToken(char sep, bool skipEmpty = false);
// Extracts a line from the string.<br>
// Returns false if there was no data to extract
bool getLine(KviCString & str);
Expand Down
2 changes: 1 addition & 1 deletion src/kvirc/sparser/KviIrcServerParser_numericHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ void KviIrcServerParser::parseNumericWhoReply(KviIrcMessage * msg)
bool bIrcOp = szFlag.indexOf('*') != -1;

KviCString trailing = msg->safeTrailing();
KviCString hops = trailing.getToken(' ');
KviCString hops = trailing.getToken(' ', true);
bool bHopsOk = false;
int iHops = hops.toInt(&bHopsOk);

Expand Down