Commit 8ae3f927 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Improved vCard grammar to authorize unix endlines + authorize as many blank...

Improved vCard grammar to authorize unix endlines + authorize as many blank lines as we want between vcards
parent df2c5131
......@@ -17,15 +17,17 @@
*/
#include "belcard/belcard_utils.hpp"
#include <string.h>
using namespace::std;
string belcard_fold(string input) {
size_t crlf = 0;
size_t next_crlf = 0;
const char *endline = "\r\n";
while (next_crlf != string::npos) {
next_crlf = input.find("\r\n", crlf);
next_crlf = input.find(endline, crlf);
if (next_crlf != string::npos) {
if (next_crlf - crlf > 75) {
input.insert(crlf + 74, "\r\n ");
......@@ -40,16 +42,22 @@ string belcard_fold(string input) {
}
string belcard_unfold(string input) {
size_t crlf = input.find("\r\n");
const char *endline = "\r\n";
size_t crlf = input.find(endline);
if (crlf == string::npos) {
endline = "\n";
crlf = input.find(endline);
}
while (crlf != string::npos) {
if (isspace(input[crlf + 2])) {
input.erase(crlf, 3);
if (isspace(input[crlf + strlen(endline)])) {
input.erase(crlf, strlen(endline) + 1);
} else {
crlf += 2;
crlf += strlen(endline);
}
crlf = input.find("\r\n", crlf);
crlf = input.find(endline, crlf);
}
return input;
......
This diff is collapsed.
......@@ -45,7 +45,11 @@ int main(int argc, char *argv[]) {
shared_ptr<BelCardList> belCards = parser.parseFile(file);
auto t_end_2 = std::chrono::high_resolution_clock::now();
cout << *belCards << endl;
if (belCards) {
cout << *belCards << endl;
} else {
cerr << "Failure: couldn't parse input file " << file << endl;
}
cout << "Parser initialized in " << std::chrono::duration<double, std::milli>(t_end - t_start).count() << " milliseconds" << endl;
cout << "Parsing done in " << std::chrono::duration<double, std::milli>(t_end_2 - t_start_2).count() << " milliseconds" << endl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment