Skip to content

Commit

Permalink
Update to C++14
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSodaSea committed Jan 25, 2018
1 parent 6f44478 commit f649cac
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 55 deletions.
64 changes: 44 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,58 @@ sudo: required

matrix:
include:
- env: CONFIG=debug FLAGS="-m32"
compiler: gcc
- env: CONFIG=release FLAGS="-m32"
compiler: gcc
- env: CONFIG=debug FLAGS="-m64"
compiler: gcc
- env: CONFIG=release FLAGS="-m64"
compiler: gcc
- env: CONFIG=debug FLAGS="-m32"
compiler: clang
- env: CONFIG=release FLAGS="-m32"
compiler: clang
- env: CONFIG=debug FLAGS="-m64"
compiler: clang
- env: CONFIG=release FLAGS="-m64"
compiler: clang
- env: EVAL="CXX=g++-5" FLAGS="-m32" CONFIG=Debug
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-5-multilib', 'lib32stdc++6', 'linux-libc-dev']
- env: EVAL="CXX=g++-5" FLAGS="-m32" CONFIG=Release
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-5-multilib', 'lib32stdc++6', 'linux-libc-dev']
- env: EVAL="CXX=g++-5" FLAGS="-m64" CONFIG=Debug
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-5']
- env: EVAL="CXX=g++-5" FLAGS="-m64" CONFIG=Release
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-5']
- env: EVAL="CXX=clang++" FLAGS="-m32" CONFIG=Debug
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-5-multilib', 'lib32stdc++6', 'linux-libc-dev']
- env: EVAL="CXX=clang++" FLAGS="-m32" CONFIG=Release
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-5-multilib', 'lib32stdc++6', 'linux-libc-dev']
- env: EVAL="CXX=clang++" FLAGS="-m64" CONFIG=Debug
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-5']
- env: EVAL="CXX=clang++" FLAGS="-m64" CONFIG=Release
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-5']

before_script:
- sudo apt-add-repository -y ppa:ubuntu-toolchain-r/test
- sudo apt-get update -qq
- sudo apt-get install -y g++-multilib lib32stdc++6 libc6-dev-i386
- sudo ln -s /usr/include/asm-generic /usr/include/asm
- eval "${EVAL}"
- $CXX -v
- cd ..
- git clone -q --branch=master https://github.com/SuperSodaSea/Corecat.git
- cd Corecat
- git checkout -fq master
- cp -r include ../Textcat
- cd ../Textcat
- cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=$CONFIG -DCMAKE_CXX_FLAGS=$FLAGS
- cmake -H. -Bbuild -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_CXX_FLAGS=$FLAGS -DCMAKE_BUILD_TYPE=$CONFIG

script:
- make -C build
Expand Down
16 changes: 8 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.1)

project(Textcat)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
Expand All @@ -12,12 +12,12 @@ endif()

include_directories("include")

set(EXAMPLE_XML
SAXReader
SAXWriter
DOMReader
DOMWriter)
set(EXAMPLE
XML_SAXReader
XML_SAXWriter
XML_DOMReader
XML_DOMWriter)

foreach(example ${EXAMPLE_XML})
add_executable(XML_${example} example/XML/${example}/${example}.cpp)
foreach(example ${EXAMPLE})
add_executable(${example} example/${example}/${example}.cpp)
endforeach()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Currently supported format:

## Requirement

+ C++11
+ C++14
+ [Corecat][Corecat]


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 19 additions & 16 deletions include/Cats/Textcat/XML/DOM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,10 @@ class XMLDocument : public XMLNode {

}

void serialize(OutputStream<char>& stream) {
template <typename H>
void visit(H& handler) {

XMLSerializer serializer(stream);
serializer.startDocument();
handler.startDocument();
if(hasChildNodes()) {

XMLNode* cur = &getFirstChild();
Expand All @@ -504,43 +504,40 @@ class XMLDocument : public XMLNode {
case XMLNodeType::Element: {

auto& element = static_cast<XMLElement&>(*cur);
serializer.startElement(element.getName());
for(auto& attr : element.attribute()) {

serializer.attribute(attr.getName(), attr.getValue());

}
handler.startElement(element.getName());
for(auto& attr : element.attribute())
handler.attribute(attr.getName(), attr.getValue());
bool empty = !cur->hasChildNodes();
serializer.endAttributes(empty);
handler.endAttributes(empty);
if(!empty) { cur = &cur->getFirstChild(); continue; }
break;

}
case XMLNodeType::Text: {

auto& text = static_cast<XMLText&>(*cur);
serializer.text(text.getValue());
handler.text(text.getValue());
break;

}
case XMLNodeType::CDATA: {

auto& cdata = static_cast<XMLCDATA&>(*cur);
serializer.cdata(cdata.getValue());
handler.cdata(cdata.getValue());
break;

}
case XMLNodeType::Comment: {

auto& comment = static_cast<XMLComment&>(*cur);
serializer.comment(comment.getValue());
handler.comment(comment.getValue());
break;

}
case XMLNodeType::ProcessingInstruction: {

auto& pi = static_cast<XMLProcessingInstruction&>(*cur);
serializer.processingInstruction(pi.getName(), pi.getValue());
handler.processingInstruction(pi.getName(), pi.getValue());
break;

}
Expand All @@ -552,7 +549,7 @@ class XMLDocument : public XMLNode {
cur = cur->parent;
if(cur == this) break;
auto name = static_cast<XMLElement*>(cur)->getName();
serializer.endElement(name);
handler.endElement(name);

}
if(cur == this) break;
Expand All @@ -561,7 +558,13 @@ class XMLDocument : public XMLNode {
}

}
serializer.endDocument();
handler.endDocument();

}
void serialize(OutputStream<char>& stream) {

XMLSerializer serializer(stream);
visit(serializer);

}

Expand Down
20 changes: 10 additions & 10 deletions include/Cats/Textcat/XML/Parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct Skipper {
using namespace Corecat;

auto t = p;
while(SequenceTable<MapperSequence<Cond, IndexSequence<unsigned char, 0, 255>>>::get(*t)) ++t;
while(SequenceTable<MapperSequence<Cond, IndexSequence<int, 0, 256>>>::get(*t)) ++t;
const size_t length = t - p;
p = t;
return length;
Expand Down Expand Up @@ -178,7 +178,7 @@ class XMLParser {
p += 3;
if(*p == ';') throw XMLParseException("Unexpected ;", p - s);
std::uint32_t code = 0;
for(unsigned char t; (t = SequenceTable<MapperSequence<Impl::Hexadecimal, IndexSequence<unsigned char, 0, 255>>>::get(*p)) != 255; code = code * 16 + t, ++p);
for(unsigned char t; (t = SequenceTable<MapperSequence<Impl::Hexadecimal, IndexSequence<int, 0, 256>>>::get(*p)) != 255; code = code * 16 + t, ++p);
if(*p != ';') throw XMLParseException("Expected ;", p - s);
++p;
// TODO: Code conversion
Expand All @@ -190,7 +190,7 @@ class XMLParser {
p += 2;
if(*p == ';') throw XMLParseException("Unexpected ;", p - s);
std::uint32_t code = 0;
for(unsigned char t; (t = SequenceTable<MapperSequence<Impl::Decimal, IndexSequence<unsigned char, 0, 255>>>::get(*p)) != 255; code = code * 10 + t, ++p);
for(unsigned char t; (t = SequenceTable<MapperSequence<Impl::Decimal, IndexSequence<int, 0, 256>>>::get(*p)) != 255; code = code * 10 + t, ++p);
if(*p != ';') throw XMLParseException("Expected ;", p - s);
++p;
// TODO: Code conversion
Expand Down Expand Up @@ -306,7 +306,7 @@ class XMLParser {
} else throw XMLParseException("Expected \" or '", p - s);
++p;

if(*p != '?' && !SequenceTable<MapperSequence<Impl::Space, IndexSequence<unsigned char, 0, 255>>>::get(*p))
if(*p != '?' && !SequenceTable<MapperSequence<Impl::Space, IndexSequence<int, 0, 256>>>::get(*p))
throw XMLParseException("Unexpected character", p - s);
Impl::Skipper<Impl::Space>::skip(p);

Expand Down Expand Up @@ -335,7 +335,7 @@ class XMLParser {

}

if(*p != '?' && !SequenceTable<MapperSequence<Impl::Space, IndexSequence<unsigned char, 0, 255>>>::get(*p))
if(*p != '?' && !SequenceTable<MapperSequence<Impl::Space, IndexSequence<int, 0, 256>>>::get(*p))
throw XMLParseException("Unexpected character", p - s);
Impl::Skipper<Impl::Space>::skip(p);

Expand Down Expand Up @@ -445,7 +445,7 @@ class XMLParser {
++p;
handler.startElement(name);
Impl::Skipper<Impl::Space>::skip(p);
while(SequenceTable<MapperSequence<Impl::AttributeName, IndexSequence<unsigned char, 0, 255>>>::get(*p)) {
while(SequenceTable<MapperSequence<Impl::AttributeName, IndexSequence<int, 0, 256>>>::get(*p)) {

// Parse attribute name
StringView8 name(p, 0);
Expand Down Expand Up @@ -577,7 +577,7 @@ class XMLParser {
}
--q;
if(F & Flag::TrimSpace)
for(; SequenceTable<MapperSequence<Impl::Space, IndexSequence<unsigned char, 0, 255>>>::get(*q); --q);
for(; SequenceTable<MapperSequence<Impl::Space, IndexSequence<int, 0, 256>>>::get(*q); --q);
++q;
text.setLength(q - text.getData());
handler.text(text);
Expand All @@ -602,7 +602,7 @@ class XMLParser {
}
--q;
if(F & Flag::TrimSpace)
for(; SequenceTable<MapperSequence<Impl::Space, IndexSequence<unsigned char, 0, 255>>>::get(*q); --q);
for(; SequenceTable<MapperSequence<Impl::Space, IndexSequence<int, 0, 256>>>::get(*q); --q);
++q;
text.setLength(q - text.getData());
handler.text(text);
Expand All @@ -614,7 +614,7 @@ class XMLParser {
if(*p == 0) throw XMLParseException("Unexpected end of data", p - s);
auto q = p - 1;
if(F & Flag::TrimSpace)
for(; SequenceTable<MapperSequence<Impl::Space, IndexSequence<unsigned char, 0, 255>>>::get(*q); --q);
for(; SequenceTable<MapperSequence<Impl::Space, IndexSequence<int, 0, 256>>>::get(*q); --q);
++q;
text.setLength(q - text.getData());
handler.text(text);
Expand Down Expand Up @@ -721,7 +721,7 @@ class XMLParser {
}

// Parse XML declaration
if(p[0] == '<' && p[1] == '?' && p[2] == 'x' && p[3] == 'm' && p[4] == 'l' && SequenceTable<MapperSequence<Impl::Space, IndexSequence<unsigned char, 0, 255>>>::get(p[5])) {
if(p[0] == '<' && p[1] == '?' && p[2] == 'x' && p[3] == 'm' && p[4] == 'l' && SequenceTable<MapperSequence<Impl::Space, IndexSequence<int, 0, 256>>>::get(p[5])) {

// "<?xml "
p += 6;
Expand Down

0 comments on commit f649cac

Please sign in to comment.