Browse Source

Cleanup String class, fix some compiler warnings

pull/506/head
falkTX 1 month ago
parent
commit
33e750e4cf
3 changed files with 56 additions and 58 deletions
  1. +51
    -56
      distrho/extra/String.hpp
  2. +2
    -2
      distrho/src/DistrhoPluginVST2.cpp
  3. +3
    -0
      distrho/src/jackbridge/JackBridge.cpp

+ 51
- 56
distrho/extra/String.hpp View File

@@ -269,7 +269,7 @@ public:
/*
* Get length of the string.
*/
std::size_t length() const noexcept
size_t length() const noexcept
{
return fBufferLen;
}
@@ -295,7 +295,7 @@ public:
*/
bool contains(const char c) const noexcept
{
for (std::size_t i=0; i<fBufferLen; ++i)
for (size_t i=0; i<fBufferLen; ++i)
{
if (fBuffer[i] == c)
return true;
@@ -334,7 +334,7 @@ public:
/*
* Check if character at 'pos' is a digit.
*/
bool isDigit(const std::size_t pos) const noexcept
bool isDigit(const size_t pos) const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(pos < fBufferLen, false);

@@ -358,7 +358,7 @@ public:
{
DISTRHO_SAFE_ASSERT_RETURN(prefix != nullptr, false);

const std::size_t prefixLen(std::strlen(prefix));
const size_t prefixLen(std::strlen(prefix));

if (fBufferLen < prefixLen)
return false;
@@ -383,7 +383,7 @@ public:
{
DISTRHO_SAFE_ASSERT_RETURN(suffix != nullptr, false);

const std::size_t suffixLen(std::strlen(suffix));
const size_t suffixLen(std::strlen(suffix));

if (fBufferLen < suffixLen)
return false;
@@ -395,7 +395,7 @@ public:
* Find the first occurrence of character 'c' in the string.
* Returns "length()" if the character is not found.
*/
std::size_t find(const char c, bool* const found = nullptr) const noexcept
size_t find(const char c, bool* const found = nullptr) const noexcept
{
if (fBufferLen == 0 || c == '\0')
{
@@ -404,7 +404,7 @@ public:
return fBufferLen;
}

for (std::size_t i=0; i < fBufferLen; ++i)
for (size_t i=0; i < fBufferLen; ++i)
{
if (fBuffer[i] == c)
{
@@ -423,7 +423,7 @@ public:
* Find the first occurrence of string 'strBuf' in the string.
* Returns "length()" if the string is not found.
*/
std::size_t find(const char* const strBuf, bool* const found = nullptr) const noexcept
size_t find(const char* const strBuf, bool* const found = nullptr) const noexcept
{
if (fBufferLen == 0 || strBuf == nullptr || strBuf[0] == '\0')
{
@@ -448,7 +448,7 @@ public:

if (found != nullptr)
*found = true;
return static_cast<std::size_t>(ret);
return static_cast<size_t>(ret);
}

if (found != nullptr)
@@ -460,7 +460,7 @@ public:
* Find the last occurrence of character 'c' in the string.
* Returns "length()" if the character is not found.
*/
std::size_t rfind(const char c, bool* const found = nullptr) const noexcept
size_t rfind(const char c, bool* const found = nullptr) const noexcept
{
if (fBufferLen == 0 || c == '\0')
{
@@ -469,7 +469,7 @@ public:
return fBufferLen;
}

for (std::size_t i=fBufferLen; i > 0; --i)
for (size_t i=fBufferLen; i > 0; --i)
{
if (fBuffer[i-1] == c)
{
@@ -488,7 +488,7 @@ public:
* Find the last occurrence of string 'strBuf' in the string.
* Returns "length()" if the string is not found.
*/
std::size_t rfind(const char* const strBuf, bool* const found = nullptr) const noexcept
size_t rfind(const char* const strBuf, bool* const found = nullptr) const noexcept
{
if (found != nullptr)
*found = false;
@@ -496,12 +496,12 @@ public:
if (fBufferLen == 0 || strBuf == nullptr || strBuf[0] == '\0')
return fBufferLen;

const std::size_t strBufLen(std::strlen(strBuf));
const size_t strBufLen(std::strlen(strBuf));

std::size_t ret = fBufferLen;
size_t ret = fBufferLen;
const char* tmpBuf = fBuffer;

for (std::size_t i=0; i < fBufferLen; ++i)
for (size_t i=0; i < fBufferLen; ++i)
{
if (std::strstr(tmpBuf+1, strBuf) == nullptr && std::strncmp(tmpBuf, strBuf, strBufLen) == 0)
{
@@ -532,7 +532,7 @@ public:
{
DISTRHO_SAFE_ASSERT_RETURN(before != '\0' /* && after != '\0' */, *this);

for (std::size_t i=0; i < fBufferLen; ++i)
for (size_t i=0; i < fBufferLen; ++i)
{
if (fBuffer[i] == before)
fBuffer[i] = after;
@@ -551,7 +551,7 @@ public:
if (fBufferLen == 0)
return *this;

for (std::size_t i=0; i < fBufferLen; ++i)
for (size_t i=0; i < fBufferLen; ++i)
{
if (fBuffer[i] == c)
{
@@ -567,7 +567,7 @@ public:
/*
* Truncate the string to size 'n'.
*/
String& truncate(const std::size_t n) noexcept
String& truncate(const size_t n) noexcept
{
if (n >= fBufferLen)
return *this;
@@ -583,7 +583,7 @@ public:
*/
String& toBasic() noexcept
{
for (std::size_t i=0; i < fBufferLen; ++i)
for (size_t i=0; i < fBufferLen; ++i)
{
if (fBuffer[i] >= '0' && fBuffer[i] <= '9')
continue;
@@ -607,7 +607,7 @@ public:
{
static constexpr const char kCharDiff = 'a' - 'A';

for (std::size_t i=0; i < fBufferLen; ++i)
for (size_t i=0; i < fBufferLen; ++i)
{
if (fBuffer[i] >= 'A' && fBuffer[i] <= 'Z')
fBuffer[i] = static_cast<char>(fBuffer[i] + kCharDiff);
@@ -623,7 +623,7 @@ public:
{
static constexpr const char kCharDiff = 'a' - 'A';

for (std::size_t i=0; i < fBufferLen; ++i)
for (size_t i=0; i < fBufferLen; ++i)
{
if (fBuffer[i] >= 'a' && fBuffer[i] <= 'z')
fBuffer[i] = static_cast<char>(fBuffer[i] - kCharDiff);
@@ -688,31 +688,28 @@ public:
// base64 stuff, based on http://www.adp-gmbh.ch/cpp/common/base64.html
// Copyright (C) 2004-2008 René Nyffenegger

static String asBase64(const void* const data, const std::size_t dataSize)
static String asBase64(const void* const data, const size_t dataSize)
{
static constexpr const char* const kBase64Chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";

#ifndef _MSC_VER
const std::size_t kTmpBufSize = std::min(d_nextPowerOf2(static_cast<uint32_t>(dataSize/3)), 65536U);
#else
constexpr std::size_t kTmpBufSize = 65536U;
#endif
const size_t strBufSize = std::min(d_nextPowerOf2(static_cast<uint32_t>(dataSize/3)), 65536U);
char* strBuf = static_cast<char*>(std::malloc(strBufSize));
DISTRHO_SAFE_ASSERT_RETURN(strBuf != nullptr, String());

const uchar* bytesToEncode((const uchar*)data);
strBuf[strBufSize] = '\0';
size_t strBufIndex = 0;

const uchar* bytesToEncode = static_cast<const uchar*>(data);

uint i=0, j=0;
uint charArray3[3], charArray4[4];

char strBuf[kTmpBufSize + 1];
strBuf[kTmpBufSize] = '\0';
std::size_t strBufIndex = 0;

String ret;

for (std::size_t s=0; s<dataSize; ++s)
for (size_t s = 0; s < dataSize; ++s)
{
charArray3[i++] = *(bytesToEncode++);

@@ -723,10 +720,10 @@ public:
charArray4[2] = ((charArray3[1] & 0x0f) << 2) + ((charArray3[2] & 0xc0) >> 6);
charArray4[3] = charArray3[2] & 0x3f;

for (i=0; i<4; ++i)
for (i = 0; i < 4; ++i)
strBuf[strBufIndex++] = kBase64Chars[charArray4[i]];

if (strBufIndex >= kTmpBufSize-7)
if (strBufIndex >= strBufSize - 7)
{
strBuf[strBufIndex] = '\0';
strBufIndex = 0;
@@ -739,7 +736,7 @@ public:

if (i != 0)
{
for (j=i; j<3; ++j)
for (j = i; j < 3; ++j)
charArray3[j] = '\0';

charArray4[0] = (charArray3[0] & 0xfc) >> 2;
@@ -747,7 +744,7 @@ public:
charArray4[2] = ((charArray3[1] & 0x0f) << 2) + ((charArray3[2] & 0xc0) >> 6);
charArray4[3] = charArray3[2] & 0x3f;

for (j=0; j<4 && i<3 && j<i+1; ++j)
for (j = 0; j < 4 && i < 3 && j < i + 1; ++j)
strBuf[strBufIndex++] = kBase64Chars[charArray4[j]];

for (; i++ < 3;)
@@ -760,6 +757,7 @@ public:
ret += strBuf;
}

std::free(strBuf);
return ret;
}

@@ -778,7 +776,7 @@ public:

char* newbufptr = newbuf;

for (std::size_t i=0; i < fBufferLen; ++i)
for (size_t i=0; i < fBufferLen; ++i)
{
const char c = fBuffer[i];

@@ -901,7 +899,7 @@ public:

char* newbufptr = newbuf;

for (std::size_t i=0; i < fBufferLen; ++i)
for (size_t i=0; i < fBufferLen; ++i)
{
const char c = fBuffer[i];

@@ -957,19 +955,16 @@ public:
return fBuffer;
}

char operator[](const std::size_t pos) const noexcept
char operator[](const size_t pos) const noexcept
{
if (pos < fBufferLen)
return fBuffer[pos];

d_safe_assert("pos < fBufferLen", __FILE__, __LINE__);

static char fallback;
fallback = '\0';
return fallback;
return '\0';
}

char& operator[](const std::size_t pos) noexcept
char& operator[](const size_t pos) noexcept
{
if (pos < fBufferLen)
return fBuffer[pos];
@@ -1020,7 +1015,7 @@ public:
if (strBuf == nullptr || strBuf[0] == '\0')
return *this;

const std::size_t strBufLen = std::strlen(strBuf);
const size_t strBufLen = std::strlen(strBuf);

// for empty strings, we can just take the appended string as our entire data
if (isEmpty())
@@ -1054,8 +1049,8 @@ public:
if (isEmpty())
return String(strBuf);

const std::size_t strBufLen = std::strlen(strBuf);
const std::size_t newBufSize = fBufferLen + strBufLen;
const size_t strBufLen = std::strlen(strBuf);
const size_t newBufSize = fBufferLen + strBufLen;
char* const newBuf = static_cast<char*>(std::malloc(newBufSize + 1));
DISTRHO_SAFE_ASSERT_RETURN(newBuf != nullptr, String());

@@ -1080,7 +1075,7 @@ public:

private:
char* fBuffer; // the actual string buffer
std::size_t fBufferLen; // string length
size_t fBufferLen; // string length
bool fBufferAlloc; // wherever the buffer is allocated, not using _null()

/*
@@ -1101,7 +1096,7 @@ private:
* - Allocates string only if 'strBuf' is not null and new string contents are different
* - If 'strBuf' is null, 'size' must be 0
*/
void _dup(const char* const strBuf, const std::size_t size = 0) noexcept
void _dup(const char* const strBuf, const size_t size = 0) noexcept
{
if (strBuf != nullptr)
{
@@ -1158,9 +1153,9 @@ String operator+(const String& strBefore, const char* const strBufAfter) noexcep
if (strBefore.isEmpty())
return String(strBufAfter);

const std::size_t strBeforeLen = strBefore.length();
const std::size_t strBufAfterLen = std::strlen(strBufAfter);
const std::size_t newBufSize = strBeforeLen + strBufAfterLen;
const size_t strBeforeLen = strBefore.length();
const size_t strBufAfterLen = std::strlen(strBufAfter);
const size_t newBufSize = strBeforeLen + strBufAfterLen;
char* const newBuf = static_cast<char*>(malloc(newBufSize + 1));
DISTRHO_SAFE_ASSERT_RETURN(newBuf != nullptr, String());

@@ -1178,9 +1173,9 @@ String operator+(const char* const strBufBefore, const String& strAfter) noexcep
if (strBufBefore == nullptr || strBufBefore[0] == '\0')
return strAfter;

const std::size_t strBufBeforeLen = std::strlen(strBufBefore);
const std::size_t strAfterLen = strAfter.length();
const std::size_t newBufSize = strBufBeforeLen + strAfterLen;
const size_t strBufBeforeLen = std::strlen(strBufBefore);
const size_t strAfterLen = strAfter.length();
const size_t newBufSize = strBufBeforeLen + strAfterLen;
char* const newBuf = static_cast<char*>(malloc(newBufSize + 1));
DISTRHO_SAFE_ASSERT_RETURN(newBuf != nullptr, String());



+ 2
- 2
distrho/src/DistrhoPluginVST2.cpp View File

@@ -398,8 +398,8 @@ public:
{
parameterValues = new float[parameterCount];

for (uint32_t i=0; i < parameterCount; ++i)
parameterValues[i] = NAN;
for (uint32_t i = 0; i < parameterCount; ++i)
parameterValues[i] = fPlugin.getParameterDefault(i);
}

#if DISTRHO_PLUGIN_WANT_MIDI_INPUT


+ 3
- 0
distrho/src/jackbridge/JackBridge.cpp View File

@@ -68,6 +68,9 @@ typedef void* lib_t;
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
# pragma clang diagnostic ignored "-Wunused-but-set-variable"
# if __clang_major__ >= 17
# pragma clang diagnostic ignored "-Wvla-cxx-extension"
# endif
# endif
# include "RtAudioBridge.hpp"
# ifdef RTAUDIO_API_TYPE


Loading…
Cancel
Save