Merge remote-tracking branch 'origin/master' into feature/add_circle-ci_support

# Conflicts:
#	include/etl/cstring.h
#	include/etl/u16string.h
#	include/etl/u32string.h
#	include/etl/wstring.h
This commit is contained in:
John Wellbelove 2019-12-06 13:50:56 +00:00
parent 06429e140b
commit 2dfff5b5c2
12 changed files with 128 additions and 6 deletions

View File

@ -5,6 +5,7 @@ AppVeyor
[![Build status](https://ci.appveyor.com/api/projects/status/b7jgecv7unqjw4u0/branch/master?svg=true)](https://ci.appveyor.com/project/jwellbelove/etl/branch/master)
![build status](https://gitlab.com/ETLCPP/etl/badges/master/build.svg)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/3c14cd918ccf40008d0bcd7b083d5946)](https://www.codacy.com/manual/jwellbelove/etl?utm_source=github.com&utm_medium=referral&utm_content=ETLCPP/etl&utm_campaign=Badge_Grade)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/jwellbelove/etl)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Github All Releases](https://img.shields.io/github/downloads/ETLCPP/etl/total.svg)]()

View File

@ -237,7 +237,7 @@ namespace etl
size_t operator()(const etl::istring& text) const
{
return etl::private_hash::generic_hash<size_t>(reinterpret_cast<const uint8_t*>(&text[0]),
reinterpret_cast<const uint8_t*>(&text[text.size()]));
reinterpret_cast<const uint8_t*>(&text[text.size()]));
}
};
@ -247,7 +247,7 @@ namespace etl
size_t operator()(const etl::string<SIZE>& text) const
{
return etl::private_hash::generic_hash<size_t>(reinterpret_cast<const uint8_t*>(&text[0]),
reinterpret_cast<const uint8_t*>(&text[text.size()]));
reinterpret_cast<const uint8_t*>(&text[text.size()]));
}
};
#endif
@ -260,6 +260,15 @@ namespace etl
{
return etl::string<MAX_SIZE - 1>(text, MAX_SIZE - 1);
}
//***************************************************************************
/// Make string with max capacity from string literal or char array
//***************************************************************************
template<const size_t MAX_SIZE, const size_t SIZE>
etl::string<MAX_SIZE> make_string_with_capacity(const char(&text)[SIZE])
{
return etl::string<MAX_SIZE>(text, SIZE - 1);
}
}
#include "private/minmax_pop.h"

View File

@ -260,6 +260,15 @@ namespace etl
{
return etl::u16string<MAX_SIZE - 1>(text, MAX_SIZE - 1);
}
//***************************************************************************
/// Make string with max capacity from string literal or char array
//***************************************************************************
template<const size_t MAX_SIZE, const size_t SIZE>
etl::u16string<MAX_SIZE> make_string_with_capacity(const char16_t(&text)[SIZE])
{
return etl::u16string<MAX_SIZE>(text, SIZE - 1);
}
}
#include "private/minmax_pop.h"

View File

@ -260,6 +260,15 @@ namespace etl
{
return etl::u32string<MAX_SIZE - 1>(text, MAX_SIZE - 1);
}
//***************************************************************************
/// Make string with max capacity from string literal or char array
//***************************************************************************
template<const size_t MAX_SIZE, const size_t SIZE>
etl::u32string<MAX_SIZE> make_string_with_capacity(const char32_t(&text)[SIZE])
{
return etl::u32string<MAX_SIZE>(text, SIZE - 1);
}
}
#include "private/minmax_pop.h"

View File

@ -38,7 +38,7 @@ SOFTWARE.
///\ingroup utilities
#define ETL_VERSION_MAJOR 15
#define ETL_VERSION_MINOR 2
#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)

View File

@ -261,6 +261,15 @@ namespace etl
{
return etl::wstring<MAX_SIZE - 1>(text, MAX_SIZE - 1);
}
//***************************************************************************
/// Make string with max capacity from string literal or char array
//***************************************************************************
template<const size_t MAX_SIZE, const size_t SIZE>
etl::wstring<MAX_SIZE> make_string_with_capacity(const wchar_t(&text)[SIZE])
{
return etl::wstring<MAX_SIZE>(text, SIZE - 1);
}
}
#include "private/minmax_pop.h"

View File

@ -1,6 +1,6 @@
{
"name": "Embedded Template Library",
"version": "15.2.0",
"version": "15.3.0",
"authors": {
"name": "John Wellbelove",
"email": "<john.wellbelove@etlcpp.com>"

View File

@ -1,5 +1,5 @@
name=Embedded Template Library
version=15.2.0
version=15.3.0
author= John Wellbelove <john.wellbelove@etlcpp.com>
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
license=MIT

View File

@ -1,3 +1,11 @@
===============================================================================
15.3.0
Added etl::make_string_with_capacity
===============================================================================
15.2.1
Compile time optimisations to etl::make_string
===============================================================================
15.2.0
Added function adaptors and removed built-in sort functions from indirect_vector.

View File

@ -430,6 +430,7 @@
<Unit filename="../test_largest.cpp" />
<Unit filename="../test_list.cpp" />
<Unit filename="../test_list_shared_pool.cpp" />
<Unit filename="../test_make_string.cpp" />
<Unit filename="../test_map.cpp" />
<Unit filename="../test_maths.cpp" />
<Unit filename="../test_memory.cpp" />

View File

@ -73,5 +73,71 @@ namespace
CHECK(Equal(std::u16string(u"Hello World"), ctext));
CHECK(Equal(std::u32string(U"Hello World"), ctext));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_make_string_with_capacity)
{
constexpr size_t CAPACITY = 20;
size_t length = strlen("Hello World");
auto ctext = etl::make_string_with_capacity<CAPACITY>("Hello World");
auto wtext = etl::make_string_with_capacity<CAPACITY>(L"Hello World");
auto u16text = etl::make_string_with_capacity<CAPACITY>(u"Hello World");
auto u32text = etl::make_string_with_capacity<CAPACITY>(U"Hello World");
CHECK_EQUAL(CAPACITY, ctext.max_size());
CHECK_EQUAL(length, ctext.size());
CHECK(!ctext.truncated());
CHECK_EQUAL(CAPACITY, wtext.max_size());
CHECK_EQUAL(length, wtext.size());
CHECK(!wtext.truncated());
CHECK_EQUAL(CAPACITY, u16text.max_size());
CHECK_EQUAL(length, u16text.size());
CHECK(!u16text.truncated());
CHECK_EQUAL(CAPACITY, u32text.max_size());
CHECK_EQUAL(length, u32text.size());
CHECK(!u32text.truncated());
CHECK(Equal(std::string("Hello World"), ctext));
CHECK(Equal(std::wstring(L"Hello World"), ctext));
CHECK(Equal(std::u16string(u"Hello World"), ctext));
CHECK(Equal(std::u32string(U"Hello World"), ctext));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_make_string_with_capacity_truncated)
{
constexpr size_t CAPACITY = 10;
size_t length = strlen("Hello World");
auto ctext = etl::make_string_with_capacity<CAPACITY>("Hello World");
auto wtext = etl::make_string_with_capacity<CAPACITY>(L"Hello World");
auto u16text = etl::make_string_with_capacity<CAPACITY>(u"Hello World");
auto u32text = etl::make_string_with_capacity<CAPACITY>(U"Hello World");
CHECK_EQUAL(CAPACITY, ctext.max_size());
CHECK_EQUAL(length - 1, ctext.size());
CHECK(ctext.truncated());
CHECK_EQUAL(CAPACITY, wtext.max_size());
CHECK_EQUAL(length - 1, wtext.size());
CHECK(wtext.truncated());
CHECK_EQUAL(CAPACITY, u16text.max_size());
CHECK_EQUAL(length - 1, u16text.size());
CHECK(u16text.truncated());
CHECK_EQUAL(CAPACITY, u32text.max_size());
CHECK_EQUAL(length - 1, u32text.size());
CHECK(u32text.truncated());
CHECK(Equal(std::string("Hello Worl"), ctext));
CHECK(Equal(std::wstring(L"Hello Worl"), ctext));
CHECK(Equal(std::u16string(u"Hello Worl"), ctext));
CHECK(Equal(std::u32string(U"Hello Worl"), ctext));
}
};
}

View File

@ -81,7 +81,6 @@ namespace
{
SetupFixture()
{
initial_text = STR("Hello World");
initial_text = STR("Hello World");
insert_text = STR("Insert");
less_text = STR("Hello Vorld");
@ -253,6 +252,17 @@ namespace
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_constructor_from_literal)
{
Text text(STR("Hello World"));
bool is_equal = Equal(initial_text, text);
CHECK(is_equal);
CHECK(text.size() == SIZE);
CHECK(!text.empty());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_copy_constructor)
{