diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index d3358699..5857ccd3 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -582,6 +582,24 @@ namespace etl return p_buffer; } + //********************************************************************* + /// Returns a pointer to the beginning of the string data. + ///\return A pointer to the beginning of the string data. + //********************************************************************* + pointer data_end() + { + return p_buffer + current_size; + } + + //********************************************************************* + /// Returns a const pointer to the beginning of the string data. + ///\return A const pointer to the beginning of the string data. + //********************************************************************* + const_pointer data_end() const + { + return p_buffer + current_size; + } + //********************************************************************* /// Assigns values to the string. /// Truncates if the string does not have enough free space. @@ -2185,20 +2203,29 @@ namespace etl #endif //********************************************************************* - /// Update the size to the distnace to the first null, or max size. + /// Clears the free space to string terminator value. //********************************************************************* - void update_size() + void initialize_free_space() { - p_buffer[max_size()] = 0; // Ensure a terminating null. +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + set_truncated(false); +#endif + etl::fill(&p_buffer[current_size], &p_buffer[CAPACITY + 1U], T(0)); + } - size_t i = 0U; + //********************************************************************* + /// Trim the size to the distance to the first null terminator. + /// If the last buffer position has a non-null value then the truncated + /// flag will be set. + //********************************************************************* + void trim_to_terminator() + { +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + set_truncated(p_buffer[CAPACITY] != T(0)); +#endif - while ((i != max_size()) && (p_buffer[i] != 0)) - { - ++i; - } - - current_size = i; + p_buffer[CAPACITY] = T(0); // Ensure a terminating null. + current_size = etl::strlen(p_buffer); } protected: diff --git a/include/etl/version.h b/include/etl/version.h index deb45761..167cfeca 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2018 jwellbelove +Copyright(c) 2021 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -38,8 +38,8 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 20 -#define ETL_VERSION_MINOR 2 -#define ETL_VERSION_PATCH 3 +#define ETL_VERSION_MINOR 3 +#define ETL_VERSION_PATCH 0 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) "." ETL_STRINGIFY(ETL_VERSION_MINOR) "." ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_W ETL_STRINGIFY(ETL_VERSION_MAJOR) L"." ETL_STRINGIFY(ETL_VERSION_MINOR) L"." ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index ab12e219..84ce520a 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "ETL Embedded Template Library", - "version": "20.2.3", + "version": "20.3.0", "author s": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index cfce3281..cd64152d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library ETL -version=20.2.3 +version=20.3.0 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 0a397dc1..bd54a662 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,6 +1,11 @@ +=============================================================================== +20.3.0 +Added initialize_free_space(), trim_to_terminator() and data_end() functions to +strings for easier integration with C APIs. + =============================================================================== 20.2.3 -Fixed indexing error in find_next for etl::bitset. +Fixed indexing error in find_next() for etl::bitset. =============================================================================== 20.2.2 diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index 6492bb67..91d02fa8 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -874,7 +874,7 @@ namespace Text text(compare_text.begin(), compare_text.end()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), + text.data_end(), compare_text.begin()); CHECK(is_equal); @@ -891,7 +891,7 @@ namespace const Text text(compare_text.begin(), compare_text.end()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), + text.data_end(), compare_text.begin()); CHECK(is_equal); @@ -4158,15 +4158,51 @@ namespace } #endif + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_initialize_free_space_empty_string) + { + Text empty; + Text text; + + text.initialize_free_space(); + + CHECK(text.empty()); + CHECK(text == empty); + + for (size_t i = text.size(); i < text.max_size(); ++i) + { + CHECK_EQUAL(0, text[i]); + } + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_initialize_free_space_part_filled_string) + { + Text empty; + Text initial = STR("ABC"); + Text text(initial); + + text.initialize_free_space(); + + CHECK(text == initial); + CHECK(text != empty); + + for (size_t i = text.size(); i < text.max_size(); ++i) + { + CHECK_EQUAL(0, text[i]); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_update_after_c_string_max_size) { Text text; - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size(), STR('A')); - text.update_size(); + text.trim_to_terminator(); + CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } @@ -4175,10 +4211,11 @@ namespace { Text text; - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); - text.update_size(); + text.trim_to_terminator(); + CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -4187,10 +4224,11 @@ namespace { Text text; - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. - text.update_size(); + text.trim_to_terminator(); + CHECK(text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } }; diff --git a/test/test_string_char_external_buffer.cpp b/test/test_string_char_external_buffer.cpp index 4cba90bb..46c29643 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -4520,42 +4520,84 @@ namespace } #endif + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_initialize_free_space_empty_string) + { + TextBuffer buffer1; + TextBuffer buffer2; + Text text(buffer1.data(), buffer1.size()); + Text empty(buffer2.data(), buffer2.size()); + + text.initialize_free_space(); + + CHECK(text.empty()); + CHECK(text == empty); + + for (size_t i = text.size(); i < text.max_size(); ++i) + { + CHECK_EQUAL(0, text[i]); + } + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_initialize_free_space_part_filled_string) + { + TextBuffer buffer1; + TextBuffer buffer2; + Text initial(STR("ABC"), buffer1.data(), buffer1.size()); + Text empty(buffer2.data(), buffer2.size()); + Text text(initial, buffer2.data(), buffer2.size()); + + text.initialize_free_space(); + + CHECK(text == initial); + CHECK(text != empty); + + for (size_t i = text.size(); i < text.max_size(); ++i) + { + CHECK_EQUAL(0, text[i]); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_update_after_c_string_max_size) { - TextBuffer buffer; - Text text(buffer.data(), buffer.size()); + TextBuffer buffer1; + Text text(buffer1.data(), buffer1.size()); - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size(), STR('A')); - text.update_size(); + text.trim_to_terminator(); + CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_update_after_c_string_shorter_size) { - TextBuffer buffer; - Text text(buffer.data(), buffer.size()); + TextBuffer buffer1; + Text text(buffer1.data(), buffer1.size()); - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); - text.update_size(); + text.trim_to_terminator(); + CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_update_after_c_string_greater_size) { - TextBuffer buffer; - Text text(buffer.data(), buffer.size()); + TextBuffer buffer1; + Text text(buffer1.data(), buffer1.size()); - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. - text.update_size(); + text.trim_to_terminator(); + CHECK(text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } }; diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index aeaab84b..477014be 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -4158,15 +4158,51 @@ namespace } #endif + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_initialize_free_space_empty_string) + { + Text empty; + Text text; + + text.initialize_free_space(); + + CHECK(text.empty()); + CHECK(text == empty); + + for (size_t i = text.size(); i < text.max_size(); ++i) + { + CHECK_EQUAL(0, text[i]); + } + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_initialize_free_space_part_filled_string) + { + Text empty; + Text initial = STR("ABC"); + Text text(initial); + + text.initialize_free_space(); + + CHECK(text == initial); + CHECK(text != empty); + + for (size_t i = text.size(); i < text.max_size(); ++i) + { + CHECK_EQUAL(0, text[i]); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_update_after_c_string_max_size) { Text text; - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size(), STR('A')); - text.update_size(); + text.trim_to_terminator(); + CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } @@ -4175,10 +4211,11 @@ namespace { Text text; - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); - text.update_size(); + text.trim_to_terminator(); + CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -4187,10 +4224,11 @@ namespace { Text text; - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. - text.update_size(); + text.trim_to_terminator(); + CHECK(text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } }; diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index 04ebef90..9098efb7 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -4520,42 +4520,84 @@ namespace } #endif + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_initialize_free_space_empty_string) + { + TextBuffer buffer1; + TextBuffer buffer2; + Text text(buffer1.data(), buffer1.size()); + Text empty(buffer2.data(), buffer2.size()); + + text.initialize_free_space(); + + CHECK(text.empty()); + CHECK(text == empty); + + for (size_t i = text.size(); i < text.max_size(); ++i) + { + CHECK_EQUAL(0, text[i]); + } + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_initialize_free_space_part_filled_string) + { + TextBuffer buffer1; + TextBuffer buffer2; + Text initial(STR("ABC"), buffer1.data(), buffer1.size()); + Text empty(buffer2.data(), buffer2.size()); + Text text(initial, buffer2.data(), buffer2.size()); + + text.initialize_free_space(); + + CHECK(text == initial); + CHECK(text != empty); + + for (size_t i = text.size(); i < text.max_size(); ++i) + { + CHECK_EQUAL(0, text[i]); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_update_after_c_string_max_size) { - TextBuffer buffer; - Text text(buffer.data(), buffer.size()); + TextBuffer buffer1; + Text text(buffer1.data(), buffer1.size()); - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size(), STR('A')); - text.update_size(); + text.trim_to_terminator(); + CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_update_after_c_string_shorter_size) { - TextBuffer buffer; - Text text(buffer.data(), buffer.size()); + TextBuffer buffer1; + Text text(buffer1.data(), buffer1.size()); - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); - text.update_size(); + text.trim_to_terminator(); + CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_update_after_c_string_greater_size) { - TextBuffer buffer; - Text text(buffer.data(), buffer.size()); + TextBuffer buffer1; + Text text(buffer1.data(), buffer1.size()); - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. - text.update_size(); + text.trim_to_terminator(); + CHECK(text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } }; diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index 9efa1362..b52aa8b3 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -4158,15 +4158,51 @@ namespace } #endif + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_initialize_free_space_empty_string) + { + Text empty; + Text text; + + text.initialize_free_space(); + + CHECK(text.empty()); + CHECK(text == empty); + + for (size_t i = text.size(); i < text.max_size(); ++i) + { + CHECK_EQUAL(0, text[i]); + } + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_initialize_free_space_part_filled_string) + { + Text empty; + Text initial = STR("ABC"); + Text text(initial); + + text.initialize_free_space(); + + CHECK(text == initial); + CHECK(text != empty); + + for (size_t i = text.size(); i < text.max_size(); ++i) + { + CHECK_EQUAL(0, text[i]); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_update_after_c_string_max_size) { Text text; - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size(), STR('A')); - text.update_size(); + text.trim_to_terminator(); + CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } @@ -4175,10 +4211,11 @@ namespace { Text text; - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); - text.update_size(); + text.trim_to_terminator(); + CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -4187,10 +4224,11 @@ namespace { Text text; - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. - text.update_size(); + text.trim_to_terminator(); + CHECK(text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } }; diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index 67b17c01..6e3a3b90 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -4503,42 +4503,84 @@ namespace } #endif + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_initialize_free_space_empty_string) + { + TextBuffer buffer1; + TextBuffer buffer2; + Text text(buffer1.data(), buffer1.size()); + Text empty(buffer2.data(), buffer2.size()); + + text.initialize_free_space(); + + CHECK(text.empty()); + CHECK(text == empty); + + for (size_t i = text.size(); i < text.max_size(); ++i) + { + CHECK_EQUAL(0, text[i]); + } + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_initialize_free_space_part_filled_string) + { + TextBuffer buffer1; + TextBuffer buffer2; + Text initial(STR("ABC"), buffer1.data(), buffer1.size()); + Text empty(buffer2.data(), buffer2.size()); + Text text(initial, buffer2.data(), buffer2.size()); + + text.initialize_free_space(); + + CHECK(text == initial); + CHECK(text != empty); + + for (size_t i = text.size(); i < text.max_size(); ++i) + { + CHECK_EQUAL(0, text[i]); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_update_after_c_string_max_size) { - TextBuffer buffer; - Text text(buffer.data(), buffer.size()); + TextBuffer buffer1; + Text text(buffer1.data(), buffer1.size()); - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size(), STR('A')); - text.update_size(); + text.trim_to_terminator(); + CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_update_after_c_string_shorter_size) { - TextBuffer buffer; - Text text(buffer.data(), buffer.size()); + TextBuffer buffer1; + Text text(buffer1.data(), buffer1.size()); - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); - text.update_size(); + text.trim_to_terminator(); + CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_update_after_c_string_greater_size) { - TextBuffer buffer; - Text text(buffer.data(), buffer.size()); + TextBuffer buffer1; + Text text(buffer1.data(), buffer1.size()); - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. - text.update_size(); + text.trim_to_terminator(); + CHECK(text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } }; diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index 0293bb85..d8b7853f 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -4158,15 +4158,51 @@ namespace } #endif + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_initialize_free_space_empty_string) + { + Text empty; + Text text; + + text.initialize_free_space(); + + CHECK(text.empty()); + CHECK(text == empty); + + for (size_t i = text.size(); i < text.max_size(); ++i) + { + CHECK_EQUAL(0, text[i]); + } + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_initialize_free_space_part_filled_string) + { + Text empty; + Text initial = STR("ABC"); + Text text(initial); + + text.initialize_free_space(); + + CHECK(text == initial); + CHECK(text != empty); + + for (size_t i = text.size(); i < text.max_size(); ++i) + { + CHECK_EQUAL(0, text[i]); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_update_after_c_string_max_size) { Text text; - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size(), STR('A')); - text.update_size(); + text.trim_to_terminator(); + CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } @@ -4175,10 +4211,11 @@ namespace { Text text; - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); - text.update_size(); + text.trim_to_terminator(); + CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -4187,10 +4224,11 @@ namespace { Text text; - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. - text.update_size(); + text.trim_to_terminator(); + CHECK(text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } }; diff --git a/test/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index ecb138df..4202ea21 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -4503,42 +4503,84 @@ namespace } #endif + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_initialize_free_space_empty_string) + { + TextBuffer buffer1; + TextBuffer buffer2; + Text text(buffer1.data(), buffer1.size()); + Text empty(buffer2.data(), buffer2.size()); + + text.initialize_free_space(); + + CHECK(text.empty()); + CHECK(text == empty); + + for (size_t i = text.size(); i < text.max_size(); ++i) + { + CHECK_EQUAL(0, text[i]); + } + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_initialize_free_space_part_filled_string) + { + TextBuffer buffer1; + TextBuffer buffer2; + Text initial(STR("ABC"), buffer1.data(), buffer1.size()); + Text empty(buffer2.data(), buffer2.size()); + Text text(initial, buffer2.data(), buffer2.size()); + + text.initialize_free_space(); + + CHECK(text == initial); + CHECK(text != empty); + + for (size_t i = text.size(); i < text.max_size(); ++i) + { + CHECK_EQUAL(0, text[i]); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_update_after_c_string_max_size) { - TextBuffer buffer; - Text text(buffer.data(), buffer.size()); + TextBuffer buffer1; + Text text(buffer1.data(), buffer1.size()); - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size(), STR('A')); - text.update_size(); + text.trim_to_terminator(); + CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_update_after_c_string_shorter_size) { - TextBuffer buffer; - Text text(buffer.data(), buffer.size()); + TextBuffer buffer1; + Text text(buffer1.data(), buffer1.size()); - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); - text.update_size(); + text.trim_to_terminator(); + CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_update_after_c_string_greater_size) { - TextBuffer buffer; - Text text(buffer.data(), buffer.size()); + TextBuffer buffer1; + Text text(buffer1.data(), buffer1.size()); - text.resize(text.max_size()); + text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. - text.update_size(); + text.trim_to_terminator(); + CHECK(text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } };