Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

gen.cpp
Go to the documentation of this file.
1 // Copyright 2014 BitPay Inc.
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 //
6 // To re-create univalue_escapes.h:
7 // $ g++ -o gen gen.cpp
8 // $ ./gen > univalue_escapes.h
9 //
10 
11 #include <stdio.h>
12 #include <string.h>
13 #include "univalue.h"
14 
15 using namespace std;
16 
17 static bool initEscapes;
18 static std::string escapes[256];
19 
20 static void initJsonEscape()
21 {
22  // Escape all lower control characters (some get overridden with smaller sequences below)
23  for (int ch=0x00; ch<0x20; ++ch) {
24  char tmpbuf[20];
25  snprintf(tmpbuf, sizeof(tmpbuf), "\\u%04x", ch);
26  escapes[ch] = std::string(tmpbuf);
27  }
28 
29  escapes[(int)'"'] = "\\\"";
30  escapes[(int)'\\'] = "\\\\";
31  escapes[(int)'\b'] = "\\b";
32  escapes[(int)'\f'] = "\\f";
33  escapes[(int)'\n'] = "\\n";
34  escapes[(int)'\r'] = "\\r";
35  escapes[(int)'\t'] = "\\t";
36  escapes[(int)'\x7f'] = "\\u007f"; // U+007F DELETE
37 
38  initEscapes = true;
39 }
40 
41 static void outputEscape()
42 {
43  printf( "// Automatically generated file. Do not modify.\n"
44  "#ifndef BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H\n"
45  "#define BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H\n"
46  "static const char *escapes[256] = {\n");
47 
48  for (unsigned int i = 0; i < 256; i++) {
49  if (escapes[i].empty()) {
50  printf("\tNULL,\n");
51  } else {
52  printf("\t\"");
53 
54  unsigned int si;
55  for (si = 0; si < escapes[i].size(); si++) {
56  char ch = escapes[i][si];
57  switch (ch) {
58  case '"':
59  printf("\\\"");
60  break;
61  case '\\':
62  printf("\\\\");
63  break;
64  default:
65  printf("%c", escapes[i][si]);
66  break;
67  }
68  }
69 
70  printf("\",\n");
71  }
72  }
73 
74  printf( "};\n"
75  "#endif // BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H\n");
76 }
77 
78 int main (int argc, char *argv[])
79 {
81  outputEscape();
82  return 0;
83 }
84 
int main(int argc, char *argv[])
Definition: gen.cpp:78
static std::string escapes[256]
Definition: gen.cpp:18
Definition: box.hpp:161
static void outputEscape()
Definition: gen.cpp:41
const impl< T, B, MP > empty
static void initJsonEscape()
Definition: gen.cpp:20
static bool initEscapes
Definition: gen.cpp:17
void printf(const char *fmt, const Args &... args)
Format list of arguments to std::cout, according to the given format string.
Definition: tinyformat.h:984
Released under the MIT license