mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-13 08:58:52 +00:00
a44caf65fe Merge bitcoin-core/univalue-subtree#28: Import fixes for sanitizer reported issues 135254331e Import fixes for sanitizer reported issues d5fb86940e refactor: use c++11 range based for loop in checkObject ff9c379304 refactor: Use nullptr (c++11) instead of NULL 08a99754d5 build: use ax_cxx_compile_stdcxx.m4 to check for C++11 support 66d3713ce7 Merge bitcoin-core/univalue#29: ci: travis -> cirrus 808d487292 ci: travis -> cirrus c390ac375f Merge bitcoin-core/univalue#19: Split sources for easier buildsystem integration 4a5b0a1c65 build: Move source entries out to sources.mk 6c7d94b33c build: cleanup wonky gen usage a222637c6d Merge #23: Merge changes from jgarzik/univalue@1ae6a23 f77d0f718d Merge commit '1ae6a231a0169938eb3972c1d48dd17cba5947e1' into HEAD 1ae6a231a0 Merge pull request #57 from MarcoFalke/test_fix 92bdd11f0b univalue_write: remove unneeded sstream.h include ffb621c130 Merge pull request #56 from drodil/remove_sstream_header f33acf9fe8 Merge commit '7890db9~' into HEAD 66e0adec4d Remove unnecessary sstream header from univalue.h 88967f6586 Version 1.0.4 1dc113dbef Merge pull request #50 from luke-jr/pushKV_bool 72392fb227 [tests] test pushKV for boolean values c23132bcf4 Pushing boolean value to univalue correctly 81faab26a1 Merge pull request #48 from fwolfst/47-UPDATE_MIT_LINK_TO_HTTPS b17634ef24 Update URLs to MIT license. 88ab64f6b5 Merge pull request #46 from jasonbcox/master 35ed96da31 Merge pull request #44 from MarcoFalke/Mf1709-univalue-cherrypick-explicit 420c226290 Merge pull request #45 from MarcoFalke/Mf1710-univalue-revert-test git-subtree-dir: src/univalue git-subtree-split: a44caf65fe55b9dd8ddb08f04c0f70409efd53b3
83 lines
1.8 KiB
C++
83 lines
1.8 KiB
C++
// Copyright 2014 BitPay Inc.
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or https://opensource.org/licenses/mit-license.php.
|
|
|
|
//
|
|
// To re-create univalue_escapes.h:
|
|
// $ g++ -o gen gen.cpp
|
|
// $ ./gen > univalue_escapes.h
|
|
//
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "univalue.h"
|
|
|
|
static bool initEscapes;
|
|
static std::string escapes[256];
|
|
|
|
static void initJsonEscape()
|
|
{
|
|
// Escape all lower control characters (some get overridden with smaller sequences below)
|
|
for (int ch=0x00; ch<0x20; ++ch) {
|
|
char tmpbuf[20];
|
|
snprintf(tmpbuf, sizeof(tmpbuf), "\\u%04x", ch);
|
|
escapes[ch] = std::string(tmpbuf);
|
|
}
|
|
|
|
escapes[(int)'"'] = "\\\"";
|
|
escapes[(int)'\\'] = "\\\\";
|
|
escapes[(int)'\b'] = "\\b";
|
|
escapes[(int)'\f'] = "\\f";
|
|
escapes[(int)'\n'] = "\\n";
|
|
escapes[(int)'\r'] = "\\r";
|
|
escapes[(int)'\t'] = "\\t";
|
|
escapes[(int)'\x7f'] = "\\u007f"; // U+007F DELETE
|
|
|
|
initEscapes = true;
|
|
}
|
|
|
|
static void outputEscape()
|
|
{
|
|
printf( "// Automatically generated file. Do not modify.\n"
|
|
"#ifndef BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H\n"
|
|
"#define BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H\n"
|
|
"static const char *escapes[256] = {\n");
|
|
|
|
for (unsigned int i = 0; i < 256; i++) {
|
|
if (escapes[i].empty()) {
|
|
printf("\tnullptr,\n");
|
|
} else {
|
|
printf("\t\"");
|
|
|
|
unsigned int si;
|
|
for (si = 0; si < escapes[i].size(); si++) {
|
|
char ch = escapes[i][si];
|
|
switch (ch) {
|
|
case '"':
|
|
printf("\\\"");
|
|
break;
|
|
case '\\':
|
|
printf("\\\\");
|
|
break;
|
|
default:
|
|
printf("%c", escapes[i][si]);
|
|
break;
|
|
}
|
|
}
|
|
|
|
printf("\",\n");
|
|
}
|
|
}
|
|
|
|
printf( "};\n"
|
|
"#endif // BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H\n");
|
|
}
|
|
|
|
int main (int argc, char *argv[])
|
|
{
|
|
initJsonEscape();
|
|
outputEscape();
|
|
return 0;
|
|
}
|
|
|