mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-30 15:54:03 +02:00
refactor: cleanups post unsubtree'ing univalue
Mostly changes to remove src/univalue exceptions from the various linters, and the required code changes to make them happy. As well as minor doc changes.
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or https://opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef __UNIVALUE_H__
|
||||
#define __UNIVALUE_H__
|
||||
#ifndef BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_H
|
||||
#define BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_H
|
||||
|
||||
#include <charconv>
|
||||
#include <cstdint>
|
||||
@@ -194,4 +194,4 @@ extern const UniValue NullUniValue;
|
||||
|
||||
const UniValue& find_value( const UniValue& obj, const std::string& name);
|
||||
|
||||
#endif // __UNIVALUE_H__
|
||||
#endif // BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_H
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// Automatically generated file. Do not modify.
|
||||
#ifndef BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H
|
||||
#define BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H
|
||||
#ifndef BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_ESCAPES_H
|
||||
#define BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_ESCAPES_H
|
||||
static const char *escapes[256] = {
|
||||
"\\u0000",
|
||||
"\\u0001",
|
||||
@@ -259,4 +258,4 @@ static const char *escapes[256] = {
|
||||
nullptr,
|
||||
nullptr,
|
||||
};
|
||||
#endif // BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H
|
||||
#endif // BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_ESCAPES_H
|
||||
@@ -1,8 +1,8 @@
|
||||
// Copyright 2016 Wladimir J. van der Laan
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or https://opensource.org/licenses/mit-license.php.
|
||||
#ifndef UNIVALUE_UTFFILTER_H
|
||||
#define UNIVALUE_UTFFILTER_H
|
||||
#ifndef BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_UTFFILTER_H
|
||||
#define BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_UTFFILTER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -116,4 +116,4 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_UTFFILTER_H
|
||||
@@ -3,7 +3,7 @@
|
||||
// file COPYING or https://opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <univalue.h>
|
||||
#include "univalue_utffilter.h"
|
||||
#include <univalue_utffilter.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdint>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// file COPYING or https://opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <univalue.h>
|
||||
#include "univalue_escapes.h"
|
||||
#include <univalue_escapes.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
@@ -12,10 +12,8 @@ UNIVALUE_INCLUDE_DIR_INT = %reldir%/include
|
||||
|
||||
UNIVALUE_DIST_HEADERS_INT =
|
||||
UNIVALUE_DIST_HEADERS_INT += %reldir%/include/univalue.h
|
||||
|
||||
UNIVALUE_LIB_HEADERS_INT =
|
||||
UNIVALUE_LIB_HEADERS_INT += %reldir%/lib/univalue_utffilter.h
|
||||
UNIVALUE_LIB_HEADERS_INT += %reldir%/lib/univalue_escapes.h
|
||||
UNIVALUE_DIST_HEADERS_INT += %reldir%/include/univalue_utffilter.h
|
||||
UNIVALUE_DIST_HEADERS_INT += %reldir%/include/univalue_escapes.h
|
||||
|
||||
UNIVALUE_LIB_SOURCES_INT =
|
||||
UNIVALUE_LIB_SOURCES_INT += %reldir%/lib/univalue.cpp
|
||||
|
||||
@@ -12,15 +12,7 @@
|
||||
#error JSON_TEST_SRC must point to test source directory
|
||||
#endif
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
#endif
|
||||
|
||||
std::string srcdir(JSON_TEST_SRC);
|
||||
static bool test_failed = false;
|
||||
|
||||
#define d_assert(expr) { if (!(expr)) { test_failed = true; fprintf(stderr, "%s failed\n", filename.c_str()); } }
|
||||
#define f_assert(expr) { if (!(expr)) { test_failed = true; fprintf(stderr, "%s failed\n", __func__); } }
|
||||
|
||||
static std::string rtrim(std::string s)
|
||||
{
|
||||
@@ -41,9 +33,9 @@ static void runtest(std::string filename, const std::string& jdata)
|
||||
bool testResult = val.read(jdata);
|
||||
|
||||
if (wantPass) {
|
||||
d_assert(testResult == true);
|
||||
assert(testResult == true);
|
||||
} else {
|
||||
d_assert(testResult == false);
|
||||
assert(testResult == false);
|
||||
}
|
||||
|
||||
if (wantRoundTrip) {
|
||||
@@ -141,30 +133,30 @@ void unescape_unicode_test()
|
||||
bool testResult;
|
||||
// Escaped ASCII (quote)
|
||||
testResult = val.read("[\"\\u0022\"]");
|
||||
f_assert(testResult);
|
||||
f_assert(val[0].get_str() == "\"");
|
||||
assert(testResult);
|
||||
assert(val[0].get_str() == "\"");
|
||||
// Escaped Basic Plane character, two-byte UTF-8
|
||||
testResult = val.read("[\"\\u0191\"]");
|
||||
f_assert(testResult);
|
||||
f_assert(val[0].get_str() == "\xc6\x91");
|
||||
assert(testResult);
|
||||
assert(val[0].get_str() == "\xc6\x91");
|
||||
// Escaped Basic Plane character, three-byte UTF-8
|
||||
testResult = val.read("[\"\\u2191\"]");
|
||||
f_assert(testResult);
|
||||
f_assert(val[0].get_str() == "\xe2\x86\x91");
|
||||
assert(testResult);
|
||||
assert(val[0].get_str() == "\xe2\x86\x91");
|
||||
// Escaped Supplementary Plane character U+1d161
|
||||
testResult = val.read("[\"\\ud834\\udd61\"]");
|
||||
f_assert(testResult);
|
||||
f_assert(val[0].get_str() == "\xf0\x9d\x85\xa1");
|
||||
assert(testResult);
|
||||
assert(val[0].get_str() == "\xf0\x9d\x85\xa1");
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
for (unsigned int fidx = 0; fidx < ARRAY_SIZE(filenames); fidx++) {
|
||||
runtest_file(filenames[fidx]);
|
||||
for (const auto& f: filenames) {
|
||||
runtest_file(f);
|
||||
}
|
||||
|
||||
unescape_unicode_test();
|
||||
|
||||
return test_failed ? 1 : 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user