Commit 259a222f authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Fix fold method + added photo property

parent c9a6f20e
......@@ -20,6 +20,7 @@ namespace belcard {
shared_ptr<BelCardAnniversary> _anniversary;
shared_ptr<BelCardGender> _gender;
list<shared_ptr<BelCardNickname>> _nicknames;
list<shared_ptr<BelCardPhoto>> _photos;
list<shared_ptr<BelCardProperty>> _properties;
public:
......@@ -79,6 +80,14 @@ namespace belcard {
return _nicknames;
}
void addPhoto(const shared_ptr<BelCardPhoto> &photo) {
_photos.push_back(photo);
addProperty(photo);
}
const list<shared_ptr<BelCardPhoto>> &getPhotos() const {
return _photos;
}
void addProperty(const shared_ptr<BelCardProperty> &property) {
_properties.push_back(property);
}
......
......@@ -44,7 +44,6 @@ namespace belcard {
virtual void setFamilyName(const string &value) {
_family_name = value;
setValue(_family_name + ";" + _given_name + ";" + _additional_name + ";" + _prefixes + ";" + _suffixes);
}
virtual const string &getFamilyName() const {
return _family_name;
......@@ -52,7 +51,6 @@ namespace belcard {
virtual void setGivenName(const string &value) {
_given_name = value;
setValue(_family_name + ";" + _given_name + ";" + _additional_name + ";" + _prefixes + ";" + _suffixes);
}
virtual const string &getGivenName() const {
return _given_name;
......@@ -60,7 +58,6 @@ namespace belcard {
virtual void setAdditionalName(const string &value) {
_additional_name = value;
setValue(_family_name + ";" + _given_name + ";" + _additional_name + ";" + _prefixes + ";" + _suffixes);
}
virtual const string &getAdditionalName() const {
return _additional_name;
......@@ -68,7 +65,6 @@ namespace belcard {
virtual void setPrefixes(const string &value) {
_prefixes = value;
setValue(_family_name + ";" + _given_name + ";" + _additional_name + ";" + _prefixes + ";" + _suffixes);
}
virtual const string &getPrefixes() const {
return _prefixes;
......@@ -76,7 +72,6 @@ namespace belcard {
virtual void setSuffixes(const string &value) {
_suffixes = value;
setValue(_family_name + ";" + _given_name + ";" + _additional_name + ";" + _prefixes + ";" + _suffixes);
}
virtual const string &getSuffixes() const {
return _suffixes;
......@@ -85,6 +80,11 @@ namespace belcard {
virtual void addParam(const shared_ptr<BelCardParam> &param) {
BelCardProperty::addParam(param);
}
virtual string toString() {
setValue(_family_name + ";" + _given_name + ";" + _additional_name + ";" + _prefixes + ";" + _suffixes);
return BelCardProperty::toString();
}
};
class BelCardNickname : public BelCardProperty {
......@@ -146,6 +146,21 @@ namespace belcard {
BelCardProperty::addParam(param);
}
};
class BelCardPhoto : public BelCardProperty {
public:
static shared_ptr<BelCardPhoto> create() {
return make_shared<BelCardPhoto>();
}
BelCardPhoto() : BelCardProperty() {
setName("PHOTO");
}
virtual void addParam(const shared_ptr<BelCardParam> &param) {
BelCardProperty::addParam(param);
}
};
}
#endif
\ No newline at end of file
......@@ -25,7 +25,8 @@ shared_ptr<BelCard> BelCardParser::parse(const string &input) {
->setCollector("BDAY", make_sfn(&BelCard::setBirthday))
->setCollector("ANNIVERSARY", make_sfn(&BelCard::setAnniversary))
->setCollector("GENDER", make_sfn(&BelCard::setGender))
->setCollector("NICKNAME", make_sfn(&BelCard::addNickname));
->setCollector("NICKNAME", make_sfn(&BelCard::addNickname))
->setCollector("PHOTO", make_sfn(&BelCard::addPhoto));
parser.setHandler("any-param", make_fn(&BelCardParam::create))
->setCollector("param-name", make_sfn(&BelCardParam::setName))
......@@ -65,6 +66,11 @@ shared_ptr<BelCard> BelCardParser::parse(const string &input) {
->setCollector("any-param", make_sfn(&BelCardNickname::addParam))
->setCollector("NICKNAME-value", make_sfn(&BelCardNickname::setValue));
parser.setHandler("PHOTO", make_fn(&BelCardPhoto::create))
->setCollector("group", make_sfn(&BelCardPhoto::setGroup))
->setCollector("any-param", make_sfn(&BelCardPhoto::addParam))
->setCollector("PHOTO-value", make_sfn(&BelCardPhoto::setValue));
size_t parsedSize = 0;
shared_ptr<BelCardGeneric> ret = parser.parseInput("vcard", vcard, &parsedSize);
shared_ptr<BelCard> belCard = dynamic_pointer_cast<BelCard>(ret);
......@@ -84,8 +90,8 @@ string BelCardParser::fold(string input) {
next_crlf = input.find("\r\n", crlf);
if (next_crlf != string::npos) {
if (next_crlf - crlf > 77) {
input.insert(crlf + 77, "\r\n ");
crlf += 80;
input.insert(crlf + 74, "\r\n ");
crlf += 76;
} else {
crlf = next_crlf + 2;
}
......
......@@ -8,7 +8,15 @@ using namespace::belr;
using namespace::belcard;
int main(int argc, char *argv[]) {
ifstream istr("vcardtest.vcf");
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;
}
......
This diff was suppressed by a .gitattributes entry.
......@@ -5,7 +5,7 @@ vcard = "BEGIN:VCARD" CRLF
1*property
"END:VCARD" CRLF
property = (FN / N / NICKNAME / BDAY / ANNIVERSARY / GENDER) CRLF
property = (FN / N / NICKNAME / BDAY / ANNIVERSARY / GENDER / PHOTO) CRLF
FN = [group "."] "FN" *(";" any-param) ":" FN-value
FN-value = text
......@@ -31,6 +31,9 @@ GENDER = [group "."] "GENDER" *(";" any-param) ":" GENDER-value
GENDER-value = [sex] [";" text]
sex = "M" / "F" / "O" / "N" / "U"
PHOTO = [group "."] "PHOTO" *(";" any-param) ":" PHOTO-value
PHOTO-value = URI
group = 1*(ALPHA / DIGIT / "-")
any-param = param-name "=" param-value
......@@ -102,3 +105,84 @@ timestamp = date-complete time-designator time-complete
date-and-or-time = date-time / date / time-designator time
utc-offset = sign hour [minute]
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
hier-part = "//" authority path-abempty
/ path-absolute
/ path-rootless
/ path-empty
URI-reference = URI / relative-ref
absolute-URI = scheme ":" hier-part [ "?" query ]
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
relative-part = "//" authority path-abempty
/ path-absolute
/ path-noscheme
/ path-empty
scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
authority = [ userinfo "@" ] host [ ":" port ]
userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
host = IP-literal / IPv4address / reg-name
port = *DIGIT
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
IPv6address = 6( h16 ":" ) ls32
/ "::" 5( h16 ":" ) ls32
/ [ h16 ] "::" 4( h16 ":" ) ls32
/ [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
/ [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
/ [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
/ [ *4( h16 ":" ) h16 ] "::" ls32
/ [ *5( h16 ":" ) h16 ] "::" h16
/ [ *6( h16 ":" ) h16 ] "::"
h16 = 1*4HEXDIG
ls32 = ( h16 ":" h16 ) / IPv4address
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet = DIGIT ; 0-9
/ %x31-39 DIGIT ; 10-99
/ "1" 2DIGIT ; 100-199
/ "2" %x30-34 DIGIT ; 200-249
/ "25" %x30-35 ; 250-255
reg-name = *( unreserved / pct-encoded / sub-delims )
path = path-abempty ; begins with "/" or is empty
/ path-absolute ; begins with "/" but not "//"
/ path-noscheme ; begins with a non-colon segment
/ path-rootless ; begins with a segment
/ path-empty ; zero characters
path-abempty = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]
path-noscheme = segment-nz-nc *( "/" segment )
path-rootless = segment-nz *( "/" segment )
path-empty = [pchar]
segment = *pchar
segment-nz = 1*pchar
segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
; non-zero-length segment without any colon ":"
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
query = *( pchar / "/" / "?" )
fragment = *( pchar / "/" / "?" )
pct-encoded = "%" HEXDIG HEXDIG
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
reserved = gen-delims / sub-delims
gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
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