Showing posts with label string_view. Show all posts
Showing posts with label string_view. Show all posts

Friday, September 13, 2019

STLSoft 1.10.1 (beta 15) released

The latest beta of STLSoft 1.10.1 is available, at https://github.com/synesissoftware/STLSoft-1.10/tree/beta-15.

Getting the beta

As usual, there are two ways to obtain the latest beta:
  1. Select one of the release archives (.zip, .tar.gz) at https://github.com/synesissoftware/STLSoft-1.10/releases/tag/1.10.1-beta15; or
  2. Clone the repo https://github.com/synesissoftware/STLSoft-1.10 and checkout the beta-15 branch (as in "$ git checkout -b beta-10 origin/beta-15").

Changes

The substantive changes are:
  • added stlsoft::fast_strftime() and stlsoft::fast_wcsftime() as drop-in replacements for std::strftime() and std::wcsftime();
  • added stlsoft::get_ptr() shim overload for std::shared_ptr and std::unique_ptr
  • added stlsoft::get_top() attribute shim, which obtains the front/top element of a non-empty container;
  • added stlsoft::basic_string_view<>::substr() method;
  • added winstl_C_format_message_strerror_w();
  • removed stlsoft::literal_cast<>;
  • various portability improvements to newer compilers.
I'll describe these changes in a future blog post.

Sunday, June 6, 2010

STLSoft 1.9.98 changes to stlsoft::split()

As of STLSoft 1.9.98, stlsoft::split() has been enhanced to be able to split into between two and six fragments. Previously you would have use intermediates to split into more fields, as in:


std::string line = "abc|def|ghi|jkl";
stlsoft::string_view dummy1;
stlsoft::string_view dummy2;
stlsoft::string_view field0;
stlsoft::string_view field1;
stlsoft::string_view field2;
stlsoft::string_view field3;

if(stlsoft::split(line, '|', field0, dummy1) &&
   stlsoft::split(dummy1, '|', field1, dummy2) &&
   stlsoft::split(dummy2, '|', field2, field3))
{
  . . . // use fields

Although there's no additional memory allocation here - because we're using string views as the intermediate and final fragment types - it's still hard to follow, and doing three separate split operations.

You can now split directly into up to six fields, as in:



std::string line = "abc|def|ghi|jkl";
stlsoft::string_view field0;
stlsoft::string_view field1;
stlsoft::string_view field2;
stlsoft::string_view field3;

if(stlsoft::split(line, '|', field0, field1, field2, field3))
{
  . . . // use fields

It's marginally more efficient when using string views, and substantially more efficient when using string value types (such as std::string and stlsoft::simple_string). In either cases, it's considerably more transparent.