/usr/include/modp_xml.h is in libmodpbase64-dev 3.10.3+git20160924-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | /**
* \file modp_xml.h
* \brief Experimental XML/HTML decoder
*
* This is mostly experimental.
*/
/*
* <PRE>
* High Performance XML Decoder (for now)
*
* Copyright © 2012-2016 Nick Galbreath
* All rights reserved.
*
* Released under MIT license. See LICENSE fro details.
*
* https://github.com/client9/stringencoders
*
* </PRE>
*/
#ifndef COM_MODP_STRINGENCODERS_XML
#define COM_MODP_STRINGENCODERS_XML
#include "modp_stdint.h"
#ifdef __cplusplus
#define BEGIN_C extern "C" {
#define END_C }
#else
#define BEGIN_C
#define END_C
#endif
BEGIN_C
/**
* \brief Validates a unicode code point is valid for HTML (undefined
* or non-white-space control char)
*
* \param[in] val a unicode char expressed as a uint32_t
* \return 0 if invalid, else returns passes back the input value.
*
* See http://www.whatwg.org/specs/web-apps/current-work/multipage/syntax.html#character-references for more details
*
* This is only exposed for testing. It is not designed for public use.
*/
int modp_xml_validate_unicode(int val);
/**
* \brief converts a unicode char expressed as uint32_t into a UTF-8 byte sequence.
* \param[out] dest assumed to have at least 4 chars available in buffer.
* \param[in] uval A unicode character expressed as a uint32_t type
* \return 0 if input value is invalid or not a unicode character, else
* returns number of bytes written to dest.
*
* This is only exposed for testing. It is not designed for public use.
*/
size_t modp_xml_unicode_char_to_utf8(char* dest, int uval);
/**
* \brief parse a hex encoded entity between "&#x" and ";"
* \param[in] s a buffer pointing at the first char after "&$x"
* \param[in] len the length of string between "&#x" and ";"
* \return -1 if invalid, otherwise the unicode character value
*
* This is only exposed for testing. It is not designed for public use.
*/
int modp_xml_parse_hex_entity(const char* s, size_t len);
/**
* \brief parse a numerical decimal XML entity, eg. &x39;
*
* \param[in] s the buffer pointing to first char after '&#'.
* \param[in] len the length between '&#' and ';'. It is expected
* that all chars between are to be decimal digits.
* \return -1 if invalid, else the unicode numeric value
*
* Exposed for testing. Not designed to be useful for public consumption.
*/
int modp_xml_parse_dec_entity(const char* s, size_t len);
/**
* \brief XML decode a string
* \param[out] dest output string. Must
* \param[in] str The input string
* \param[in] len The length of the input string, excluding any
* final null byte.
* \return the final size of the output, excluding any ending null byte.
*
* Decode numerical entities (decimal or hexadecimal), and following named
* entities:
* * '
* * "
* * &
* * <
* * >
*
*/
size_t modp_xml_decode(char* dest, const char* str, size_t len);
/**
* \brief XML encode a UTF-8 string
* \param[out] dest output string.
* \param[in] str The input string
* \param[in] len The length of the input string, excluding any
* final null byte.
* \return the final size of the output, excluding any ending null byte.
* Encodes an assumed valid UTF-8 input and escapes
* * '
* * "
* * &
* * <
* * >
*/
size_t modp_xml_encode(char* dest, const char* str, size_t len);
size_t modp_xml_min_encode_strlen(const char* str, size_t len);
END_C
#ifdef __cplusplus
#include <cstring>
#include <string>
namespace modp {
/**
* Url decode a string.
* This function does not allocate memory.
*
* \param[in,out] s the string to be decoded
* \return a reference to the input string.
* There is no error case, bad characters are passed through
*/
inline std::string& xml_decode(std::string& s)
{
size_t d = modp_xml_decode(const_cast<char*>(s.data()), s.data(), s.size());
s.erase(d, std::string::npos);
return s;
}
inline std::string xml_decode(const char* str)
{
std::string s(str);
xml_decode(s);
return s;
}
inline std::string xml_decode(const char* str, size_t len)
{
std::string s(str, len);
xml_decode(s);
return s;
}
inline std::string xml_decode(const std::string& s)
{
std::string x(s);
xml_decode(x);
return x;
}
}
#endif
#endif
|