Merge remote-tracking branch 'origin/hotfix/string-truncate-bug' into development

This commit is contained in:
John Wellbelove 2019-03-17 17:52:39 +00:00
commit 7d4b0ef7a2
13 changed files with 1704 additions and 440 deletions

View File

@ -393,6 +393,8 @@ namespace etl
//*********************************************************************
void resize(size_t new_size, T value)
{
is_truncated = (new_size > CAPACITY);
new_size = std::min(new_size, CAPACITY);
// Size up?
@ -560,6 +562,8 @@ namespace etl
//*********************************************************************
void assign(const_pointer other, size_t length_)
{
is_truncated = (length_ > CAPACITY);
length_ = std::min(length_, CAPACITY);
initialise();
@ -593,6 +597,8 @@ namespace etl
}
p_buffer[current_size] = 0;
is_truncated = (first != last);
}
//*********************************************************************
@ -605,6 +611,8 @@ namespace etl
{
initialise();
is_truncated = (n > CAPACITY);
n = std::min(n, CAPACITY);
std::fill_n(begin(), n, value);
@ -786,8 +794,9 @@ namespace etl
const size_t start = std::distance(cbegin(), position);
// No effect.
if (start == CAPACITY)
if (start >= CAPACITY)
{
is_truncated = true;
return;
}
@ -846,8 +855,9 @@ namespace etl
const size_t n = std::distance(first, last);
// No effect.
if (start == CAPACITY)
if (start >= CAPACITY)
{
is_truncated = true;
return;
}
@ -994,6 +1004,8 @@ namespace etl
std::copy(i_element + 1, end(), i_element);
p_buffer[--current_size] = 0;
is_truncated = false;
return i_element;
}
@ -1013,6 +1025,8 @@ namespace etl
current_size -= n_delete;
p_buffer[current_size] = 0;
is_truncated = false;
return first;
}
@ -1032,6 +1046,8 @@ namespace etl
//*********************************************************************
size_t copy(pointer s, size_t len, size_t pos = 0)
{
is_truncated = (pos + len > size());
size_t endpos = std::min(pos + len, size());
for (size_t i = pos; i < endpos; ++i)
@ -1919,7 +1935,8 @@ namespace etl
void initialise()
{
current_size = 0;
p_buffer[0] = 0;
p_buffer[0] = 0;
is_truncated = false;
}
//*************************************************************************

View File

@ -94,14 +94,11 @@ namespace etl
///\param position The position of the first character.
///\param length The number of characters. Default = npos.
//*************************************************************************
string(const etl::string<MAX_SIZE_>& other, size_t position, size_t length_ = npos)
string(const etl::istring& other, size_t position, size_t length_ = npos)
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds));
// Set the length to the exact amount.
length_ = (length_ > MAX_SIZE_) ? MAX_SIZE_ : length_;
this->assign(other.begin() + position, other.begin() + position + length_);
}
@ -186,7 +183,7 @@ namespace etl
//*************************************************************************
/// Assignment operator.
//*************************************************************************
string& operator = (const string& rhs)
string& operator = (const istring& rhs)
{
if (&rhs != this)
{

View File

@ -39,6 +39,7 @@ SOFTWARE.
#include "char_traits.h"
#include "integral_limits.h"
#include "hash.h"
#include "basic_string.h"
#include "algorithm.h"
@ -124,6 +125,15 @@ namespace etl
{
}
//*************************************************************************
/// Construct from string.
//*************************************************************************
ETL_CONSTEXPR basic_string_view(const etl::ibasic_string<T>& str)
: mbegin(str.begin()),
mend(str.end())
{
}
//*************************************************************************
/// Construct from T*.
//*************************************************************************

View File

@ -95,14 +95,11 @@ namespace etl
///\param position The position of the first character.
///\param length The number of characters. Default = npos.
//*************************************************************************
u16string(const etl::u16string<MAX_SIZE_>& other, size_t position, size_t length_ = npos)
u16string(const etl::iu16string& other, size_t position, size_t length_ = npos)
: iu16string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds));
// Set the length to the exact amount.
length_ = (length_ > MAX_SIZE_) ? MAX_SIZE_ : length_;
this->initialise();
this->assign(other.begin() + position, other.begin() + position + length_);
}

View File

@ -95,14 +95,11 @@ namespace etl
///\param position The position of the first character.
///\param length The number of characters. Default = npos.
//*************************************************************************
u32string(const etl::u32string<MAX_SIZE_>& other, size_t position, size_t length_ = npos)
u32string(const etl::iu32string& other, size_t position, size_t length_ = npos)
: iu32string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds));
// Set the length to the exact amount.
length_ = (length_ > MAX_SIZE_) ? MAX_SIZE_ : length_;
this->initialise();
this->assign(other.begin() + position, other.begin() + position + length_);
}

View File

@ -39,7 +39,7 @@ SOFTWARE.
#define ETL_VERSION_MAJOR 14
#define ETL_VERSION_MINOR 14
#define ETL_VERSION_PATCH 0
#define ETL_VERSION_PATCH 1
#define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) ETL_STRINGIFY(ETL_VERSION_MINOR) ETL_STRINGIFY(ETL_VERSION_PATCH)
#define ETL_VERSION_W ETL_WIDE_STRING(ETL_CONCAT(ETL_CONCAT(ETL_VERSION_MAJOR, ETL_VERSION_MINOR), ETL_VERSION_PATCH))

View File

@ -96,14 +96,11 @@ namespace etl
///\param position The position of the first character.
///\param length The number of characters. Default = npos.
//*************************************************************************
wstring(const etl::wstring<MAX_SIZE_>& other, size_t position, size_t length_ = npos)
wstring(const etl::iwstring& other, size_t position, size_t length_ = npos)
: iwstring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds));
// Set the length to the exact amount.
length_ = (length_ > MAX_SIZE_) ? MAX_SIZE_ : length_;
this->initialise();
this->assign(other.begin() + position, other.begin() + position + length_);
}

View File

@ -1,3 +1,7 @@
===============================================================================
14.14.1
Fixed bug where 'truncated' was not always set correctly for strings.
===============================================================================
14.14.0
Fixed string push_back() bug where ther internal terminator was not updated.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -86,6 +86,18 @@ namespace
CHECK(isEqual);
}
//*************************************************************************
TEST(test_constructor_etl_string)
{
View view(etltext);
CHECK_EQUAL(etltext.size(), view.size());
CHECK_EQUAL(etltext.size(), view.max_size());
bool isEqual = std::equal(view.begin(), view.end(), etltext.begin());
CHECK(isEqual);
}
//*************************************************************************
TEST(test_constructor_pointer_size)
{

File diff suppressed because it is too large Load Diff