From fb31de1b875565cb8734b0f10cb6df28e406ffd1 Mon Sep 17 00:00:00 2001 From: Aleksey Dobrunov Date: Mon, 30 Sep 2024 21:25:59 +0500 Subject: [PATCH] remove xerces-c depends --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/colorer_ci.yml | 36 +----- .github/workflows/docker_build.yml | 9 -- .github/workflows/release.yml | 2 +- CMakeLists.txt | 7 +- CMakePresets.json | 27 +---- README.md | 7 +- ci/Dockerfile-test-xercesc | 17 --- ci/Dockerfile-xercesc | 30 ----- cmake/colorerConfig.cmake.in | 2 +- src/CMakeLists.txt | 65 +++------- src/colorer/common/Features.h.in | 1 - src/colorer/strings/icu/UStr.cpp | 21 ---- src/colorer/strings/icu/UStr.h | 9 -- src/colorer/strings/legacy/UStr.cpp | 22 ---- src/colorer/strings/legacy/UStr.h | 8 -- src/colorer/xml/XmlInputSource.cpp | 21 ---- src/colorer/xml/XmlInputSource.h | 16 +-- src/colorer/xml/XmlReader.cpp | 4 - src/colorer/xml/XmlReader.h | 8 -- .../xml/xercesc/BaseEntityResolver.cpp | 19 --- src/colorer/xml/xercesc/BaseEntityResolver.h | 12 -- .../xml/xercesc/LocalFileXmlInputSource.cpp | 35 ------ .../xml/xercesc/LocalFileXmlInputSource.h | 25 ---- .../xml/xercesc/SharedXmlInputSource.cpp | 74 ------------ .../xml/xercesc/SharedXmlInputSource.h | 50 -------- .../xml/xercesc/XercesXmlInputSource.cpp | 44 ------- .../xml/xercesc/XercesXmlInputSource.h | 53 --------- src/colorer/xml/xercesc/XercesXmlReader.cpp | 112 ------------------ src/colorer/xml/xercesc/XercesXmlReader.h | 37 ------ .../xml/xercesc/XmlParserErrorHandler.cpp | 35 ------ .../xml/xercesc/XmlParserErrorHandler.h | 27 ----- src/colorer/xml/xercesc/ZipXmlInputSource.cpp | 91 -------------- src/colorer/xml/xercesc/ZipXmlInputSource.h | 48 -------- vcpkg.json | 4 - 35 files changed, 34 insertions(+), 946 deletions(-) delete mode 100644 ci/Dockerfile-test-xercesc delete mode 100644 ci/Dockerfile-xercesc delete mode 100644 src/colorer/xml/xercesc/BaseEntityResolver.cpp delete mode 100644 src/colorer/xml/xercesc/BaseEntityResolver.h delete mode 100644 src/colorer/xml/xercesc/LocalFileXmlInputSource.cpp delete mode 100644 src/colorer/xml/xercesc/LocalFileXmlInputSource.h delete mode 100644 src/colorer/xml/xercesc/SharedXmlInputSource.cpp delete mode 100644 src/colorer/xml/xercesc/SharedXmlInputSource.h delete mode 100644 src/colorer/xml/xercesc/XercesXmlInputSource.cpp delete mode 100644 src/colorer/xml/xercesc/XercesXmlInputSource.h delete mode 100644 src/colorer/xml/xercesc/XercesXmlReader.cpp delete mode 100644 src/colorer/xml/xercesc/XercesXmlReader.h delete mode 100644 src/colorer/xml/xercesc/XmlParserErrorHandler.cpp delete mode 100644 src/colorer/xml/xercesc/XmlParserErrorHandler.h delete mode 100644 src/colorer/xml/xercesc/ZipXmlInputSource.cpp delete mode 100644 src/colorer/xml/xercesc/ZipXmlInputSource.h diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 651f0b64..fd3b7f84 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -35,7 +35,7 @@ jobs: languages: ${{ matrix.language }} - name: Install dependency - run: sudo apt-get -y install ninja-build libicu-dev libxerces-c-dev zlib1g-dev libminizip-dev + run: sudo apt-get -y install ninja-build libicu-dev libxml2-dev zlib1g-dev libminizip-dev - name: Create Build folder run: mkdir -p _build diff --git a/.github/workflows/colorer_ci.yml b/.github/workflows/colorer_ci.yml index 737c3303..7de4c541 100644 --- a/.github/workflows/colorer_ci.yml +++ b/.github/workflows/colorer_ci.yml @@ -39,16 +39,15 @@ jobs: arch: [ x64 ] icu: [ON, OFF] zip: [ON, OFF] - libxml: [ON, OFF] - name: linux-${{ matrix.arch }}-icu_${{ matrix.icu }}-zip_${{ matrix.zip }}-libxml_${{ matrix.libxml }} + name: linux-${{ matrix.arch }}-icu_${{ matrix.icu }}-zip_${{ matrix.zip }} steps: - name: Checkout source uses: actions/checkout@v4 - name: Install dependency - run: sudo apt-get -y install ninja-build libicu-dev libxerces-c-dev zlib1g-dev libminizip-dev libxml2-dev + run: sudo apt-get -y install ninja-build libicu-dev zlib1g-dev libminizip-dev libxml2-dev - name: Create Build folder run: mkdir -p _build @@ -66,7 +65,6 @@ jobs: -DCOLORER_BUILD_ARCH=${{ matrix.arch }} -DCOLORER_USE_ICU_STRINGS=${{ matrix.icu }} -DCOLORER_USE_ZIPINPUTSOURCE=${{ matrix.zip }} - -DCOLORER_USE_LIBXML=${{ matrix.libxml }} - name: Build run: cmake --build _build --config $BUILD_TYPE -j ${{ steps.cpu-cores.outputs.count }} @@ -83,7 +81,6 @@ jobs: arch: [ x64, x86 ] icu: [ON, OFF] zip: [ON, OFF] - libxml: [ON, OFF] include: - arch: x64 triplet: x64-windows-static-rel @@ -93,7 +90,7 @@ jobs: - arch: x86 zip: OFF - name: windows-${{ matrix.arch }}-icu_${{ matrix.icu }}-zip_${{ matrix.zip }}-libxml_${{ matrix.libxml }} + name: windows-${{ matrix.arch }}-icu_${{ matrix.icu }}-zip_${{ matrix.zip }} steps: - name: Checkout source @@ -146,7 +143,6 @@ jobs: -DVCPKG_FEATURE_FLAGS=manifests,versions -DCOLORER_USE_ICU_STRINGS=${{ matrix.icu }} -DCOLORER_USE_ZIPINPUTSOURCE=${{ matrix.zip }} - -DCOLORER_USE_LIBXML=${{ matrix.libxml }} - name: Build shell: bash @@ -164,9 +160,8 @@ jobs: arch: [ x64 ] icu: [ON, OFF] zip: [ON, OFF] - libxml: [ON, OFF] - name: macos-${{ matrix.arch }}-icu_${{ matrix.icu }}-zip_${{ matrix.zip }}-libxml_${{ matrix.libxml }} + name: macos-${{ matrix.arch }}-icu_${{ matrix.icu }}-zip_${{ matrix.zip }} steps: - name: Checkout source @@ -174,7 +169,7 @@ jobs: - name: Install dependency # icu4c is already installed - run: brew install xerces-c minizip ninja libxml2 + run: brew install minizip ninja libxml2 - name: Relink icu, because he is 'keg-only' run: brew link icu4c --force @@ -191,30 +186,9 @@ jobs: -DCOLORER_BUILD_ARCH=${{ matrix.arch }} -DCOLORER_USE_ICU_STRINGS=${{ matrix.icu }} -DCOLORER_USE_ZIPINPUTSOURCE=${{ matrix.zip }} - -DCOLORER_USE_LIBXML=${{ matrix.libxml }} - name: Build run: cmake --build _build --config $BUILD_TYPE -j$(getconf _NPROCESSORS_ONLN) - name: Test run: ./_build/tests/unit/unit_tests - - test-xercesc: - # check build with xerces-c (unit16_t) - runs-on: ubuntu-22.04 - name: linux-xercesc-uint16t - - steps: - - name: Checkout source - uses: actions/checkout@v4 - - - name: 'Login to GitHub Container Registry' - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ secrets.PACKAGES_GITHUB_USER }} - password: ${{ secrets.PACKAGES_GITHUB_TOKEN }} - - - name: 'Build in docker' - run: | - docker build -f ci/Dockerfile-test-xercesc -t tempx:latest . diff --git a/.github/workflows/docker_build.yml b/.github/workflows/docker_build.yml index 43acc6a7..d31fa259 100644 --- a/.github/workflows/docker_build.yml +++ b/.github/workflows/docker_build.yml @@ -25,12 +25,3 @@ jobs: tags: ghcr.io/colorer/devenv22_base:latest cache-from: type=registry,ref=ghcr.io/colorer/devenv22_base:latest cache-to: type=inline - - - name: Build and push xercesc image - uses: docker/build-push-action@v6 - with: - file: ./ci/Dockerfile-xercesc - push: true - tags: ghcr.io/colorer/devenv22_xercesc:latest - cache-from: type=registry,ref=ghcr.io/colorer/devenv22_base:latest - cache-to: type=inline diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 24356b53..cdf16811 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,7 +17,7 @@ jobs: uses: actions/checkout@v4 - name: Install dependency - run: sudo apt-get -y install ninja-build libicu-dev libxerces-c-dev libxml2-dev zlib1g-dev libminizip-dev + run: sudo apt-get -y install ninja-build libicu-dev libxml2-dev libxml2-dev zlib1g-dev libminizip-dev - name: Create Build folder run: cmake -E make_directory build diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cf44a46..6ee1258e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,6 @@ option(COLORER_BUILD_OLD_COMPILERS "Use own implementation for standard library" option(COLORER_USE_ZIPINPUTSOURCE "Use zip inputsource for schemes" ON) option(COLORER_USE_DEEPTRACE "Use trace logging" OFF) option(COLORER_USE_ICU_STRINGS "Use ICU library for strings" ON) -option(COLORER_USE_LIBXML "Use LibXml2 library for parse xml, instead XercesC" OFF) #==================================================== # global compilation settings @@ -76,11 +75,7 @@ if(COLORER_USE_ICU_STRINGS) find_package(ICU COMPONENTS uc data REQUIRED) endif() -if(COLORER_USE_LIBXML) - find_package(LibXml2 REQUIRED) -else() - find_package(XercesC REQUIRED) -endif() +find_package(LibXml2 REQUIRED) if(COLORER_USE_ZIPINPUTSOURCE) find_package(ZLIB REQUIRED) diff --git a/CMakePresets.json b/CMakePresets.json index 8ae19ca9..746c5fbe 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -129,20 +129,6 @@ }, "hidden": true }, - { - "name": "XercesXml", - "cacheVariables": { - "COLORER_USE_LIBXML": "OFF" - }, - "hidden": true - }, - { - "name": "LibXml2", - "cacheVariables": { - "COLORER_USE_LIBXML": "ON" - }, - "hidden": true - }, { "name": "Tests", "cacheVariables": { @@ -191,14 +177,9 @@ { "name": "msvc-arm64-Release", "description": "MSVC for ARM64 (Release, ICU)", "inherits": [ "base", "ARM64", "Release", "MSVC", "vcpkg_win_arm64" ] }, { "name": "msvc-arm64-Debug-noICU", "description": "MSVC for ARM64 (Debug, noICU)", "inherits": [ "base", "ARM64", "Debug", "MSVC", "vcpkg_win_arm64", "NoICU", "Tests" ] }, { "name": "msvc-arm64-Release-noICU", "description": "MSVC for ARM64 (Release, noICU)", "inherits": [ "base", "ARM64", "Release", "MSVC", "vcpkg_win_arm64", "NoICU" ] }, - { "name": "linux-x64-Debug-noICU", "description": "Linux for x64 (Debug, noICU, LibXml)", "inherits": [ "base", "x64", "Debug", "NoVcpkg", "NoICU", "Tests", "LibXml2" ] }, - { "name": "linux-x64-Release-noICU", "description": "Linux for x64 (Release, noICU, LibXml)", "inherits": [ "base", "x64", "Release", "NoVcpkg", "NoICU", "LibXml2" ] }, - { "name": "linux-x64-Debug", "description": "Linux for x64 (Debug, ICU, LibXml)", "inherits": [ "base", "x64", "Debug", "NoVcpkg", "Tests", "LibXml2" ] }, - { "name": "linux-x64-Release", "description": "Linux for x64 (Release, ICU, LibXml)", "inherits": [ "base", "x64", "Release", "NoVcpkg", "LibXml2" ] }, - { "name": "linux-x64-Debug-noICU-Xerces", "description": "Linux for x64 (Debug, noICU, Xerces)", "inherits": [ "base", "x64", "Debug", "NoVcpkg", "NoICU", "Tests", "XercesXml"] }, - { "name": "linux-x64-Release-noICU-Xerces", "description": "Linux for x64 (Release, noICU, Xerces)", "inherits": [ "base", "x64", "Release", "NoVcpkg", "NoICU", "XercesXml" ] }, - { "name": "linux-x64-Debug-Xerces", "description": "Linux for x64 (Debug, ICU, Xerces)", "inherits": [ "base", "x64", "Debug", "NoVcpkg", "Tests", "XercesXml" ] }, - { "name": "linux-x64-Release-Xerces", "description": "Linux for x64 (Release, ICU, Xerces)", "inherits": [ "base", "x64", "Release", "NoVcpkg", "XercesXml" ] } - + { "name": "linux-x64-Debug-noICU", "description": "Linux for x64 (Debug, noICU, LibXml)", "inherits": [ "base", "x64", "Debug", "NoVcpkg", "NoICU", "Tests" ] }, + { "name": "linux-x64-Release-noICU", "description": "Linux for x64 (Release, noICU, LibXml)", "inherits": [ "base", "x64", "Release", "NoVcpkg", "NoICU" ] }, + { "name": "linux-x64-Debug", "description": "Linux for x64 (Debug, ICU, LibXml)", "inherits": [ "base", "x64", "Debug", "NoVcpkg", "Tests" ] }, + { "name": "linux-x64-Release", "description": "Linux for x64 (Release, ICU, LibXml)", "inherits": [ "base", "x64", "Release", "NoVcpkg" ] } ] } \ No newline at end of file diff --git a/README.md b/README.md index 4793d6ff..0204f070 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ You may build library on linux using standard package, without vcpkg. #### Ubuntu example ```bash -sudo apt install libicu-dev libxerces-c-dev zlib1g-dev libminizip-dev libxml2-dev +sudo apt install libicu-dev zlib1g-dev libminizip-dev libxml2-dev git clone https://github.com/colorer/Colorer-library.git cd Colorer-library mkdir _build @@ -57,7 +57,7 @@ cmake --build _build -j$(nproc --all) #### CentOS Example ```bash -sudo yum install libicu-devel xerces-c-devel zlib-devel minizip1.2-devel +sudo yum install libicu-devel zlib-devel minizip1.2-devel git clone https://github.com/colorer/Colorer-library.git cd Colorer-library mkdir _build @@ -67,7 +67,7 @@ cmake --build _build -j$(nproc --all) ### MacOS ```bash -brew install xerces-c icu4c minizip ninja libxml2 +brew install icu4c minizip ninja libxml2 git clone https://github.com/colorer/Colorer-library.git cd Colorer-library mkdir _build @@ -89,7 +89,6 @@ This options available for build * `COLORER_USE_ZIPINPUTSOURCE` - Enable the ability to work with schemes in zip archives. Default 'ON'. * `COLORER_USE_DEEPTRACE` - Use trace logging. Default 'OFF'. * `COLORER_USE_ICU_STRINGS` - Use ICU library for strings. Default 'ON'. -* `COLORER_USE_LIBXML` - Use LibXml2 library for parse xml, instead XercesC. Default 'OFF'. Links ======================== diff --git a/ci/Dockerfile-test-xercesc b/ci/Dockerfile-test-xercesc deleted file mode 100644 index 4df8dfbb..00000000 --- a/ci/Dockerfile-test-xercesc +++ /dev/null @@ -1,17 +0,0 @@ -# Image for the test build Colorer with Xerces-C (uint16_t) -# run build from root of project - -FROM ghcr.io/colorer/devenv22_xercesc:latest - -SHELL ["/bin/bash", "-xeuo", "pipefail", "-c"] - -WORKDIR /code - -RUN --mount=type=bind,source=.,target=/code/colorer \ -< UStr::to_xmlch(const UnicodeString* str) -{ - // XMLCh and UChar are the same size - std::unique_ptr out_s; - if (str) { - auto len = str->length(); - out_s = std::make_unique(len + 1); - str->extract(0, len, out_s.get()); - out_s[len] = 0; - } - return out_s; -} - -std::string UStr::to_stdstr(const XMLCh* str) -{ - std::string _string = std::string(xercesc::XMLString::transcode(str)); - return _string; -} -#endif diff --git a/src/colorer/strings/icu/UStr.h b/src/colorer/strings/icu/UStr.h index af80cba1..c8f60d9f 100644 --- a/src/colorer/strings/icu/UStr.h +++ b/src/colorer/strings/icu/UStr.h @@ -3,9 +3,6 @@ #include #include "colorer/Common.h" -#ifndef COLORER_FEATURE_LIBXML -#include "xercesc/util/XMLString.hpp" -#endif class UStr { @@ -19,12 +16,6 @@ class UStr [[nodiscard]] static std::wstring to_stdwstr(const uUnicodeString& str); #endif -#ifndef COLORER_FEATURE_LIBXML - [[nodiscard]] static std::unique_ptr to_xmlch(const UnicodeString* str); - [[nodiscard]] static std::string to_stdstr(const XMLCh* str); - inline static bool isEmpty(const XMLCh* string) { return *string == '\0'; } -#endif - static std::unique_ptr createCharClass(const UnicodeString& ccs, int pos, int* retPos, bool ignore_case); diff --git a/src/colorer/strings/legacy/UStr.cpp b/src/colorer/strings/legacy/UStr.cpp index 967411e1..927682a7 100644 --- a/src/colorer/strings/legacy/UStr.cpp +++ b/src/colorer/strings/legacy/UStr.cpp @@ -1,28 +1,6 @@ #include "colorer/strings/legacy/UStr.h" #include -#ifndef COLORER_FEATURE_LIBXML -std::string UStr::to_stdstr(const XMLCh* str) -{ - std::string _string = std::string(xercesc::XMLString::transcode(str)); - return _string; -} - -std::unique_ptr UStr::to_xmlch(const UnicodeString* str) -{ - // XMLCh and UChar are the same size - std::unique_ptr out_s; - if (str) { - auto len = str->length(); - out_s = std::make_unique(len + 1); - memcpy(out_s.get(),str->getW2Chars(),len*2); - out_s[len] = 0; - } - return out_s; -} - -#endif - std::string UStr::to_stdstr(const UnicodeString* str) { std::string out_str(str->getChars()); diff --git a/src/colorer/strings/legacy/UStr.h b/src/colorer/strings/legacy/UStr.h index de7e88da..817a2a3f 100644 --- a/src/colorer/strings/legacy/UStr.h +++ b/src/colorer/strings/legacy/UStr.h @@ -3,9 +3,6 @@ #include #include "colorer/Common.h" -#ifndef COLORER_FEATURE_LIBXML -#include -#endif #include "colorer/strings/legacy/CharacterClass.h" class UStr @@ -18,11 +15,6 @@ class UStr [[nodiscard]] static std::wstring to_stdwstr(const UnicodeString* str); [[nodiscard]] static std::wstring to_stdwstr(const UnicodeString& str); -#ifndef COLORER_FEATURE_LIBXML - [[nodiscard]] static std::string to_stdstr(const XMLCh* str); - [[nodiscard]] static std::unique_ptr to_xmlch(const UnicodeString* str); - inline static bool isEmpty(const XMLCh* string) { return *string == '\0'; } -#endif static std::unique_ptr createCharClass(const UnicodeString& ccs, int pos, int* retPos, bool ignore_case); static int8_t caseCompare(const UnicodeString& str1, const UnicodeString& str2); diff --git a/src/colorer/xml/XmlInputSource.cpp b/src/colorer/xml/XmlInputSource.cpp index 8e4f8aeb..14f2fbb3 100644 --- a/src/colorer/xml/XmlInputSource.cpp +++ b/src/colorer/xml/XmlInputSource.cpp @@ -2,23 +2,9 @@ XmlInputSource::XmlInputSource(const UnicodeString& source_path) : XmlInputSource(source_path, nullptr) {} -XmlInputSource::~XmlInputSource() -{ -#ifndef COLORER_FEATURE_LIBXML - //xml_input_source child of xercesc classes and need to free before xercesc - xml_input_source.reset(); - xercesc::XMLPlatformUtils::Terminate(); -#endif -} - XmlInputSource::XmlInputSource(const UnicodeString& source_path, const UnicodeString* source_base) { -#ifdef COLORER_FEATURE_LIBXML xml_input_source = std::make_unique(source_path, source_base); -#else - xercesc::XMLPlatformUtils::Initialize(); - xml_input_source = XercesXmlInputSource::newInstance(&source_path, source_base); -#endif } uXmlInputSource XmlInputSource::createRelative(const UnicodeString& relPath) const @@ -32,13 +18,6 @@ UnicodeString& XmlInputSource::getPath() const return xml_input_source->getPath(); } -#ifndef COLORER_FEATURE_LIBXML -XercesXmlInputSource* XmlInputSource::getInputSource() const -{ - return xml_input_source.get(); -} -#endif - bool XmlInputSource::isFileURI(const UnicodeString& path, const UnicodeString* base) { const UnicodeString jar(u"jar:"); diff --git a/src/colorer/xml/XmlInputSource.h b/src/colorer/xml/XmlInputSource.h index 1d382a58..74773c04 100644 --- a/src/colorer/xml/XmlInputSource.h +++ b/src/colorer/xml/XmlInputSource.h @@ -2,12 +2,7 @@ #define COLORER_XMLINPUTSOURCE_H #include "colorer/Common.h" -#ifdef COLORER_FEATURE_LIBXML #include "colorer/xml/libxml2/LibXmlInputSource.h" -#else -#include "colorer/xml/xercesc/XercesXmlInputSource.h" -#endif - class XmlInputSource; using uXmlInputSource = std::unique_ptr; @@ -16,7 +11,7 @@ class XmlInputSource { public: explicit XmlInputSource(const UnicodeString& source_path); - ~XmlInputSource(); + ~XmlInputSource() = default; XmlInputSource(const UnicodeString& source_path, const UnicodeString* source_base); @@ -26,19 +21,10 @@ class XmlInputSource [[nodiscard]] UnicodeString& getPath() const; -#ifndef COLORER_FEATURE_LIBXML - [[nodiscard]] - XercesXmlInputSource* getInputSource() const; -#endif - static bool isFileURI(const UnicodeString& path, const UnicodeString* base); private: -#ifdef COLORER_FEATURE_LIBXML std::unique_ptr xml_input_source; -#else - uXercesXmlInputSource xml_input_source; -#endif }; #endif // COLORER_XMLINPUTSOURCE_H diff --git a/src/colorer/xml/XmlReader.cpp b/src/colorer/xml/XmlReader.cpp index 6174e88e..ce9fd7bd 100644 --- a/src/colorer/xml/XmlReader.cpp +++ b/src/colorer/xml/XmlReader.cpp @@ -12,11 +12,7 @@ XmlReader::~XmlReader() bool XmlReader::parse() { -#ifdef COLORER_FEATURE_LIBXML xml_reader = new LibXmlReader(*input_source); -#else - xml_reader = new XercesXmlReader(*input_source); -#endif return xml_reader->isParsed(); } diff --git a/src/colorer/xml/XmlReader.h b/src/colorer/xml/XmlReader.h index 4e9eeafb..4dfa3761 100644 --- a/src/colorer/xml/XmlReader.h +++ b/src/colorer/xml/XmlReader.h @@ -3,11 +3,7 @@ #include "colorer/xml/XMLNode.h" #include "colorer/xml/XmlInputSource.h" -#ifdef COLORER_FEATURE_LIBXML #include "libxml2/LibXmlReader.h" -#else -#include "colorer/xml/xercesc/XercesXmlReader.h" -#endif class XmlReader { @@ -19,11 +15,7 @@ class XmlReader private: const XmlInputSource* input_source; -#ifdef COLORER_FEATURE_LIBXML LibXmlReader* xml_reader = nullptr; -#else - XercesXmlReader* xml_reader = nullptr; -#endif }; #endif // COLORER_XMLREADER_H diff --git a/src/colorer/xml/xercesc/BaseEntityResolver.cpp b/src/colorer/xml/xercesc/BaseEntityResolver.cpp deleted file mode 100644 index f7def7bb..00000000 --- a/src/colorer/xml/xercesc/BaseEntityResolver.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "colorer/xml/xercesc/BaseEntityResolver.h" -#include -#include "colorer/Exception.h" -#include "colorer/xml/xercesc/XercesXmlInputSource.h" - -xercesc::InputSource* BaseEntityResolver::resolveEntity(xercesc::XMLResourceIdentifier* resourceIdentifier) -{ - try { - auto input_source = - XercesXmlInputSource::newInstance(resourceIdentifier->getSystemId(), resourceIdentifier->getBaseURI()); - return input_source.release(); - } catch (InputSourceException& e) { - COLORER_LOG_WARN(e.what()); - // Если не можем открыть external entity, то отдаем пустой файл. - // Тем самым гасим ошибку загрузки схемы. Работа продолжится, но раскраска будет не до конца верной. - auto empty_buf = new xercesc::MemBufInputSource((const XMLByte*) "", 0, "dummy"); - return empty_buf; - } -} diff --git a/src/colorer/xml/xercesc/BaseEntityResolver.h b/src/colorer/xml/xercesc/BaseEntityResolver.h deleted file mode 100644 index 2fbeab85..00000000 --- a/src/colorer/xml/xercesc/BaseEntityResolver.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef COLORER_BASE_ENTITY_RESOLVER_H -#define COLORER_BASE_ENTITY_RESOLVER_H - -#include - -class BaseEntityResolver : public xercesc::XMLEntityResolver -{ - public: - xercesc::InputSource* resolveEntity(xercesc::XMLResourceIdentifier* resourceIdentifier) override; -}; - -#endif // COLORER_BASE_ENTITY_RESOLVER_H diff --git a/src/colorer/xml/xercesc/LocalFileXmlInputSource.cpp b/src/colorer/xml/xercesc/LocalFileXmlInputSource.cpp deleted file mode 100644 index cb9154bf..00000000 --- a/src/colorer/xml/xercesc/LocalFileXmlInputSource.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "colorer/xml/xercesc/LocalFileXmlInputSource.h" -#include -#include -#include "colorer/Exception.h" -#include "colorer/utils/Environment.h" - -LocalFileXmlInputSource::LocalFileXmlInputSource(const XMLCh* path, const XMLCh* base) -{ - auto upath = UnicodeString(path); - auto ubase = UnicodeString(base); - - UnicodeString full_path; - if (colorer::Environment::isRegularFile(&ubase, &upath, full_path)) { - source_path = std::make_unique(full_path); - setSystemId(UStr::to_xmlch(&full_path).get()); - // file is not open yet, only after makeStream - } - else { - throw InputSourceException(full_path + " isn't regular file."); - } -} - -xercesc::BinInputStream* LocalFileXmlInputSource::makeStream() const -{ - auto stream = std::make_unique(UStr::to_xmlch(source_path.get()).get()); - if (!stream->getIsOpen()) { - throw InputSourceException("Can't open file '" + this->getPath() + "'"); - } - return stream.release(); -} - -xercesc::InputSource* LocalFileXmlInputSource::getInputSource() const -{ - return (xercesc::InputSource*) this; -} diff --git a/src/colorer/xml/xercesc/LocalFileXmlInputSource.h b/src/colorer/xml/xercesc/LocalFileXmlInputSource.h deleted file mode 100644 index c4456f60..00000000 --- a/src/colorer/xml/xercesc/LocalFileXmlInputSource.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _COLORER_LOCALFILEINPUTSOURCE_H_ -#define _COLORER_LOCALFILEINPUTSOURCE_H_ - -#include "colorer/xml/xercesc/XercesXmlInputSource.h" -#include - -/** - * LocalFileXmlInputSource класс для работы с InputSource - локальными файлами - */ -class LocalFileXmlInputSource : public XercesXmlInputSource -{ - public: - LocalFileXmlInputSource(const XMLCh* path, const XMLCh* base); - ~LocalFileXmlInputSource() override = default; - [[nodiscard]] xercesc::BinInputStream* makeStream() const override; - xercesc::InputSource* getInputSource() const override; - - LocalFileXmlInputSource(LocalFileXmlInputSource const&) = delete; - LocalFileXmlInputSource& operator=(LocalFileXmlInputSource const&) = delete; - LocalFileXmlInputSource(LocalFileXmlInputSource&&) = delete; - LocalFileXmlInputSource& operator=(LocalFileXmlInputSource&&) = delete; - -}; - -#endif //_COLORER_LOCALFILEINPUTSOURCE_H_ diff --git a/src/colorer/xml/xercesc/SharedXmlInputSource.cpp b/src/colorer/xml/xercesc/SharedXmlInputSource.cpp deleted file mode 100644 index 8730b8a4..00000000 --- a/src/colorer/xml/xercesc/SharedXmlInputSource.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "colorer/xml/xercesc/SharedXmlInputSource.h" -#include -#include "colorer/Exception.h" - -std::unordered_map* SharedXmlInputSource::isHash = nullptr; - -int SharedXmlInputSource::addref() -{ - return ++ref_count; -} - -int SharedXmlInputSource::delref() -{ - ref_count--; - if (ref_count <= 0) { - delete this; - return -1; - } - return ref_count; -} - -SharedXmlInputSource::SharedXmlInputSource(uXercesXmlInputSource source) -{ - ref_count = 1; - input_source = std::move(source); - auto pStream = input_source->makeStream(); - // don`t use dynamic_cast, see https://github.com/colorer/Colorer-library/issues/32 - std::unique_ptr bfis( - static_cast(pStream)); - if (bfis == nullptr) { - throw InputSourceException("can`t read " + input_source->getPath()); - } - mSize = static_cast(bfis->getSize()); - mSrc.reset(new XMLByte[mSize]); - bfis->readBytes(mSrc.get(), mSize); -} - -SharedXmlInputSource::~SharedXmlInputSource() -{ - // не нужно удалять объект, удаляемый из массива. мы и так уже в деструкторе - isHash->erase(input_source->getPath()); - if (isHash->empty()) { - delete isHash; - isHash = nullptr; - } -} - -SharedXmlInputSource* SharedXmlInputSource::getSharedInputSource(const XMLCh* path, - const XMLCh* base) -{ - uXercesXmlInputSource tempis = XercesXmlInputSource::newInstance(path, base); - - if (isHash == nullptr) { - isHash = new std::unordered_map(); - } - - UnicodeString d_id = UnicodeString(tempis->getInputSource()->getSystemId()); - auto s = isHash->find(d_id); - if (s != isHash->end()) { - SharedXmlInputSource* sis = s->second; - sis->addref(); - return sis; - } - else { - auto* sis = new SharedXmlInputSource(std::move(tempis)); - isHash->emplace(std::make_pair(d_id, sis)); - return sis; - } -} - -xercesc::InputSource* SharedXmlInputSource::getInputSource() const -{ - return input_source->getInputSource(); -} diff --git a/src/colorer/xml/xercesc/SharedXmlInputSource.h b/src/colorer/xml/xercesc/SharedXmlInputSource.h deleted file mode 100644 index 694132f6..00000000 --- a/src/colorer/xml/xercesc/SharedXmlInputSource.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef _COLORER_SHAREDXMLINPUTSOURCE_H_ -#define _COLORER_SHAREDXMLINPUTSOURCE_H_ - -#include -#include "colorer/Common.h" -#include "colorer/xml/xercesc/XercesXmlInputSource.h" -#include - -class SharedXmlInputSource -{ - public: - static SharedXmlInputSource* getSharedInputSource(const XMLCh* path, const XMLCh* base); - [[nodiscard]] xercesc::InputSource* getInputSource() const; - - /** Increments reference counter */ - int addref(); - /** Decrements reference counter */ - int delref(); - - [[nodiscard]] XMLSize_t getSize() const; - [[nodiscard]] XMLByte* getSrc() const; - - SharedXmlInputSource(SharedXmlInputSource const&) = delete; - SharedXmlInputSource& operator=(SharedXmlInputSource const&) = delete; - SharedXmlInputSource(SharedXmlInputSource&&) = delete; - SharedXmlInputSource& operator=(SharedXmlInputSource&&) = delete; - - private: - explicit SharedXmlInputSource(uXercesXmlInputSource source); - ~SharedXmlInputSource(); - - static std::unordered_map* isHash; - - uXercesXmlInputSource input_source; - int ref_count; - std::unique_ptr mSrc; - XMLSize_t mSize; -}; - -inline XMLSize_t SharedXmlInputSource::getSize() const -{ - return mSize; -} - -inline XMLByte* SharedXmlInputSource::getSrc() const -{ - return mSrc.get(); -} - -#endif //_COLORER_SHAREDXMLINPUTSOURCE_H_ diff --git a/src/colorer/xml/xercesc/XercesXmlInputSource.cpp b/src/colorer/xml/xercesc/XercesXmlInputSource.cpp deleted file mode 100644 index 35fb4c80..00000000 --- a/src/colorer/xml/xercesc/XercesXmlInputSource.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "colorer/xml/xercesc/XercesXmlInputSource.h" -#include "colorer/Exception.h" -#include "colorer/xml/xercesc/LocalFileXmlInputSource.h" -#ifdef COLORER_FEATURE_ZIPINPUTSOURCE -#include "colorer/xml/xercesc/ZipXmlInputSource.h" -#endif - -uXercesXmlInputSource XercesXmlInputSource::newInstance(const UnicodeString* path, const UnicodeString* base) -{ - return newInstance(UStr::to_xmlch(path).get(), UStr::to_xmlch(base).get()); -} - -uXercesXmlInputSource XercesXmlInputSource::newInstance(const XMLCh* path, const XMLCh* base) -{ - if (!path || (*path == '\0')) { - throw InputSourceException("XmlInputSource::newInstance: path is empty"); - } - if (xercesc::XMLString::startsWith(path, kJar) || (base != nullptr && xercesc::XMLString::startsWith(base, kJar))) { -#ifdef COLORER_FEATURE_ZIPINPUTSOURCE - return std::make_unique(path, base); -#else - throw InputSourceException("ZipXmlInputSource not supported"); -#endif - } - return std::make_unique(path, base); -} - -bool XercesXmlInputSource::isUriFile(const UnicodeString& path, const UnicodeString* base) -{ - if ((path.startsWith(kJar)) || (base && base->startsWith(kJar))) { - return false; - } - return true; -} - -uXercesXmlInputSource XercesXmlInputSource::createRelative(const UnicodeString& relPath) -{ - return newInstance(UStr::to_xmlch(&relPath).get(), this->getInputSource()->getSystemId()); -} - -UnicodeString& XercesXmlInputSource::getPath() const -{ - return *source_path; -} diff --git a/src/colorer/xml/xercesc/XercesXmlInputSource.h b/src/colorer/xml/xercesc/XercesXmlInputSource.h deleted file mode 100644 index 6d2488e5..00000000 --- a/src/colorer/xml/xercesc/XercesXmlInputSource.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef COLORER_XERCESXMLINPUTSOURCE_H -#define COLORER_XERCESXMLINPUTSOURCE_H - -#include -#include "colorer/Common.h" - -inline const auto kJar = (const XMLCh *) u"jar:\0"; - -class XercesXmlInputSource; - -typedef std::unique_ptr uXercesXmlInputSource; - -/** - * @brief Class to creat xercesc::InputSource - */ -class XercesXmlInputSource : public xercesc::InputSource -{ - public: - /** - * @brief Tries statically create instance of InputSource object, - * according to passed path string. - * @param path Could be relative file location, absolute file - */ - static uXercesXmlInputSource newInstance(const XMLCh* path, const XMLCh* base); - static uXercesXmlInputSource newInstance(const UnicodeString* path, - const UnicodeString* base = nullptr); - - /** - * @brief Creates inherited InputSource with the same type - * relatively to the current. - * @param relPath Relative URI part. - */ - virtual uXercesXmlInputSource createRelative(const UnicodeString& relPath); - - [[nodiscard]] virtual xercesc::InputSource* getInputSource() const = 0; - - ~XercesXmlInputSource() override = default; - - static bool isUriFile(const UnicodeString& path, const UnicodeString* base = nullptr); - - [[nodiscard]] UnicodeString& getPath() const; - - XercesXmlInputSource(XercesXmlInputSource const&) = delete; - XercesXmlInputSource& operator=(XercesXmlInputSource const&) = delete; - XercesXmlInputSource(XercesXmlInputSource&&) = delete; - XercesXmlInputSource& operator=(XercesXmlInputSource&&) = delete; - - protected: - XercesXmlInputSource() = default; - uUnicodeString source_path; -}; - -#endif // COLORER_XERCESXMLINPUTSOURCE_H diff --git a/src/colorer/xml/xercesc/XercesXmlReader.cpp b/src/colorer/xml/xercesc/XercesXmlReader.cpp deleted file mode 100644 index d0966cf4..00000000 --- a/src/colorer/xml/xercesc/XercesXmlReader.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "colorer/xml/xercesc/XercesXmlReader.h" -#include "colorer/xml/xercesc/BaseEntityResolver.h" -#include "colorer/xml/xercesc/XmlParserErrorHandler.h" - -XercesXmlReader::XercesXmlReader(const XmlInputSource& source) : XercesXmlReader(source.getInputSource()) {} - -XercesXmlReader::XercesXmlReader(const xercesc::InputSource* in) -{ - xercesc::XMLPlatformUtils::Initialize(); - - xml_parser = new xercesc::XercesDOMParser(); - XmlParserErrorHandler error_handler; - BaseEntityResolver resolver; - xml_parser->setErrorHandler(&error_handler); - xml_parser->setXMLEntityResolver(&resolver); - xml_parser->setLoadExternalDTD(false); - xml_parser->setSkipDTDValidation(true); - xml_parser->setDisableDefaultEntityResolution(true); - - xml_parser->parse(*in); - saw_error = error_handler.getSawErrors(); -} - -XercesXmlReader::~XercesXmlReader() -{ - delete xml_parser; - xercesc::XMLPlatformUtils::Terminate(); -} - -void XercesXmlReader::parse(std::list& nodes) -{ - const xercesc::DOMDocument* doc = xml_parser->getDocument(); - const xercesc::DOMElement* root = doc->getDocumentElement(); - - XMLNode result; - populateNode(root, result); - nodes.push_back(result); -} - -bool XercesXmlReader::populateNode(const xercesc::DOMNode* node, XMLNode& result) -{ - if (node->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { - return false; - } - - // don`t use dynamic_cast, see https://github.com/colorer/Colorer-library/issues/32 - const auto* elem = static_cast(node); - result.name = UnicodeString(elem->getNodeName()); - const auto* t = getElementText(elem); - if (t != nullptr) { - result.text = UnicodeString(t); - } - - getChildren(elem, result); - - getAttributes(elem, result.attributes); - - return true; -} - -void XercesXmlReader::getAttributes(const xercesc::DOMElement* node, - std::unordered_map& data) -{ - const auto* attrs = node->getAttributes(); - for (size_t i = 0; i < attrs->getLength(); i++) { - const auto* attr = attrs->item(i); - data.insert(std::pair(UnicodeString(attr->getNodeName()), UnicodeString(attr->getNodeValue()))); - } -} - -void XercesXmlReader::getChildren(const xercesc::DOMNode* node, XMLNode& result) -{ - for (const auto* elem = node->getFirstChild(); elem != nullptr; elem = elem->getNextSibling()) { - if (elem->getNodeType() == xercesc::DOMNode::ENTITY_REFERENCE_NODE) { - getChildren(elem, result); - } - else { - if (XMLNode child; populateNode(elem, child)) { - result.children.push_back(child); - } - } - } -} - -const XMLCh* XercesXmlReader::getElementText(const xercesc::DOMElement* blkel) const -{ - const XMLCh* p = nullptr; - // возможно текст указан как ... - for (xercesc::DOMNode* child = blkel->getFirstChild(); child != nullptr; child = child->getNextSibling()) { - if (child->getNodeType() == xercesc::DOMNode::CDATA_SECTION_NODE) { - // ... блок CDATA: например ![CDATA[ match_regexp ]] - const auto* cdata = static_cast(child); - p = cdata->getData(); - break; - } - if (child->getNodeType() == xercesc::DOMNode::TEXT_NODE) { - // ... текстовый блок match_regexp - const auto* text = static_cast(child); - const XMLCh* p1 = text->getData(); - auto* temp_string = xercesc::XMLString::replicate(p1); - // перед блоком CDATA могут быть пустые строки, учитываем это - xercesc::XMLString::trim(temp_string); - if (*temp_string != '\0') { - p = p1; - xercesc::XMLString::release(&temp_string); - break; - } - xercesc::XMLString::release(&temp_string); - } - } - return p; -} diff --git a/src/colorer/xml/xercesc/XercesXmlReader.h b/src/colorer/xml/xercesc/XercesXmlReader.h deleted file mode 100644 index 3aab00aa..00000000 --- a/src/colorer/xml/xercesc/XercesXmlReader.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef COLORER_XERCESXML_H -#define COLORER_XERCESXML_H - -#include -#include -#include -#include -#include "colorer/Common.h" -#include "colorer/xml/XMLNode.h" -#include "colorer/xml/XmlInputSource.h" - -class XercesXmlReader -{ - public: - - explicit XercesXmlReader(const xercesc::InputSource* in); - explicit XercesXmlReader(const XmlInputSource& source); - - void parse(std::list& nodes); - - ~XercesXmlReader(); - - [[nodiscard]] bool isParsed() const - { - return !saw_error; - } - - private: - bool saw_error = false; - bool populateNode(const xercesc::DOMNode* node, XMLNode& result); - void getAttributes(const xercesc::DOMElement* node, std::unordered_map& data); - void getChildren(const xercesc::DOMNode* node, XMLNode& result); - const XMLCh* getElementText(const xercesc::DOMElement* blkel) const; - - xercesc::XercesDOMParser* xml_parser; -}; -#endif // COLORER_XERCESXML_H diff --git a/src/colorer/xml/xercesc/XmlParserErrorHandler.cpp b/src/colorer/xml/xercesc/XmlParserErrorHandler.cpp deleted file mode 100644 index 8fec6750..00000000 --- a/src/colorer/xml/xercesc/XmlParserErrorHandler.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "colorer/xml/xercesc/XmlParserErrorHandler.h" -#include "colorer/Common.h" - -void XmlParserErrorHandler::warning(const xercesc::SAXParseException& toCatch) -{ - COLORER_LOG_WARN("Warning at file %, line %, column %. Message: %", - UStr::to_stdstr(toCatch.getSystemId()), toCatch.getLineNumber(), - toCatch.getColumnNumber(), UStr::to_stdstr(toCatch.getMessage())); -} - -void XmlParserErrorHandler::error(const xercesc::SAXParseException& toCatch) -{ - fSawErrors = true; - COLORER_LOG_ERROR("Error at file %, line %, column %. Message: %", - UStr::to_stdstr(toCatch.getSystemId()), toCatch.getLineNumber(), - toCatch.getColumnNumber(), UStr::to_stdstr(toCatch.getMessage())); -} - -void XmlParserErrorHandler::fatalError(const xercesc::SAXParseException& toCatch) -{ - fSawErrors = true; - COLORER_LOG_ERROR("Fatal error at file %, line %, column %. Message: %", - UStr::to_stdstr(toCatch.getSystemId()), toCatch.getLineNumber(), - toCatch.getColumnNumber(), UStr::to_stdstr(toCatch.getMessage())); -} - -bool XmlParserErrorHandler::getSawErrors() const -{ - return fSawErrors; -} - -void XmlParserErrorHandler::resetErrors() -{ - fSawErrors = false; -} diff --git a/src/colorer/xml/xercesc/XmlParserErrorHandler.h b/src/colorer/xml/xercesc/XmlParserErrorHandler.h deleted file mode 100644 index 51e6e2aa..00000000 --- a/src/colorer/xml/xercesc/XmlParserErrorHandler.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef COLORER_XML_PARSER_ERROR_HANDLER_H -#define COLORER_XML_PARSER_ERROR_HANDLER_H - -#include -#include - -/* XmlParserErrorHandler - class to catch errors and warnings from the XML Parser*/ -class XmlParserErrorHandler : public xercesc::ErrorHandler -{ - public: - XmlParserErrorHandler() : fSawErrors {false} {} - - void warning(const xercesc::SAXParseException& toCatch) override; - void error(const xercesc::SAXParseException& toCatch) override; - void fatalError(const xercesc::SAXParseException& toCatch) override; - void resetErrors() override; - [[nodiscard]] bool getSawErrors() const; - - private: - /* fSawErrors - This is set if we get any errors, and is queryable via a getter - method. Its used by the main code to suppress output if there are - errors. */ - bool fSawErrors; -}; - -#endif // COLORER_XML_PARSER_ERROR_HANDLER_H diff --git a/src/colorer/xml/xercesc/ZipXmlInputSource.cpp b/src/colorer/xml/xercesc/ZipXmlInputSource.cpp deleted file mode 100644 index da4212e5..00000000 --- a/src/colorer/xml/xercesc/ZipXmlInputSource.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include "colorer/xml/xercesc/ZipXmlInputSource.h" -#include "colorer/Exception.h" -#include "colorer/utils/Environment.h" -#include "colorer/zip/MemoryFile.h" - -ZipXmlInputSource::ZipXmlInputSource(const XMLCh* path, const XMLCh* base) -{ - create(path, base); -} - -void ZipXmlInputSource::create(const XMLCh* path, const XMLCh* base) -{ - const auto kJar_len = xercesc::XMLString::stringLen(kJar); - if (xercesc::XMLString::startsWith(path, kJar)) { - int path_idx = xercesc::XMLString::lastIndexOf(path, '!'); - if (path_idx == -1) { - throw InputSourceException("Bad jar uri format: " + UnicodeString(path)); - } - - auto bpath = std::make_unique(path_idx - kJar_len + 1); - xercesc::XMLString::subString(bpath.get(), path, kJar_len, path_idx); - jar_input_source = SharedXmlInputSource::getSharedInputSource(bpath.get(), base); - - in_jar_location = UnicodeString(UnicodeString(path), path_idx + 1); - } - else if (base != nullptr && xercesc::XMLString::startsWith(base, kJar)) { - int base_idx = xercesc::XMLString::lastIndexOf(base, '!'); - if (base_idx == -1) { - throw InputSourceException("Bad jar uri format: " + UnicodeString(path)); - } - - auto bpath = std::make_unique(base_idx - kJar_len + 1); - xercesc::XMLString::subString(bpath.get(), base, kJar_len, base_idx); - jar_input_source = SharedXmlInputSource::getSharedInputSource(bpath.get(), nullptr); - - auto in_base = std::make_unique(UnicodeString(base), base_idx + 1); - in_jar_location = colorer::Environment::getAbsolutePath(*in_base.get(), UnicodeString(path)); - } - else { - throw InputSourceException("Can't create jar source"); - } - - UnicodeString str("jar:"); - str.append(UnicodeString(jar_input_source->getInputSource()->getSystemId())); - str.append("!"); - str.append(in_jar_location); - setSystemId(UStr::to_xmlch(&str).get()); - source_path = std::make_unique(str); -} - -ZipXmlInputSource::~ZipXmlInputSource() -{ - jar_input_source->delref(); -} - -xercesc::InputSource* ZipXmlInputSource::getInputSource() const -{ - return (xercesc::InputSource*) this; -} - -xercesc::BinInputStream* ZipXmlInputSource::makeStream() const -{ - return new UnZip(jar_input_source->getSrc(), jar_input_source->getSize(), &in_jar_location); -} - -UnZip::UnZip(const XMLByte* src, XMLSize_t size, const UnicodeString* path) : mPos(0), stream(nullptr) -{ - stream = unzip(src, static_cast(size), *path); -} - -XMLFilePos UnZip::curPos() const -{ - return mPos; -} - -XMLSize_t UnZip::readBytes(XMLByte* const toFill, const XMLSize_t maxToRead) -{ - XMLSize_t mBoundary = stream->size(); - XMLSize_t remain = mBoundary - mPos; - XMLSize_t toRead = (maxToRead < remain) ? maxToRead : remain; - memcpy(toFill, stream->data() + mPos, toRead); - mPos += toRead; - return toRead; -} - -const XMLCh* UnZip::getContentType() const -{ - return nullptr; -} - -UnZip::~UnZip() = default; diff --git a/src/colorer/xml/xercesc/ZipXmlInputSource.h b/src/colorer/xml/xercesc/ZipXmlInputSource.h deleted file mode 100644 index 403651d7..00000000 --- a/src/colorer/xml/xercesc/ZipXmlInputSource.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef _COLORER_ZIPINPUTSOURCE_H_ -#define _COLORER_ZIPINPUTSOURCE_H_ - -#include -#include -#include "colorer/xml/xercesc/SharedXmlInputSource.h" -#include "colorer/xml/xercesc/XercesXmlInputSource.h" - -class ZipXmlInputSource : public XercesXmlInputSource -{ - public: - ZipXmlInputSource(const XMLCh* path, const XMLCh* base); - ~ZipXmlInputSource() override; - [[nodiscard]] xercesc::BinInputStream* makeStream() const override; - xercesc::InputSource* getInputSource() const override; - - ZipXmlInputSource(ZipXmlInputSource const&) = delete; - ZipXmlInputSource& operator=(ZipXmlInputSource const&) = delete; - ZipXmlInputSource(ZipXmlInputSource&&) = delete; - ZipXmlInputSource& operator=(ZipXmlInputSource&&) = delete; - - private: - void create(const XMLCh* path, const XMLCh* base); - UnicodeString in_jar_location; - SharedXmlInputSource* jar_input_source = nullptr; -}; - -class UnZip : public xercesc::BinInputStream -{ - public: - UnZip(const XMLByte* src, XMLSize_t size, const UnicodeString* path); - ~UnZip() override; - - [[nodiscard]] XMLFilePos curPos() const override; - XMLSize_t readBytes(XMLByte* toFill, XMLSize_t maxToRead) override; - [[nodiscard]] const XMLCh* getContentType() const override; - - UnZip(UnZip const&) = delete; - UnZip& operator=(UnZip const&) = delete; - UnZip(UnZip&&) = delete; - UnZip& operator=(UnZip&&) = delete; - - private: - XMLSize_t mPos; - std::unique_ptr> stream; -}; - -#endif //_COLORER_ZIPINPUTSOURCE_H_ diff --git a/vcpkg.json b/vcpkg.json index 2827ec6c..dc8ee6e2 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -2,10 +2,6 @@ "name": "colorer", "version": "1.3.1", "dependencies": [ - { - "name": "xerces-c", - "version>=": "3.2.5#0" - }, "minizip", { "name": "icu",