Commit 8d2f4628 authored by jan.koester's avatar jan.koester
Browse files

added htmlencode support

parent 635f075e
Loading
Loading
Loading
Loading
+1 −0
Changes for src/CMakeLists.txt: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ install(FILES
    request.h
    utils.h
    exception.h
    encode.h
    "${CMAKE_BINARY_DIR}/config.h"
    "${CMAKE_CURRENT_BINARY_DIR}/htmlpp_export.h"
    DESTINATION include/htmlpp

src/encode.h

0 → 100644
+39 −0
Changes for src/encode.h: 39 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*******************************************************************************
Copyright (c) 2014, Jan Koester jan.koester@gmx.net
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the <organization> nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/

#pragma once

namespace libhtmlpp {
    const char *HtmlSigns[][2]={
        {"\"","&quot;"},
        {"&","&amp;"},
        {"<","&lt;"},
        {">","&gt;"},
        {"'","&apos;"},
        {nullptr,nullptr}
    };
};
+18 −0
Changes for src/html.cpp: 18 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -45,6 +45,24 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define HTMLCOMMENT 2
#define HTMLHEADER 3

void libhtmlpp::HtmlEncode(const char* input, std::string& output){
    size_t ilen=strlen(input);
    for(size_t i=0; i<ilen; ++i){
        size_t ii=0;
        bool changed=false;
        while(HtmlSigns[ii][0]){
            if(input[i]==HtmlSigns[ii][0][0]){
                output.append(HtmlSigns[ii][1]);
                changed=true;
            }
            ++ii;
        }
        if(!changed)
            output.push_back(input[i]);
    }
}


namespace libhtmlpp {
    class DocElements {
    public:
+4 −0
Changes for src/html.h: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string>
#include <cstring>

#include "encode.h"

#pragma once

namespace libhtmlpp {
@@ -41,6 +43,8 @@ namespace libhtmlpp {
        HtmlEl=1
    };

    void HtmlEncode(const char *input,std::string &output);

    class Element {
    public:
        Element();