Commit 13289c7b authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Various fixes

parent 22ce8e88
......@@ -31,4 +31,5 @@ belcard.kdev4
tests/belcard-tester
tests/belcard-folder
tests/belcard-unfolder
tests/belcard-parser
src/vcard_grammar.cpp
......@@ -109,19 +109,22 @@ namespace belcard {
BelCardProperty::addParam(param);
}
friend ostream &operator<<(ostream &output, const BelCardAddress &addr) {
if (addr.getGroup().length() > 0) {
output << addr.getGroup() << ".";
string serialize() const {
stringstream output;
if (getGroup().length() > 0) {
output << getGroup() << ".";
}
output << addr.getName();
for (auto it = addr.getParams().begin(); it != addr.getParams().end(); ++it) {
output << getName();
for (auto it = getParams().begin(); it != getParams().end(); ++it) {
output << ";" << (**it);
}
output << ":" << addr.getPostOfficeBox() << ";" << addr.getExtendedAddress()
<< ";" << addr.getStreet() << ";" << addr.getLocality() << ";" << addr.getRegion()
<< ";" << addr.getPostalCode() << ";" << addr.getCountry() << "\r\n";
return output;
output << ":" << getPostOfficeBox() << ";" << getExtendedAddress()
<< ";" << getStreet() << ";" << getLocality() << ";" << getRegion()
<< ";" << getPostalCode() << ";" << getCountry() << "\r\n";
return output.str();
}
};
}
......
......@@ -8,8 +8,7 @@
#include <string>
#include <list>
#include <map>
#include <memory>
#include <sstream>
using namespace::std;
using namespace::belr;
......@@ -64,8 +63,14 @@ namespace belcard {
return _value;
}
virtual string serialize() const {
stringstream output;
output << getName() << "=" << getValue();
return output.str();
}
friend ostream &operator<<(ostream &output, const BelCardParam &param) {
output << param.getName() << "=" << param.getValue();
output << param.serialize();
return output;
}
};
......@@ -114,16 +119,24 @@ namespace belcard {
return _params;
}
friend ostream &operator<<(ostream &output, const BelCardProperty &prop) {
if (prop.getGroup().length() > 0) {
output << prop.getGroup() << ".";
virtual string serialize() const {
stringstream output;
if (getGroup().length() > 0) {
output << getGroup() << ".";
}
output << prop.getName();
for (auto it = prop.getParams().begin(); it != prop.getParams().end(); ++it) {
output << getName();
for (auto it = getParams().begin(); it != getParams().end(); ++it) {
output << ";" << (**it);
}
output << ":" << prop.getValue() << "\r\n";
output << ":" << getValue() << "\r\n";
return output.str();
}
friend ostream &operator<<(ostream &output, const BelCardProperty &prop) {
output << prop.serialize();
return output;
}
};
......
......@@ -7,8 +7,7 @@
#include <string>
#include <list>
#include <map>
#include <memory>
#include <sstream>
using namespace::std;
using namespace::belr;
......@@ -123,17 +122,20 @@ namespace belcard {
BelCardProperty::addParam(param);
}
friend ostream &operator<<(ostream &output, const BelCardN &n) {
if (n.getGroup().length() > 0) {
output << n.getGroup() << ".";
string serialize() const {
stringstream output;
if (getGroup().length() > 0) {
output << getGroup() << ".";
}
output << n.getName();
for (auto it = n.getParams().begin(); it != n.getParams().end(); ++it) {
output << getName();
for (auto it = getParams().begin(); it != getParams().end(); ++it) {
output << ";" << (**it);
}
output << ":" << n.getFamilyName() + ";" + n.getGivenName() + ";" + n.getAdditionalName() + ";" + n.getPrefixes() + ";" + n.getSuffixes() << "\r\n";
return output;
output << ":" << getFamilyName() + ";" + getGivenName() + ";" + getAdditionalName() + ";" + getPrefixes() + ";" + getSuffixes() << "\r\n";
return output.str();
}
};
......
#ifndef vcard_grammar_hpp
#define vcard_grammar_hpp
extern unsigned char vcard_grammar[8000];
extern unsigned char vcard_grammar[];
extern unsigned int vcard_grammar_len;
#endif
......@@ -20,6 +20,7 @@ shared_ptr<BelCard> BelCardParser::parse(const string &input) {
BelCard::setHandlerAndCollectors(&parser);
BelCardParam::setHandlerAndCollectors(&parser);
BelCardKind::setHandlerAndCollectors(&parser);
BelCardFN::setHandlerAndCollectors(&parser);
BelCardN::setHandlerAndCollectors(&parser);
BelCardBirthday::setHandlerAndCollectors(&parser);
......@@ -27,6 +28,7 @@ shared_ptr<BelCard> BelCardParser::parse(const string &input) {
BelCardGender::setHandlerAndCollectors(&parser);
BelCardNickname::setHandlerAndCollectors(&parser);
BelCardPhoto::setHandlerAndCollectors(&parser);
BelCardAddress::setHandlerAndCollectors(&parser);
size_t parsedSize = 0;
shared_ptr<BelCardGeneric> ret = parser.parseInput("vcard", vcard, &parsedSize);
......
EXTRA_DIST=vcards/vcard.vcf vcards/unfoldtest.vcf vcards/foldtest.vcf
bin_PROGRAMS=belcard-folder belcard-unfolder
bin_PROGRAMS=belcard-folder belcard-unfolder belcard-parser
if BUILD_TESTS
......@@ -22,4 +22,7 @@ belcard_folder_LDADD=$(top_builddir)/src/libbelcard.la -lbelr
belcard_unfolder_SOURCES=belcard-unfolder.cpp
belcard_unfolder_LDADD=$(top_builddir)/src/libbelcard.la -lbelr
belcard_parser_SOURCES=belcard-parser.cpp
belcard_parser_LDADD=$(top_builddir)/src/libbelcard.la -lbelr
AM_CPPFLAGS=-I$(top_srcdir)/include
#include "belcard/belcard_parser.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
using namespace::belr;
using namespace::belcard;
int main(int argc, char *argv[]) {
const char *file = NULL;
if (argc < 2) {
cerr << argv[0] << " <file to parse> - parse the content of a file" << endl;
return -1;
}
file = argv[1];
ifstream istr(file);
if (!istr.is_open()) {
return -1;
}
stringstream vcardStream;
vcardStream << istr.rdbuf();
string vcard = vcardStream.str();
BelCardParser *parser = new BelCardParser();
shared_ptr<BelCard> belCard = parser->parse(vcard);
cout << *belCard << endl;
delete parser;
return 0;
}
\ No newline at end of file
......@@ -26,6 +26,9 @@ static void folding(void) {
BelCardParser *parser = new BelCardParser();
string folded_vcard = parser->fold(vcard);
string unfolded_vcard = openFile("vcards/unfoldtest.vcf");
BC_ASSERT_EQUAL(unfolded_vcard.compare(folded_vcard), 0, int, "%d");
delete parser;
}
......@@ -34,6 +37,9 @@ static void unfolding(void) {
BelCardParser *parser = new BelCardParser();
string unfolded_vcard = parser->unfold(vcard);
string folded_vcard = openFile("vcards/foldtest.vcf");
BC_ASSERT_EQUAL(folded_vcard.compare(unfolded_vcard), 0, int, "%d");
delete parser;
}
......@@ -42,6 +48,8 @@ static void vcard_parsing(void) {
BelCardParser *parser = new BelCardParser();
shared_ptr<BelCard> belCard = parser->parse(vcard);
//TODO: find a way to check the belCard object
delete parser;
}
......
This diff was suppressed by a .gitattributes entry.
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