Skip to content

Commit

Permalink
Added etl::string::fill()
Browse files Browse the repository at this point in the history
  • Loading branch information
John Wellbelove committed Oct 4, 2023
1 parent b5bed0f commit 6b7093d
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/etl/basic_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,16 @@ namespace etl
p_buffer[new_size] = 0;
}

//*********************************************************************
/// Fills the string with the specified character.
/// Does not change the string length.
///\param value The character used to fill the string.
//*********************************************************************
void fill(T value)
{
etl::fill(begin(), end(), value);
}

//*********************************************************************
/// Returns a reference to the value at index 'i'
///\param i The index.
Expand Down
16 changes: 16 additions & 0 deletions test/test_string_char.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,22 @@ namespace
CHECK_EQUAL(text.size(), NEW_SIZE);
}

//*************************************************************************
TEST_FIXTURE(SetupFixture, test_fill)
{
Text text(SIZE, STR('A'));
Text expected(SIZE, STR('B'));

text.fill(STR('B'));

bool is_equal = Equal(expected, text);
CHECK(is_equal);

#if ETL_HAS_STRING_TRUNCATION_CHECKS
CHECK(!text.is_truncated());
#endif
}

//*************************************************************************
TEST_FIXTURE(SetupFixture, test_empty_full)
{
Expand Down
16 changes: 16 additions & 0 deletions test/test_string_u16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,22 @@ namespace
CHECK_EQUAL(text.size(), NEW_SIZE);
}

//*************************************************************************
TEST_FIXTURE(SetupFixture, test_fill)
{
Text text(SIZE, STR('A'));
Text expected(SIZE, STR('B'));

text.fill(STR('B'));

bool is_equal = Equal(expected, text);
CHECK(is_equal);

#if ETL_HAS_STRING_TRUNCATION_CHECKS
CHECK(!text.is_truncated());
#endif
}

//*************************************************************************
TEST_FIXTURE(SetupFixture, test_empty_full)
{
Expand Down
18 changes: 18 additions & 0 deletions test/test_string_u16_external_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,24 @@ namespace
CHECK_EQUAL(text.size(), NEW_SIZE);
}

//*************************************************************************
TEST_FIXTURE(SetupFixture, test_fill)
{
TextBuffer buffer1{ 0 };
TextBuffer buffer2{ 0 };
Text text(11, STR('A'), buffer1.data(), buffer1.size());
Text expected(11, STR('B'), buffer2.data(), buffer2.size());

text.fill(STR('B'));

bool is_equal = Equal(expected, text);
CHECK(is_equal);

#if ETL_HAS_STRING_TRUNCATION_CHECKS
CHECK(!text.is_truncated());
#endif
}

//*************************************************************************
TEST_FIXTURE(SetupFixture, test_empty_full)
{
Expand Down
16 changes: 16 additions & 0 deletions test/test_string_u32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,22 @@ namespace
CHECK_EQUAL(text.size(), NEW_SIZE);
}

//*************************************************************************
TEST_FIXTURE(SetupFixture, test_fill)
{
Text text(SIZE, STR('A'));
Text expected(SIZE, STR('B'));

text.fill(STR('B'));

bool is_equal = Equal(expected, text);
CHECK(is_equal);

#if ETL_HAS_STRING_TRUNCATION_CHECKS
CHECK(!text.is_truncated());
#endif
}

//*************************************************************************
TEST_FIXTURE(SetupFixture, test_empty_full)
{
Expand Down
18 changes: 18 additions & 0 deletions test/test_string_u32_external_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,24 @@ namespace
CHECK_EQUAL(text.size(), NEW_SIZE);
}

//*************************************************************************
TEST_FIXTURE(SetupFixture, test_fill)
{
TextBuffer buffer1{ 0 };
TextBuffer buffer2{ 0 };
Text text(11, STR('A'), buffer1.data(), buffer1.size());
Text expected(11, STR('B'), buffer2.data(), buffer2.size());

text.fill(STR('B'));

bool is_equal = Equal(expected, text);
CHECK(is_equal);

#if ETL_HAS_STRING_TRUNCATION_CHECKS
CHECK(!text.is_truncated());
#endif
}

//*************************************************************************
TEST_FIXTURE(SetupFixture, test_empty_full)
{
Expand Down
16 changes: 16 additions & 0 deletions test/test_string_wchar_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,22 @@ namespace
CHECK_EQUAL(text.size(), NEW_SIZE);
}

//*************************************************************************
TEST_FIXTURE(SetupFixture, test_fill)
{
Text text(SIZE, STR('A'));
Text expected(SIZE, STR('B'));

text.fill(STR('B'));

bool is_equal = Equal(expected, text);
CHECK(is_equal);

#if ETL_HAS_STRING_TRUNCATION_CHECKS
CHECK(!text.is_truncated());
#endif
}

//*************************************************************************
TEST_FIXTURE(SetupFixture, test_empty_full)
{
Expand Down
18 changes: 18 additions & 0 deletions test/test_string_wchar_t_external_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,24 @@ namespace
CHECK_EQUAL(text.size(), NEW_SIZE);
}

//*************************************************************************
TEST_FIXTURE(SetupFixture, test_fill)
{
TextBuffer buffer1{ 0 };
TextBuffer buffer2{ 0 };
Text text(11, STR('A'), buffer1.data(), buffer1.size());
Text expected(11, STR('B'), buffer2.data(), buffer2.size());

text.fill(STR('B'));

bool is_equal = Equal(expected, text);
CHECK(is_equal);

#if ETL_HAS_STRING_TRUNCATION_CHECKS
CHECK(!text.is_truncated());
#endif
}

//*************************************************************************
TEST_FIXTURE(SetupFixture, test_empty_full)
{
Expand Down

0 comments on commit 6b7093d

Please sign in to comment.