From 99c3bead5a74d4c6b2810b3ce7a9b7a954fc2036 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 18 Feb 2021 12:40:31 +0000 Subject: [PATCH] Added data_end() and renamed trim() to trim_to_terminator() --- include/etl/basic_string.h | 20 +++++++++++++++++++- test/test_string_char.cpp | 10 +++++----- test/test_string_char_external_buffer.cpp | 6 +++--- test/test_string_u16.cpp | 6 +++--- test/test_string_u16_external_buffer.cpp | 6 +++--- test/test_string_u32.cpp | 6 +++--- test/test_string_u32_external_buffer.cpp | 6 +++--- test/test_string_wchar_t.cpp | 6 +++--- test/test_string_wchar_t_external_buffer.cpp | 6 +++--- 9 files changed, 45 insertions(+), 27 deletions(-) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 7e6d61ec..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. @@ -2200,7 +2218,7 @@ namespace etl /// If the last buffer position has a non-null value then the truncated /// flag will be set. //********************************************************************* - void trim() + void trim_to_terminator() { #if ETL_STRING_TRUNCATION_CHECKS_ENABLED set_truncated(p_buffer[CAPACITY] != T(0)); diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index 3acb1e56..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); @@ -4200,7 +4200,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size(), STR('A')); - text.trim(); + text.trim_to_terminator(); CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); @@ -4213,7 +4213,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); - text.trim(); + text.trim_to_terminator(); CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); @@ -4226,7 +4226,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. - text.trim(); + 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 336faebe..46c29643 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -4567,7 +4567,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size(), STR('A')); - text.trim(); + text.trim_to_terminator(); CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); @@ -4581,7 +4581,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); - text.trim(); + text.trim_to_terminator(); CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); @@ -4595,7 +4595,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. - text.trim(); + 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 0677bba8..477014be 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -4200,7 +4200,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size(), STR('A')); - text.trim(); + text.trim_to_terminator(); CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); @@ -4213,7 +4213,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); - text.trim(); + text.trim_to_terminator(); CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); @@ -4226,7 +4226,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. - text.trim(); + 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 755e2130..9098efb7 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -4567,7 +4567,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size(), STR('A')); - text.trim(); + text.trim_to_terminator(); CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); @@ -4581,7 +4581,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); - text.trim(); + text.trim_to_terminator(); CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); @@ -4595,7 +4595,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. - text.trim(); + 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 95fe3d18..b52aa8b3 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -4200,7 +4200,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size(), STR('A')); - text.trim(); + text.trim_to_terminator(); CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); @@ -4213,7 +4213,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); - text.trim(); + text.trim_to_terminator(); CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); @@ -4226,7 +4226,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. - text.trim(); + 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 78eea17a..6e3a3b90 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -4550,7 +4550,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size(), STR('A')); - text.trim(); + text.trim_to_terminator(); CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); @@ -4564,7 +4564,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); - text.trim(); + text.trim_to_terminator(); CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); @@ -4578,7 +4578,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. - text.trim(); + 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 de1375a1..d8b7853f 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -4200,7 +4200,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size(), STR('A')); - text.trim(); + text.trim_to_terminator(); CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); @@ -4213,7 +4213,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); - text.trim(); + text.trim_to_terminator(); CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); @@ -4226,7 +4226,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. - text.trim(); + 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 08cc2798..4202ea21 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -4550,7 +4550,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size(), STR('A')); - text.trim(); + text.trim_to_terminator(); CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); @@ -4564,7 +4564,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); - text.trim(); + text.trim_to_terminator(); CHECK(!text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); @@ -4578,7 +4578,7 @@ namespace text.initialize_free_space(); std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. - text.trim(); + text.trim_to_terminator(); CHECK(text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size());