/usr/include/modp_bjavascript.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 | /**
* \file modp_bjavascript.h
* \brief "C-string" to "javascript-string" encoder
*
* Used in emitting dynamically-generated javascript. Given a regular
* C-string which might contain binary, the encoder will emit a string
* that can be used inside a javascript string. For example:
*
* \code
* printf("var foo = '%s';", modp_bjavascript_encode(mystring, len));
* \endcode
*
* The "b" in "modp_bjavascript" is due to legacy reasons. It doesn't
* mean anything
*
* There is no decoder.
*/
/*
* <PRE>
* High Performance c-string to javascript-string encoder
*
* Copyright © 2006-2016 Nick Galbreath
* All rights reserved.
*
* https://github.com/client9/stringencoders
*
* Released under MIT license. See LICENSE for details.
* </PRE>
*/
#ifndef COM_MODP_STRINGENCODERS_BJAVASCRIPT
#define COM_MODP_STRINGENCODERS_BJAVASCRIPT
#include "modp_stdint.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* "javascript" encode a stirng
* This takes a c-string and does character escaping
* so it can be put into a var js_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.
*/
size_t modp_bjavascript_encode(char* dest, const char* str, size_t len);
#define modp_bjavascript_encode_len(A) (4 * A + 1)
/**
* Given the exact size of output string.
*
* Can be used to allocate the right amount of memory for
* modp_burl_encode. Be sure to add 1 byte for final null.
*
* This is somewhat expensive since it examines every character
* in the input string
*
* \param[in] str The input string
* \param[in] len THe length of the input string, excluding any
* final null byte (i.e. strlen(str))
* \return the size of the output string, excluding the final
* null byte.
*/
size_t modp_bjavascript_encode_strlen(const char* str, size_t len);
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
#include <cstring>
#include <string>
namespace modp {
inline std::string javascript_encode(const char* s, size_t len)
{
std::string x(modp_bjavascript_encode_len(len), '\0');
size_t d = modp_bjavascript_encode(const_cast<char*>(x.data()), s, len);
x.erase(d, std::string::npos);
return x;
}
inline std::string javascript_encode(const char* s)
{
return javascript_encode(s, strlen(s));
}
inline std::string& javascript_encode(std::string& s)
{
std::string x(javascript_encode(s.data(), s.size()));
s.swap(x);
return s;
}
inline std::string javascript_encode(const std::string& s)
{
return javascript_encode(s.data(), s.size());
}
} /* namespace modp */
#endif /* __cplusplus */
#endif /* modp_bjavascript */
|