Commit 2f7219e9 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Initial commit

parents
INSTALL
aclocal.m4
*~
configure
Makefile.in
Makefile
build-aux
m4
autom4te.cache
*.o
*.lo
*.la
config.log
config.status
.deps
.libs
libtool
compile
depcomp
missing
install-sh
config.guess
config.h.in
config.sub
ltmain.sh
stamp-h1
.kdev4/
config.h
*.orig
belcard.kdev4
tests/belcard-tester
This diff is collapsed.
SUBDIRS=src tests include
#!/bin/sh
if ! type aclocal-$AM_VERSION 1>/dev/null 2>&1; then
# automake-1.10 (recommended) is not available on Fedora 8
AUTOMAKE=automake
ACLOCAL=aclocal
else
ACLOCAL=aclocal-${AM_VERSION}
AUTOMAKE=automake-${AM_VERSION}
fi
if test -f /opt/local/bin/glibtoolize ; then
# darwin
LIBTOOLIZE=/opt/local/bin/glibtoolize
else
LIBTOOLIZE=libtoolize
fi
if test -d /opt/local/share/aclocal ; then
ACLOCAL_ARGS="-I /opt/local/share/aclocal"
fi
if test -d /share/aclocal ; then
ACLOCAL_ARGS="-I /share/aclocal"
fi
echo "Generating build scripts in myantlr..."
set -x
$LIBTOOLIZE --copy --force
$ACLOCAL $ACLOCAL_ARGS
autoheader
$AUTOMAKE --force-missing --add-missing --copy
autoconf
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([belcard], [0.0.1], [sylvain.berfini@belledonne-communications.com])
AC_CONFIG_SRCDIR([src/])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE
AM_SILENT_RULES(yes)
LT_INIT(disable-static win32-dll)
# Checks for programs.
AC_PROG_CXX
CXXFLAGS="$CXXFLAGS -std=c++11 -Wall -Werror"
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SSIZE_T
# Checks for library functions.
AC_CONFIG_FILES(
Makefile
src/Makefile
tests/Makefile
include/Makefile
include/belcard/Makefile
)
AC_OUTPUT
SUBDIRS=belcard
belcard_includedir=$(includedir)/belcard
belcard_include_HEADERS = belcard.hpp
EXTRA_DIST=$(belcard_include_HEADERS)
#ifndef belcard_hpp
#define belcard_hpp
#include <string>
#include <list>
#include <map>
#include <memory>
using namespace::std;
namespace belcard {
class BelCardGeneric {
public:
BelCardGeneric() { }
virtual ~BelCardGeneric() { } //put a virtual destructor to enable polymorphism and dynamic casting.
};
class BelCardProperty : public BelCardGeneric {
protected:
string _name;
string _value;
public:
static shared_ptr<BelCardProperty> create() {
return make_shared<BelCardProperty>();
}
BelCardProperty() {
}
virtual void setName(const string & name) {
_name = name;
}
virtual const string & getName() const {
return _name;
}
virtual void setValue(const string & value) {
_value = value;
}
virtual const string & getValue() const {
return _value;
}
};
class BelCardFN : public BelCardProperty {
public:
static shared_ptr<BelCardFN> create() {
return make_shared<BelCardFN>();
}
BelCardFN() : BelCardProperty() {
setName("FN");
}
};
class BelCard : public BelCardGeneric {
private:
shared_ptr<BelCardFN> _fn;
list<shared_ptr<BelCardProperty>> _properties;
public:
static shared_ptr<BelCard> create() {
return make_shared<BelCard>();
}
BelCard() {
}
void setFN(const shared_ptr<BelCardFN> &fn) {
_fn = fn;
addProperty(_fn);
}
const shared_ptr<BelCardFN> &getFN() const {
return _fn;
}
void addProperty(const shared_ptr<BelCardProperty> &property) {
_properties.push_back(property);
}
const list<shared_ptr<BelCardProperty>> &getProperties() const {
return _properties;
}
};
}
#endif
\ No newline at end of file
lib_LTLIBRARIES=libbelcard.la
libbelcard_la_SOURCES=belcard.cpp
AM_CPPFLAGS=-I$(top_srcdir)/include
#include "belcard/belcard.hpp"
using namespace::std;
namespace belcard {
}
\ No newline at end of file
bin_PROGRAMS=belcard-tester
belcard_tester_SOURCES=belcard-tester.cpp
belcard_tester_LDADD=$(top_builddir)/src/libbelcard.la -lbelr
EXTRA_DIST=vcardgrammar.txt vcardtest.vcf
AM_CPPFLAGS=-I$(top_srcdir)/include
#include "belcard/belcard.hpp"
#include <belr/grammarbuilder.hh>
#include <belr/abnf.hh>
#include <belr/parser-impl.cc>
#include <iostream>
#include <fstream>
#include <sstream>
using namespace::belr;
using namespace::belcard;
int main(int argc, char *argv[]) {
ABNFGrammarBuilder builder;
shared_ptr<Grammar> grammar = builder.createFromAbnf("vcardgrammar.txt", make_shared<CoreRules>());
if (!grammar) {
cerr << "Could not build grammar from vcardgrammar.txt" << endl;
return -1;
}
Parser<shared_ptr<BelCardGeneric>> parser(grammar);
parser.setHandler("vcard", make_fn(&BelCard::create))
->setCollector("FN", make_sfn(&BelCard::setFN));
parser.setHandler("FN", make_fn(&BelCardFN::create))
->setCollector("FN-value", make_sfn(&BelCardFN::setValue));
ifstream istr("vcardtest.vcf");
if (!istr.is_open()) {
return -1;
}
stringstream vcard;
vcard << istr.rdbuf();
size_t parsedSize = 0;
shared_ptr<BelCardGeneric> ret = parser.parseInput("vcard", vcard.str(), &parsedSize);
shared_ptr<BelCard> belCard = dynamic_pointer_cast<BelCard>(ret);
cout << "FN is " << belCard->getFN()->getValue() << endl;
return 0;
}
\ No newline at end of file
vcard-entity = 1*vcard
vcard = "BEGIN:VCARD" CRLF
"VERSION:4.0" CRLF
1*property
"END:VCARD" CRLF
property = FN
FN = "FN" *(";" FN-param) ":" FN-value CRLF
FN-param = any-param
FN-value = text
any-param = (iana-token / x-name) "=" param-value *("," param-value)
param-value = *SAFE-CHAR / DQUOTE *QSAFE-CHAR DQUOTE
iana-token = 1*(ALPHA / DIGIT / "-")
x-name = "x-" 1*(ALPHA / DIGIT / "-")
text = *TEXT-CHAR
TEXT-CHAR = "\\" / "\," / "\n" / WSP / NON-ASCII / %x21-2B / %x2D-5B / %x5D-7E
NON-ASCII = UTF8-2 / UTF8-3 / UTF8-4
QSAFE-CHAR = WSP / "!" / %x23-7E / NON-ASCII
SAFE-CHAR = WSP / "!" / %x23-39 / %x3C-7E / NON-ASCII
VALUE-CHAR = WSP / VCHAR / NON-ASCII
UTF8-1 = %x00-7F
UTF8-2 = %xC2-DF UTF8-tail
UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) / %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) / %xF4 %x80-8F 2( UTF8-tail )
UTF8-tail = %x80-BF
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