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

Added tel property

parent 66ada773
......@@ -5,6 +5,7 @@ belcard_include_HEADERS = belcard.hpp \
belcard_general.hpp \
belcard_identification.hpp \
belcard_addressing.hpp \
belcard_communication.hpp \
belcard_parser.hpp \
vcard_grammar.hpp
......
......@@ -5,6 +5,7 @@
#include "belcard_general.hpp"
#include "belcard_identification.hpp"
#include "belcard_addressing.hpp"
#include "belcard_communication.hpp"
#include <string>
#include <list>
......@@ -26,6 +27,7 @@ namespace belcard {
list<shared_ptr<BelCardNickname>> _nicknames;
list<shared_ptr<BelCardPhoto>> _photos;
list<shared_ptr<BelCardAddress>> _addr;
list<shared_ptr<BelCardTel>> _tel;
list<shared_ptr<BelCardProperty>> _properties;
public:
......@@ -43,7 +45,8 @@ namespace belcard {
->setCollector("GENDER", make_sfn(&BelCard::setGender))
->setCollector("NICKNAME", make_sfn(&BelCard::addNickname))
->setCollector("PHOTO", make_sfn(&BelCard::addPhoto))
->setCollector("ADR", make_sfn(&BelCard::addAddress));
->setCollector("ADR", make_sfn(&BelCard::addAddress))
->setCollector("TEL", make_sfn(&BelCard::addTel));
}
BelCard() {
......@@ -122,6 +125,14 @@ namespace belcard {
return _addr;
}
void addTel(const shared_ptr<BelCardTel> &tel) {
_tel.push_back(tel);
addProperty(tel);
}
const list<shared_ptr<BelCardTel>> &getTel() const {
return _tel;
}
void addProperty(const shared_ptr<BelCardProperty> &property) {
_properties.push_back(property);
}
......
......@@ -6,9 +6,7 @@
#include <belr/abnf.hh>
#include <string>
#include <list>
#include <map>
#include <memory>
#include <sstream>
using namespace::std;
using namespace::belr;
......
#ifndef belcard_communication_hpp
#define belcard_communication_hpp
#include "belcard_generic.hpp"
#include <belr/grammarbuilder.hh>
#include <belr/abnf.hh>
#include <string>
#include <sstream>
using namespace::std;
using namespace::belr;
namespace belcard {
class BelCardTel : public BelCardProperty {
public:
static shared_ptr<BelCardTel> create() {
return make_shared<BelCardTel>();
}
static shared_ptr<BelCardTel> parse(const string& input) {
ABNFGrammarBuilder grammar_builder;
shared_ptr<Grammar> grammar = grammar_builder.createFromAbnf((const char*)vcard_grammar, make_shared<CoreRules>());
Parser<shared_ptr<BelCardGeneric>> parser(grammar);
setHandlerAndCollectors(&parser);
BelCardParam::setHandlerAndCollectors(&parser);
shared_ptr<BelCardGeneric> ret = parser.parseInput("TEL", input, NULL);
return dynamic_pointer_cast<BelCardTel>(ret);
}
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
parser->setHandler("TEL", make_fn(&BelCardTel::create))
->setCollector("group", make_sfn(&BelCardTel::setGroup))
->setCollector("any-param", make_sfn(&BelCardTel::addParam))
->setCollector("TEL-value", make_sfn(&BelCardTel::setValue));
}
BelCardTel() : BelCardProperty() {
setName("TEL");
}
virtual void addParam(const shared_ptr<BelCardParam> &param) {
BelCardProperty::addParam(param);
}
};
}
#endif
\ No newline at end of file
......@@ -29,6 +29,7 @@ shared_ptr<BelCard> BelCardParser::parse(const string &input) {
BelCardNickname::setHandlerAndCollectors(&parser);
BelCardPhoto::setHandlerAndCollectors(&parser);
BelCardAddress::setHandlerAndCollectors(&parser);
BelCardTel::setHandlerAndCollectors(&parser);
size_t parsedSize = 0;
shared_ptr<BelCardGeneric> ret = parser.parseInput("vcard", vcard, &parsedSize);
......
......@@ -5,7 +5,7 @@ vcard = "BEGIN:VCARD" CRLF
1*property
"END:VCARD" CRLF
property = KIND / FN / N / NICKNAME / BDAY / ANNIVERSARY / GENDER / PHOTO / ADR
property = KIND / FN / N / NICKNAME / BDAY / ANNIVERSARY / GENDER / PHOTO / ADR / TEL
KIND = [group "."] "KIND" *(";" any-param) ":" KIND-value CRLF
KIND-value = "individual" / "group" / "org" / "location" / iana-token / x-name
......@@ -49,6 +49,9 @@ ADR-locality = component *("," component)
ADR-region = component *("," component)
ADR-code = component *("," component)
ADR-country = component *("," component)
TEL = [group "."] "TEL" *(";" any-param) ":" TEL-value CRLF
TEL-value = URI / text
group = 1*(ALPHA / DIGIT / "-")
......
......@@ -7,6 +7,7 @@ if BUILD_TESTS
noinst_PROGRAMS=belcard-tester
belcard_tester_SOURCES=belcard-tester.cpp belcard-tester.hpp common/bc_tester_utils.c common/bc_tester_utils.h \
belcard-general-tester.cpp belcard-identification-tester.cpp belcard-addressing-tester.cpp \
belcard-communication-tester.cpp \
belcard-vcard-tester.cpp
belcard_tester_LDADD=$(top_builddir)/src/libbelcard.la -lbelr $(CUNIT_LIBS)
......
#include "belcard/belcard_communication.hpp"
#include "common/bc_tester_utils.h"
#include <sstream>
using namespace::std;
using namespace::belcard;
static void tel_property(void) {
string input = "TEL;VALUE=uri;TYPE=work:tel:+33-9-52-63-65-05\r\n";
shared_ptr<BelCardTel> tel = BelCardTel::parse(input);
BC_ASSERT_TRUE_FATAL(tel != NULL);
stringstream sstream;
sstream << *tel;
BC_ASSERT_EQUAL(input.compare(sstream.str()), 0, int, "%d");
}
static test_t tests[] = {
{ "Tel", tel_property },
};
test_suite_t vcard_communication_properties_test_suite = {
"Communication",
NULL,
NULL,
NULL,
NULL,
sizeof(tests) / sizeof(tests[0]),
tests
};
\ No newline at end of file
......@@ -55,6 +55,7 @@ void belcard_tester_init(void(*ftester_printf)(int level, const char *fmt, va_li
bc_tester_add_suite(&vcard_general_properties_test_suite);
bc_tester_add_suite(&vcard_identification_properties_test_suite);
bc_tester_add_suite(&vcard_addressing_properties_test_suite);
bc_tester_add_suite(&vcard_communication_properties_test_suite);
bc_tester_add_suite(&vcard_test_suite);
}
......
......@@ -10,6 +10,7 @@ extern "C" {
extern test_suite_t vcard_identification_properties_test_suite;
extern test_suite_t vcard_general_properties_test_suite;
extern test_suite_t vcard_addressing_properties_test_suite;
extern test_suite_t vcard_communication_properties_test_suite;
extern test_suite_t vcard_test_suite;
void belcard_tester_init(void(*ftester_printf)(int level, const char *fmt, va_list args));
......
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