Skip to content

Commit 2f7219e

Browse files
committed
Initial commit
0 parents  commit 2f7219e

18 files changed

+970
-0
lines changed

.gitignore

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
INSTALL
2+
aclocal.m4
3+
*~
4+
configure
5+
Makefile.in
6+
Makefile
7+
build-aux
8+
m4
9+
autom4te.cache
10+
*.o
11+
*.lo
12+
*.la
13+
config.log
14+
config.status
15+
.deps
16+
.libs
17+
libtool
18+
compile
19+
depcomp
20+
missing
21+
install-sh
22+
config.guess
23+
config.h.in
24+
config.sub
25+
ltmain.sh
26+
stamp-h1
27+
.kdev4/
28+
config.h
29+
*.orig
30+
belcard.kdev4
31+
tests/belcard-tester

AUTHORS

Whitespace-only changes.

COPYING

+674
Large diffs are not rendered by default.

ChangeLog

Whitespace-only changes.

Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SUBDIRS=src tests include

NEWS

Whitespace-only changes.

README

Whitespace-only changes.

autogen.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
3+
if ! type aclocal-$AM_VERSION 1>/dev/null 2>&1; then
4+
# automake-1.10 (recommended) is not available on Fedora 8
5+
AUTOMAKE=automake
6+
ACLOCAL=aclocal
7+
else
8+
ACLOCAL=aclocal-${AM_VERSION}
9+
AUTOMAKE=automake-${AM_VERSION}
10+
fi
11+
12+
if test -f /opt/local/bin/glibtoolize ; then
13+
# darwin
14+
LIBTOOLIZE=/opt/local/bin/glibtoolize
15+
else
16+
LIBTOOLIZE=libtoolize
17+
fi
18+
if test -d /opt/local/share/aclocal ; then
19+
ACLOCAL_ARGS="-I /opt/local/share/aclocal"
20+
fi
21+
22+
if test -d /share/aclocal ; then
23+
ACLOCAL_ARGS="-I /share/aclocal"
24+
fi
25+
26+
echo "Generating build scripts in myantlr..."
27+
set -x
28+
$LIBTOOLIZE --copy --force
29+
$ACLOCAL $ACLOCAL_ARGS
30+
autoheader
31+
$AUTOMAKE --force-missing --add-missing --copy
32+
autoconf
33+

configure.ac

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -*- Autoconf -*-
2+
# Process this file with autoconf to produce a configure script.
3+
4+
AC_PREREQ([2.69])
5+
AC_INIT([belcard], [0.0.1], [[email protected]])
6+
AC_CONFIG_SRCDIR([src/])
7+
AC_CONFIG_HEADERS([config.h])
8+
9+
AM_INIT_AUTOMAKE
10+
AM_SILENT_RULES(yes)
11+
LT_INIT(disable-static win32-dll)
12+
13+
# Checks for programs.
14+
AC_PROG_CXX
15+
16+
CXXFLAGS="$CXXFLAGS -std=c++11 -Wall -Werror"
17+
18+
# Checks for libraries.
19+
20+
# Checks for header files.
21+
22+
# Checks for typedefs, structures, and compiler characteristics.
23+
AC_TYPE_SSIZE_T
24+
25+
# Checks for library functions.
26+
AC_CONFIG_FILES(
27+
Makefile
28+
src/Makefile
29+
tests/Makefile
30+
include/Makefile
31+
include/belcard/Makefile
32+
)
33+
34+
AC_OUTPUT

include/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SUBDIRS=belcard

include/belcard/Makefile.am

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
belcard_includedir=$(includedir)/belcard
2+
3+
belcard_include_HEADERS = belcard.hpp
4+
5+
EXTRA_DIST=$(belcard_include_HEADERS)

include/belcard/belcard.hpp

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#ifndef belcard_hpp
2+
#define belcard_hpp
3+
4+
#include <string>
5+
#include <list>
6+
#include <map>
7+
#include <memory>
8+
9+
using namespace::std;
10+
11+
namespace belcard {
12+
class BelCardGeneric {
13+
public:
14+
BelCardGeneric() { }
15+
16+
virtual ~BelCardGeneric() { } //put a virtual destructor to enable polymorphism and dynamic casting.
17+
};
18+
19+
class BelCardProperty : public BelCardGeneric {
20+
protected:
21+
string _name;
22+
string _value;
23+
public:
24+
static shared_ptr<BelCardProperty> create() {
25+
return make_shared<BelCardProperty>();
26+
}
27+
28+
BelCardProperty() {
29+
30+
}
31+
32+
virtual void setName(const string & name) {
33+
_name = name;
34+
}
35+
virtual const string & getName() const {
36+
return _name;
37+
}
38+
39+
virtual void setValue(const string & value) {
40+
_value = value;
41+
}
42+
virtual const string & getValue() const {
43+
return _value;
44+
}
45+
};
46+
47+
class BelCardFN : public BelCardProperty {
48+
public:
49+
static shared_ptr<BelCardFN> create() {
50+
return make_shared<BelCardFN>();
51+
}
52+
53+
BelCardFN() : BelCardProperty() {
54+
setName("FN");
55+
}
56+
};
57+
58+
class BelCard : public BelCardGeneric {
59+
private:
60+
shared_ptr<BelCardFN> _fn;
61+
list<shared_ptr<BelCardProperty>> _properties;
62+
63+
public:
64+
static shared_ptr<BelCard> create() {
65+
return make_shared<BelCard>();
66+
}
67+
68+
BelCard() {
69+
70+
}
71+
72+
void setFN(const shared_ptr<BelCardFN> &fn) {
73+
_fn = fn;
74+
addProperty(_fn);
75+
}
76+
const shared_ptr<BelCardFN> &getFN() const {
77+
return _fn;
78+
}
79+
80+
void addProperty(const shared_ptr<BelCardProperty> &property) {
81+
_properties.push_back(property);
82+
}
83+
const list<shared_ptr<BelCardProperty>> &getProperties() const {
84+
return _properties;
85+
}
86+
};
87+
}
88+
89+
#endif

src/Makefile.am

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
lib_LTLIBRARIES=libbelcard.la
3+
4+
libbelcard_la_SOURCES=belcard.cpp
5+
6+
AM_CPPFLAGS=-I$(top_srcdir)/include
7+

src/belcard.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "belcard/belcard.hpp"
2+
3+
using namespace::std;
4+
5+
namespace belcard {
6+
7+
}

tests/Makefile.am

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
bin_PROGRAMS=belcard-tester
2+
3+
belcard_tester_SOURCES=belcard-tester.cpp
4+
5+
belcard_tester_LDADD=$(top_builddir)/src/libbelcard.la -lbelr
6+
7+
EXTRA_DIST=vcardgrammar.txt vcardtest.vcf
8+
9+
AM_CPPFLAGS=-I$(top_srcdir)/include

tests/belcard-tester.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "belcard/belcard.hpp"
2+
3+
#include <belr/grammarbuilder.hh>
4+
#include <belr/abnf.hh>
5+
#include <belr/parser-impl.cc>
6+
7+
#include <iostream>
8+
#include <fstream>
9+
#include <sstream>
10+
11+
using namespace::belr;
12+
using namespace::belcard;
13+
14+
int main(int argc, char *argv[]) {
15+
ABNFGrammarBuilder builder;
16+
shared_ptr<Grammar> grammar = builder.createFromAbnf("vcardgrammar.txt", make_shared<CoreRules>());
17+
if (!grammar) {
18+
cerr << "Could not build grammar from vcardgrammar.txt" << endl;
19+
return -1;
20+
}
21+
22+
Parser<shared_ptr<BelCardGeneric>> parser(grammar);
23+
parser.setHandler("vcard", make_fn(&BelCard::create))
24+
->setCollector("FN", make_sfn(&BelCard::setFN));
25+
26+
parser.setHandler("FN", make_fn(&BelCardFN::create))
27+
->setCollector("FN-value", make_sfn(&BelCardFN::setValue));
28+
29+
ifstream istr("vcardtest.vcf");
30+
if (!istr.is_open()) {
31+
return -1;
32+
}
33+
stringstream vcard;
34+
vcard << istr.rdbuf();
35+
36+
size_t parsedSize = 0;
37+
shared_ptr<BelCardGeneric> ret = parser.parseInput("vcard", vcard.str(), &parsedSize);
38+
shared_ptr<BelCard> belCard = dynamic_pointer_cast<BelCard>(ret);
39+
40+
cout << "FN is " << belCard->getFN()->getValue() << endl;
41+
42+
return 0;
43+
}

tests/vcardgrammar.txt

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
vcard-entity = 1*vcard
2+
3+
vcard = "BEGIN:VCARD" CRLF
4+
"VERSION:4.0" CRLF
5+
1*property
6+
"END:VCARD" CRLF
7+
8+
property = FN
9+
10+
FN = "FN" *(";" FN-param) ":" FN-value CRLF
11+
FN-param = any-param
12+
FN-value = text
13+
14+
any-param = (iana-token / x-name) "=" param-value *("," param-value)
15+
16+
param-value = *SAFE-CHAR / DQUOTE *QSAFE-CHAR DQUOTE
17+
18+
iana-token = 1*(ALPHA / DIGIT / "-")
19+
20+
x-name = "x-" 1*(ALPHA / DIGIT / "-")
21+
22+
text = *TEXT-CHAR
23+
TEXT-CHAR = "\\" / "\," / "\n" / WSP / NON-ASCII / %x21-2B / %x2D-5B / %x5D-7E
24+
NON-ASCII = UTF8-2 / UTF8-3 / UTF8-4
25+
QSAFE-CHAR = WSP / "!" / %x23-7E / NON-ASCII
26+
SAFE-CHAR = WSP / "!" / %x23-39 / %x3C-7E / NON-ASCII
27+
VALUE-CHAR = WSP / VCHAR / NON-ASCII
28+
UTF8-1 = %x00-7F
29+
UTF8-2 = %xC2-DF UTF8-tail
30+
UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) / %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
31+
UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) / %xF4 %x80-8F 2( UTF8-tail )
32+
UTF8-tail = %x80-BF

tests/vcardtest.vcf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
BEGIN:VCARD
2+
VERSION:4.0
3+
FN:Sylvain Berfini
4+
END:VCARD

0 commit comments

Comments
 (0)