Commit b2b31336 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Added method to parse vcards from a file instead of a buffer + fixed issue in grammar

parent 06e445f4
......@@ -23,6 +23,7 @@ namespace belcard {
shared_ptr<BelCard> parseOne(const string &input);
shared_ptr<BelCardList> parse(const string &input);
shared_ptr<BelCardList> parseFile(const string &filename);
};
}
......
......@@ -2,6 +2,10 @@
#include "belcard/belcard.hpp"
#include "belcard/belcard_utils.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
using namespace::std;
using namespace::belr;
using namespace::belcard;
......@@ -87,4 +91,20 @@ shared_ptr<BelCardList> BelCardParser::parse(const string &input) {
shared_ptr<BelCardGeneric> ret = _parse(vcards, "vcard-list");
shared_ptr<BelCardList> belCards = dynamic_pointer_cast<BelCardList>(ret);
return belCards;
}
shared_ptr<BelCardList> BelCardParser::parseFile(const string &filename) {
ifstream istr(filename);
if (!istr.is_open()) {
return NULL;
}
stringstream vcardStream;
vcardStream << istr.rdbuf();
string vcard = vcardStream.str();
string vcards = belcard_unfold(vcard);
shared_ptr<BelCardGeneric> ret = _parse(vcards, "vcard-list");
shared_ptr<BelCardList> belCards = dynamic_pointer_cast<BelCardList>(ret);
return belCards;
}
\ No newline at end of file
......@@ -105,7 +105,7 @@ EMAIL-value = text
IMPP = [group "."] "IMPP" *(";" IMPP-param) ":" IMPP-value CRLF
IMPP-param = VALUE-param / PID-param / PREF-param / TYPE-param / MEDIATYPE-param / ALTID-param / any-param
IMPP-value = text
IMPP-value = URI
LANG = [group "."] "LANG" *(";" LANG-param) ":" LANG-value CRLF
LANG-param = VALUE-param / PID-param / PREF-param / ALTID-param / TYPE-param / any-param
......
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