From 90532c2424345f991cbf7c2521e4baeace95eb07 Mon Sep 17 00:00:00 2001 From: Daniel Parker Date: Tue, 7 Jan 2025 18:39:40 -0500 Subject: [PATCH] tidy includes --- include/jsoncons/detail/string_view.hpp | 6 +- include/jsoncons/ser_context.hpp | 2 + include/jsoncons/utility/bigint.hpp | 2 +- include/jsoncons_ext/bson/bson_decimal128.hpp | 18 ++-- include/jsoncons_ext/bson/bson_parser.hpp | 2 +- .../jsoncons_ext/jsonpointer/jsonpointer.hpp | 2 +- .../jsonschema/common/keyword_validators.hpp | 24 +++--- .../jsonschema/common/schema_builder.hpp | 8 +- .../draft202012/schema_builder_202012.hpp | 2 +- test/thirdparty/catch/catch.hpp | 86 +++++++++---------- 10 files changed, 77 insertions(+), 75 deletions(-) diff --git a/include/jsoncons/detail/string_view.hpp b/include/jsoncons/detail/string_view.hpp index 65843671c2..2955801e4e 100644 --- a/include/jsoncons/detail/string_view.hpp +++ b/include/jsoncons/detail/string_view.hpp @@ -540,12 +540,12 @@ namespace std { template struct hash> { - size_t operator()(const jsoncons::detail::basic_string_view& s) const noexcept + std::size_t operator()(const jsoncons::detail::basic_string_view& s) const noexcept { const int p = 53; const int m = 1000000009; - size_t hash_value = 0; - size_t p_pow = 1; + std::size_t hash_value = 0; + std::size_t p_pow = 1; for (CharT c : s) { hash_value = (hash_value + (c - 'a' + 1) * p_pow) % m; p_pow = (p_pow * p) % m; diff --git a/include/jsoncons/ser_context.hpp b/include/jsoncons/ser_context.hpp index 8812a855e6..a23527d927 100644 --- a/include/jsoncons/ser_context.hpp +++ b/include/jsoncons/ser_context.hpp @@ -7,6 +7,8 @@ #ifndef JSONCONS_SER_CONTEXT_HPP #define JSONCONS_SER_CONTEXT_HPP +#include + namespace jsoncons { class ser_context diff --git a/include/jsoncons/utility/bigint.hpp b/include/jsoncons/utility/bigint.hpp index 9a3cf2eb7b..8af406cbf1 100644 --- a/include/jsoncons/utility/bigint.hpp +++ b/include/jsoncons/utility/bigint.hpp @@ -1001,7 +1001,7 @@ class basic_bigint : protected detail::basic_bigint_base { basic_bigint v(*this); - size_t len = (v.length() * basic_type_bits / 3) + 2; + std::size_t len = (v.length() * basic_type_bits / 3) + 2; data.reserve(len); static uint64_t p10 = 1; diff --git a/include/jsoncons_ext/bson/bson_decimal128.hpp b/include/jsoncons_ext/bson/bson_decimal128.hpp index 6564ec12b5..5434e78020 100644 --- a/include/jsoncons_ext/bson/bson_decimal128.hpp +++ b/include/jsoncons_ext/bson/bson_decimal128.hpp @@ -582,18 +582,18 @@ namespace jsoncons { namespace bson { bool includes_sign = false; /* True if the input first contains a sign. */ bool found_nonzero = false; - size_t significant_digits = 0; /* Total number of significant digits + std::size_t significant_digits = 0; /* Total number of significant digits * (no leading or trailing zero) */ - size_t ndigits_read = 0; /* Total number of significand digits read */ - size_t ndigits = 0; /* Total number of digits (no leading zeros) */ - size_t radix_position = 0; /* The number of the digits after radix */ - size_t first_nonzero = 0; /* The index of the first non-zero in *str* */ + std::size_t ndigits_read = 0; /* Total number of significand digits read */ + std::size_t ndigits = 0; /* Total number of digits (no leading zeros) */ + std::size_t radix_position = 0; /* The number of the digits after radix */ + std::size_t first_nonzero = 0; /* The index of the first non-zero in *str* */ uint16_t digits[decimal128_limits::max_digits] = {0}; uint16_t ndigits_stored = 0; /* The number of digits in digits */ uint16_t *digits_insert = digits; /* Insertion pointer for digits */ - size_t first_digit = 0; /* The index of the first non-zero digit */ - size_t last_digit = 0; /* The index of the last digit */ + std::size_t first_digit = 0; /* The index of the first non-zero digit */ + std::size_t last_digit = 0; /* The index of the last digit */ int32_t exponent = 0; uint64_t significand_high = 0; /* The high 17 digits of the significand */ @@ -808,7 +808,7 @@ namespace jsoncons { namespace bson { significand_high = 0; significand_low = 0; } else if (last_digit - first_digit < 17) { - size_t d_idx = first_digit; + std::size_t d_idx = first_digit; significand_low = digits[d_idx++]; for (; d_idx <= last_digit; d_idx++) { @@ -817,7 +817,7 @@ namespace jsoncons { namespace bson { significand_high = 0; } } else { - size_t d_idx = first_digit; + std::size_t d_idx = first_digit; significand_high = digits[d_idx++]; for (; d_idx <= last_digit - 17; d_idx++) { diff --git a/include/jsoncons_ext/bson/bson_parser.hpp b/include/jsoncons_ext/bson/bson_parser.hpp index cab18c476c..84157655d2 100644 --- a/include/jsoncons_ext/bson/bson_parser.hpp +++ b/include/jsoncons_ext/bson/bson_parser.hpp @@ -232,7 +232,7 @@ class basic_bson_parser : public ser_context } uint8_t buf[sizeof(int32_t)]; - size_t n = source_.read(buf, sizeof(int32_t)); + std::size_t n = source_.read(buf, sizeof(int32_t)); if (JSONCONS_UNLIKELY(n != sizeof(int32_t))) { ec = bson_errc::unexpected_eof; diff --git a/include/jsoncons_ext/jsonpointer/jsonpointer.hpp b/include/jsoncons_ext/jsonpointer/jsonpointer.hpp index f7aabc8526..bacdd5d75a 100644 --- a/include/jsoncons_ext/jsonpointer/jsonpointer.hpp +++ b/include/jsoncons_ext/jsonpointer/jsonpointer.hpp @@ -1343,7 +1343,7 @@ namespace jsoncons { namespace jsonpointer { for (auto it = ptr.begin(); it != ptr.end(); ) { auto s = *it; - size_t n{0}; + std::size_t n{0}; auto r = jsoncons::detail::decimal_to_integer(s.data(), s.size(), n); if (r.ec == jsoncons::detail::to_integer_errc() && (index++ == n)) { diff --git a/include/jsoncons_ext/jsonschema/common/keyword_validators.hpp b/include/jsoncons_ext/jsonschema/common/keyword_validators.hpp index 545d84fa0a..7db794f845 100644 --- a/include/jsoncons_ext/jsonschema/common/keyword_validators.hpp +++ b/include/jsoncons_ext/jsonschema/common/keyword_validators.hpp @@ -751,9 +751,9 @@ namespace jsonschema { } else { - size_t index = 0; - size_t start = 0; - size_t end = 0; + std::size_t index = 0; + std::size_t start = 0; + std::size_t end = 0; for (const auto& item : instance.array_range()) { jsonpointer::json_pointer item_location = instance_location / index; @@ -810,7 +810,7 @@ namespace jsonschema { if (schema_val_) { - size_t index = 0; + std::size_t index = 0; for (const auto& item : instance.array_range()) { jsonpointer::json_pointer item_location = instance_location / index; @@ -3368,8 +3368,8 @@ namespace jsonschema { collecting_error_listener local_reporter; std::size_t index = 0; - size_t start = 0; - size_t end = 0; + std::size_t start = 0; + std::size_t end = 0; for (const auto& item : instance.array_range()) { std::size_t errors = local_reporter.errors.size(); @@ -3642,12 +3642,12 @@ namespace jsonschema { return walk_result::advance; } - size_t data_index = 0; + std::size_t data_index = 0; evaluation_context prefix_items_context(context, this->keyword_name()); - size_t start = 0; - size_t end = 0; + std::size_t start = 0; + std::size_t end = 0; for (std::size_t schema_index=0; schema_index < prefix_item_validators_.size() && data_index < instance.size(); ++schema_index, ++data_index) @@ -3712,7 +3712,7 @@ namespace jsonschema { return result; } - size_t data_index = 0; + std::size_t data_index = 0; evaluation_context prefix_items_context(context, this->keyword_name()); @@ -3922,8 +3922,8 @@ namespace jsonschema { else { std::size_t index = 0; - size_t start = 0; - size_t end = 0; + std::size_t start = 0; + std::size_t end = 0; for (const auto& item : instance.array_range()) { // check if it is in "evaluated_items" diff --git a/include/jsoncons_ext/jsonschema/common/schema_builder.hpp b/include/jsoncons_ext/jsonschema/common/schema_builder.hpp index e7f038a1b7..b4ab3a44dd 100644 --- a/include/jsoncons_ext/jsonschema/common/schema_builder.hpp +++ b/include/jsoncons_ext/jsonschema/common/schema_builder.hpp @@ -777,7 +777,7 @@ namespace jsonschema { uri schema_location = context.make_schema_location("allOf"); std::vector subschemas; - size_t c = 0; + std::size_t c = 0; for (const auto& subsch : sch.array_range()) { std::string sub_keys[] = { "allOf", std::to_string(c++) }; @@ -792,7 +792,7 @@ namespace jsonschema { uri schema_location = context.make_schema_location("anyOf"); std::vector subschemas; - size_t c = 0; + std::size_t c = 0; for (const auto& subsch : sch.array_range()) { std::string sub_keys[] = { "anyOf", std::to_string(c++) }; @@ -807,7 +807,7 @@ namespace jsonschema { uri schema_location{ context.make_schema_location("oneOf") }; std::vector subschemas; - size_t c = 0; + std::size_t c = 0; for (const auto& subsch : sch.array_range()) { std::string sub_keys[] = { "oneOf", std::to_string(c++) }; @@ -940,7 +940,7 @@ namespace jsonschema { if (sch.type() == json_type::array_value) { - size_t c = 0; + std::size_t c = 0; for (const auto& subsch : sch.array_range()) { std::string sub_keys[] = {"items", std::to_string(c++)}; diff --git a/include/jsoncons_ext/jsonschema/draft202012/schema_builder_202012.hpp b/include/jsoncons_ext/jsonschema/draft202012/schema_builder_202012.hpp index bacfcb9362..b97fa4af1d 100644 --- a/include/jsoncons_ext/jsonschema/draft202012/schema_builder_202012.hpp +++ b/include/jsoncons_ext/jsonschema/draft202012/schema_builder_202012.hpp @@ -482,7 +482,7 @@ namespace draft202012 { if (sch.type() == json_type::array_value) { - size_t c = 0; + std::size_t c = 0; for (const auto& subsch : sch.array_range()) { std::string sub_keys[] = {"prefixItems", std::to_string(c++)}; diff --git a/test/thirdparty/catch/catch.hpp b/test/thirdparty/catch/catch.hpp index 1ca41879c5..5ed1a1bf08 100644 --- a/test/thirdparty/catch/catch.hpp +++ b/test/thirdparty/catch/catch.hpp @@ -2652,20 +2652,20 @@ namespace Catch { class Capturer { std::vector m_messages; IResultCapture& m_resultCapture = getResultCapture(); - size_t m_captured = 0; + std::size_t m_captured = 0; public: Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names ); ~Capturer(); - void captureValue( size_t index, std::string const& value ); + void captureValue( std::size_t index, std::string const& value ); template - void captureValues( size_t index, T const& value ) { + void captureValues( std::size_t index, T const& value ) { captureValue( index, Catch::Detail::stringify( value ) ); } template - void captureValues( size_t index, T const& value, Ts const&... values ) { + void captureValues( std::size_t index, T const& value, Ts const&... values ) { captureValue( index, Catch::Detail::stringify(value) ); captureValues( index+1, values... ); } @@ -3969,7 +3969,7 @@ namespace Generators { "FixedValuesGenerator does not support bools because of std::vector" "specialization, use SingleValue Generator instead."); std::vector m_values; - size_t m_idx = 0; + std::size_t m_idx = 0; public: FixedValuesGenerator( std::initializer_list values ) : m_values( values ) {} @@ -4009,7 +4009,7 @@ namespace Generators { template class Generators : public IGenerator { std::vector> m_generators; - size_t m_current = 0; + std::size_t m_current = 0; void populate(GeneratorWrapper&& generator) { m_generators.emplace_back(std::move(generator)); @@ -4119,8 +4119,8 @@ namespace Generators { template class TakeGenerator : public IGenerator { GeneratorWrapper m_generator; - size_t m_returned = 0; - size_t m_target; + std::size_t m_returned = 0; + std::size_t m_target; public: TakeGenerator(size_t target, GeneratorWrapper&& generator): m_generator(std::move(generator)), @@ -4203,9 +4203,9 @@ namespace Generators { "because of std::vector specialization"); GeneratorWrapper m_generator; mutable std::vector m_returned; - size_t m_target_repeats; - size_t m_current_repeat = 0; - size_t m_repeat_index = 0; + std::size_t m_target_repeats; + std::size_t m_current_repeat = 0; + std::size_t m_repeat_index = 0; public: RepeatGenerator(size_t repeats, GeneratorWrapper&& generator): m_generator(std::move(generator)), @@ -4296,7 +4296,7 @@ namespace Generators { template class ChunkGenerator final : public IGenerator> { std::vector m_chunk; - size_t m_chunk_size; + std::size_t m_chunk_size; GeneratorWrapper m_generator; bool m_used_up = false; public: @@ -4715,7 +4715,7 @@ class IteratorGenerator final : public IGenerator { "because of std::vector specialization"); std::vector m_elems; - size_t m_current = 0; + std::size_t m_current = 0; public: template IteratorGenerator(InputIterator first, InputSentinel last):m_elems(first, last) { @@ -8490,23 +8490,23 @@ class Columns; class Column { std::vector m_strings; - size_t m_width = CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH; - size_t m_indent = 0; - size_t m_initialIndent = std::string::npos; + std::size_t m_width = CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH; + std::size_t m_indent = 0; + std::size_t m_initialIndent = std::string::npos; public: class iterator { friend Column; Column const& m_column; - size_t m_stringIndex = 0; - size_t m_pos = 0; + std::size_t m_stringIndex = 0; + std::size_t m_pos = 0; - size_t m_len = 0; - size_t m_end = 0; + std::size_t m_len = 0; + std::size_t m_end = 0; bool m_suffix = false; - iterator(Column const& column, size_t stringIndex) + iterator(Column const& column, std::size_t stringIndex) : m_column(column), m_stringIndex(stringIndex) {} @@ -8537,7 +8537,7 @@ class Column { if (m_end < m_pos + width) { m_len = m_end - m_pos; } else { - size_t len = width; + std::size_t len = width; while (len > 0 && !isBoundary(m_pos + len)) --len; while (len > 0 && isWhitespace(line()[m_pos + len - 1])) @@ -8552,7 +8552,7 @@ class Column { } } - auto indent() const -> size_t { + auto indent() const -> std::size_t { auto initial = m_pos == 0 && m_stringIndex == 0 ? m_column.m_initialIndent : std::string::npos; return initial == std::string::npos ? m_column.m_indent : initial; } @@ -8632,7 +8632,7 @@ class Column { return *this; } - auto width() const -> size_t { return m_width; } + auto width() const -> std::size_t { return m_width; } auto begin() const -> iterator { return iterator(*this); } auto end() const -> iterator { return { *this, m_strings.size() }; } @@ -8676,7 +8676,7 @@ class Columns { std::vector const& m_columns; std::vector m_iterators; - size_t m_activeIterators; + std::size_t m_activeIterators; iterator(Columns const& columns, EndTag) : m_columns(columns.m_columns), @@ -8883,7 +8883,7 @@ namespace detail { } else { if( next[1] != '-' && next.size() > 2 ) { std::string opt = "- "; - for( size_t i = 1; i < next.size(); ++i ) { + for( std::size_t i = 1; i < next.size(); ++i ) { opt[1] = next[i]; m_tokenBuffer.push_back( { TokenType::Option, opt } ); } @@ -8908,7 +8908,7 @@ namespace detail { return !m_tokenBuffer.empty() || it != itEnd; } - auto count() const -> size_t { return m_tokenBuffer.size() + (itEnd - it); } + auto count() const -> std::size_t { return m_tokenBuffer.size() + (itEnd - it); } auto operator*() const -> Token { assert( !m_tokenBuffer.empty() ); @@ -9225,7 +9225,7 @@ namespace detail { virtual ~ParserBase() = default; virtual auto validate() const -> Result { return Result::ok(); } virtual auto parse( std::string const& exeName, TokenStream const &tokens) const -> InternalParseResult = 0; - virtual auto cardinality() const -> size_t { return 1; } + virtual auto cardinality() const -> std::size_t { return 1; } auto parse( Args const &args ) const -> InternalParseResult { return parse( args.exeName(), TokenStream( args ) ); @@ -9285,7 +9285,7 @@ namespace detail { return m_optionality == Optionality::Optional; } - auto cardinality() const -> size_t override { + auto cardinality() const -> std::size_t override { if( m_ref->isContainer() ) return 0; else @@ -9558,8 +9558,8 @@ namespace detail { } auto rows = getHelpColumns(); - size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH; - size_t optWidth = 0; + std::size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH; + std::size_t optWidth = 0; for( auto const &cols : rows ) optWidth = (std::max)(optWidth, cols.left.size() + 2); @@ -9599,7 +9599,7 @@ namespace detail { struct ParserInfo { ParserBase const* parser = nullptr; - size_t count = 0; + std::size_t count = 0; }; const size_t totalParsers = m_options.size() + m_args.size(); assert( totalParsers < 512 ); @@ -9607,7 +9607,7 @@ namespace detail { ParserInfo parseInfos[512]; { - size_t i = 0; + std::size_t i = 0; for (auto const &opt : m_options) parseInfos[i++].parser = &opt; for (auto const &arg : m_args) parseInfos[i++].parser = &arg; } @@ -9618,7 +9618,7 @@ namespace detail { while( result.value().remainingTokens() ) { bool tokenParsed = false; - for( size_t i = 0; i < totalParsers; ++i ) { + for( std::size_t i = 0; i < totalParsers; ++i ) { auto& parseInfo = parseInfos[i]; if( parseInfo.parser->cardinality() == 0 || parseInfo.count < parseInfo.parser->cardinality() ) { result = parseInfo.parser->parse(exeName, result.value().remainingTokens()); @@ -10591,7 +10591,7 @@ namespace Catch { // In other words, it returns the Blue part of Bikeshed::Colour::Blue StringRef extractInstanceName(StringRef enumInstance) { // Find last occurrence of ":" - size_t name_start = enumInstance.size(); + std::size_t name_start = enumInstance.size(); while (name_start > 0 && enumInstance[name_start - 1] != ':') { --name_start; } @@ -11309,7 +11309,7 @@ namespace Catch { } std::string TagInfo::all() const { - size_t size = 0; + std::size_t size = 0; for (auto const& spelling : spellings) { // Add 2 for the brackes size += spelling.size() + 2; @@ -11864,7 +11864,7 @@ namespace Catch { } Capturer::Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names ) { - auto trimmed = [&] (size_t start, size_t end) { + auto trimmed = [&] (size_t start, std::size_t end) { while (names[start] == ',' || isspace(static_cast(names[start]))) { ++start; } @@ -11883,7 +11883,7 @@ namespace Catch { CATCH_INTERNAL_ERROR("CAPTURE parsing encountered unmatched quote"); }; - size_t start = 0; + std::size_t start = 0; std::stack openings; for (size_t pos = 0; pos < names.size(); ++pos) { char c = names[pos]; @@ -11923,12 +11923,12 @@ namespace Catch { Capturer::~Capturer() { if ( !uncaught_exceptions() ){ assert( m_captured == m_messages.size() ); - for( size_t i = 0; i < m_captured; ++i ) + for( std::size_t i = 0; i < m_captured; ++i ) m_resultCapture.popScopedMessage( m_messages[i] ); } } - void Capturer::captureValue( size_t index, std::string const& value ) { + void Capturer::captureValue( std::size_t index, std::string const& value ) { assert( index < m_messages.size() ); m_messages[index].message += value; m_resultCapture.pushScopedMessage( m_messages[index] ); @@ -13851,9 +13851,9 @@ namespace Catch { const auto is_ws = [](char c) { return c == ' ' || c == '\t' || c == '\n' || c == '\r'; }; - size_t real_begin = 0; + std::size_t real_begin = 0; while (real_begin < ref.size() && is_ws(ref[real_begin])) { ++real_begin; } - size_t real_end = ref.size(); + std::size_t real_end = ref.size(); while (real_end > real_begin && is_ws(ref[real_end - 1])) { --real_end; } return ref.substr(real_begin, real_end - real_begin); @@ -15443,7 +15443,7 @@ namespace Catch { namespace { - size_t trailingBytes(unsigned char c) { + std::size_t trailingBytes(unsigned char c) { if ((c & 0xE0) == 0xC0) { return 2; }