Browse Source

Allow to create dpf strings from std::string_view

Signed-off-by: falkTX <falktx@falktx.com>
pull/491/head
falkTX 3 months ago
parent
commit
34435e0d86
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
1 changed files with 18 additions and 4 deletions
  1. +18
    -4
      distrho/extra/String.hpp

+ 18
- 4
distrho/extra/String.hpp View File

@@ -22,6 +22,10 @@


#include <algorithm> #include <algorithm>


#if __cplusplus >= 201703L
# include <string_view>
#endif

START_NAMESPACE_DISTRHO START_NAMESPACE_DISTRHO


// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -49,10 +53,7 @@ public:
fBufferLen(0), fBufferLen(0),
fBufferAlloc(false) fBufferAlloc(false)
{ {
char ch[2];
ch[0] = c;
ch[1] = '\0';

const char ch[2] = { c, '\0' };
_dup(ch); _dup(ch);
} }


@@ -87,6 +88,19 @@ public:
_dup(strBuf); _dup(strBuf);
} }


#if __cplusplus >= 201703L
/*
* std::string_view compatible variant.
*/
explicit String(const std::string_view& strView) noexcept
: fBuffer(_null()),
fBufferLen(0),
fBufferAlloc(false)
{
_dup(strView.data(), strView.size());
}
#endif

/* /*
* Integer. * Integer.
*/ */


Loading…
Cancel
Save