Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/hotfix/string-truncate-bug' into…
Browse files Browse the repository at this point in the history
… development
  • Loading branch information
jwellbelove committed Mar 17, 2019
2 parents e4f34d5 + 92989fe commit 7d4b0ef
Show file tree
Hide file tree
Showing 13 changed files with 1,704 additions and 440 deletions.
23 changes: 20 additions & 3 deletions include/etl/basic_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand 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();
Expand Down Expand Up @@ -593,6 +597,8 @@ namespace etl
}

p_buffer[current_size] = 0;

is_truncated = (first != last);
}

//*********************************************************************
Expand All @@ -605,6 +611,8 @@ namespace etl
{
initialise();

is_truncated = (n > CAPACITY);

n = std::min(n, CAPACITY);

std::fill_n(begin(), n, value);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -1013,6 +1025,8 @@ namespace etl
current_size -= n_delete;
p_buffer[current_size] = 0;

is_truncated = false;

return first;
}

Expand All @@ -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)
Expand Down Expand Up @@ -1919,7 +1935,8 @@ namespace etl
void initialise()
{
current_size = 0;
p_buffer[0] = 0;
p_buffer[0] = 0;
is_truncated = false;
}

//*************************************************************************
Expand Down
7 changes: 2 additions & 5 deletions include/etl/cstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}

Expand Down Expand Up @@ -186,7 +183,7 @@ namespace etl
//*************************************************************************
/// Assignment operator.
//*************************************************************************
string& operator = (const string& rhs)
string& operator = (const istring& rhs)
{
if (&rhs != this)
{
Expand Down
10 changes: 10 additions & 0 deletions include/etl/string_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ SOFTWARE.
#include "char_traits.h"
#include "integral_limits.h"
#include "hash.h"
#include "basic_string.h"

#include "algorithm.h"

Expand Down Expand Up @@ -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*.
//*************************************************************************
Expand Down
5 changes: 1 addition & 4 deletions include/etl/u16string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}
Expand Down
5 changes: 1 addition & 4 deletions include/etl/u32string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}
Expand Down
2 changes: 1 addition & 1 deletion include/etl/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 1 addition & 4 deletions include/etl/wstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}
Expand Down
4 changes: 4 additions & 0 deletions support/Release notes.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Loading

0 comments on commit 7d4b0ef

Please sign in to comment.