mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Message Format
- Relaxed message parsing slightly.
This commit is contained in:
parent
82c4b05fe4
commit
12809fd0bf
2 changed files with 20 additions and 15 deletions
27
src/Msg.cpp
27
src/Msg.cpp
|
@ -145,26 +145,25 @@ bool Msg::parse (const std::string& input)
|
|||
_header.clear ();
|
||||
_payload = "";
|
||||
|
||||
std::vector <std::string> lines;
|
||||
split (lines, input.substr (0, input.size ()), '\n');
|
||||
std::string::size_type separator = input.find ("\n\n");
|
||||
if (separator == std::string::npos)
|
||||
throw std::string ("ERROR: Malformed message");
|
||||
|
||||
// Parse header.
|
||||
std::vector <std::string> lines;
|
||||
split (lines, input.substr (0, separator), '\n');
|
||||
std::vector <std::string>::iterator i;
|
||||
bool tripped = false;
|
||||
for (i = lines.begin (); i != lines.end (); ++i)
|
||||
{
|
||||
if (*i == "")
|
||||
tripped = true;
|
||||
else if (tripped)
|
||||
_payload += *i + "\n";
|
||||
else
|
||||
{
|
||||
std::string::size_type delim = i->find (": ");
|
||||
if (delim != std::string::npos)
|
||||
_header[i->substr (0, delim)] = i->substr (delim + 2);
|
||||
else
|
||||
std::string::size_type delimiter = i->find (':');
|
||||
if (delimiter == std::string::npos)
|
||||
throw std::string ("ERROR: Malformed message header '") + *i + "'";
|
||||
|
||||
_header[trim (i->substr (0, delimiter))] = trim (i->substr (delimiter + 1));
|
||||
}
|
||||
}
|
||||
|
||||
// Parse payload.
|
||||
_payload = input.substr (separator + 2);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue