From 2dfff5b5c2c993ed14cc5fd7a936560faa6eedc0 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 6 Dec 2019 13:50:56 +0000 Subject: [PATCH] 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 --- README.md | 1 + include/etl/cstring.h | 13 ++++++-- include/etl/u16string.h | 9 ++++++ include/etl/u32string.h | 9 ++++++ include/etl/version.h | 2 +- include/etl/wstring.h | 9 ++++++ library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 8 +++++ test/codeblocks/ETL.cbp | 1 + test/test_make_string.cpp | 66 +++++++++++++++++++++++++++++++++++++++ test/test_string_char.cpp | 12 ++++++- 12 files changed, 128 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 10437ee1..978d25d3 100644 --- a/README.md +++ b/README.md @@ -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)]() diff --git a/include/etl/cstring.h b/include/etl/cstring.h index 122cdb3b..93a559df 100644 --- a/include/etl/cstring.h +++ b/include/etl/cstring.h @@ -237,7 +237,7 @@ namespace etl size_t operator()(const etl::istring& text) const { return etl::private_hash::generic_hash(reinterpret_cast(&text[0]), - reinterpret_cast(&text[text.size()])); + reinterpret_cast(&text[text.size()])); } }; @@ -247,7 +247,7 @@ namespace etl size_t operator()(const etl::string& text) const { return etl::private_hash::generic_hash(reinterpret_cast(&text[0]), - reinterpret_cast(&text[text.size()])); + reinterpret_cast(&text[text.size()])); } }; #endif @@ -260,6 +260,15 @@ namespace etl { return etl::string(text, MAX_SIZE - 1); } + + //*************************************************************************** + /// Make string with max capacity from string literal or char array + //*************************************************************************** + template + etl::string make_string_with_capacity(const char(&text)[SIZE]) + { + return etl::string(text, SIZE - 1); + } } #include "private/minmax_pop.h" diff --git a/include/etl/u16string.h b/include/etl/u16string.h index 3dd33aab..0da8209c 100644 --- a/include/etl/u16string.h +++ b/include/etl/u16string.h @@ -260,6 +260,15 @@ namespace etl { return etl::u16string(text, MAX_SIZE - 1); } + + //*************************************************************************** + /// Make string with max capacity from string literal or char array + //*************************************************************************** + template + etl::u16string make_string_with_capacity(const char16_t(&text)[SIZE]) + { + return etl::u16string(text, SIZE - 1); + } } #include "private/minmax_pop.h" diff --git a/include/etl/u32string.h b/include/etl/u32string.h index 7c01c7a7..34fad1a3 100644 --- a/include/etl/u32string.h +++ b/include/etl/u32string.h @@ -260,6 +260,15 @@ namespace etl { return etl::u32string(text, MAX_SIZE - 1); } + + //*************************************************************************** + /// Make string with max capacity from string literal or char array + //*************************************************************************** + template + etl::u32string make_string_with_capacity(const char32_t(&text)[SIZE]) + { + return etl::u32string(text, SIZE - 1); + } } #include "private/minmax_pop.h" diff --git a/include/etl/version.h b/include/etl/version.h index 3f91e496..3f6458c0 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -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) diff --git a/include/etl/wstring.h b/include/etl/wstring.h index c2533037..f85275ed 100644 --- a/include/etl/wstring.h +++ b/include/etl/wstring.h @@ -261,6 +261,15 @@ namespace etl { return etl::wstring(text, MAX_SIZE - 1); } + + //*************************************************************************** + /// Make string with max capacity from string literal or char array + //*************************************************************************** + template + etl::wstring make_string_with_capacity(const wchar_t(&text)[SIZE]) + { + return etl::wstring(text, SIZE - 1); + } } #include "private/minmax_pop.h" diff --git a/library.json b/library.json index 477ce514..c2e9281e 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "15.2.0", + "version": "15.3.0", "authors": { "name": "John Wellbelove", "email": "" diff --git a/library.properties b/library.properties index 3bb62455..0a327d6e 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=15.2.0 +version=15.3.0 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index fe0d467e..abc768f1 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -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. diff --git a/test/codeblocks/ETL.cbp b/test/codeblocks/ETL.cbp index 3ce6a93c..46869784 100644 --- a/test/codeblocks/ETL.cbp +++ b/test/codeblocks/ETL.cbp @@ -430,6 +430,7 @@ + diff --git a/test/test_make_string.cpp b/test/test_make_string.cpp index 2bd432b0..08ba1c24 100644 --- a/test/test_make_string.cpp +++ b/test/test_make_string.cpp @@ -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("Hello World"); + auto wtext = etl::make_string_with_capacity(L"Hello World"); + auto u16text = etl::make_string_with_capacity(u"Hello World"); + auto u32text = etl::make_string_with_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("Hello World"); + auto wtext = etl::make_string_with_capacity(L"Hello World"); + auto u16text = etl::make_string_with_capacity(u"Hello World"); + auto u32text = etl::make_string_with_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)); + } }; } diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index c1b0f8a5..075cb82b 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -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) {