fix: Custom stick and switch names were being mangled internally (#1770)

* followup to PR1754

* Cleanup

* Formatting

* Long comment
This commit is contained in:
Wilhelm
2022-04-01 14:16:01 +10:00
committed by GitHub
parent c9594390e2
commit 5e6cf2e79c
3 changed files with 56 additions and 23 deletions
+32 -1
View File
@@ -78,7 +78,7 @@ char *getSwitchPositionName(char *dest, swsrc_t idx);
char *getSwitchName(char *dest, swsrc_t idx);
template<size_t L>
char *getSourceString(char (&dest)[L], mixsrc_t idx);
char* getSourceString(char (&dest)[L], mixsrc_t idx);
int getRawSwitchIdx(char sw);
char getRawSwitchFromIdx(int sw);
@@ -113,4 +113,35 @@ template<typename S>
void clearStruct(S& s) {
memset((void*) &s, 0, sizeof(S));
}
template <size_t N>
using offset_t = std::integral_constant<size_t, N>;
template <size_t DL, size_t SL, size_t O = 0>
void copyToTerminated(char (&dest)[DL], const char (&src)[SL],
const offset_t<O> = offset_t<0>{})
{
// unfortinately std::min() isn't constexpr in C++11
// static constexpr size_t len = std::min(DL - O - 1, SL);
static constexpr size_t dl{DL - O - 1};
static_assert(dl > 0, "wrong sizes or offset");
static constexpr size_t len = (dl < SL) ? dl : SL;
strncpy(&dest[O], &src[0], len);
static_assert((len + O) < DL);
dest[len + O] = '\0';
}
template <size_t L1, size_t L2>
int strncasecmp(char (&s1)[L1], const char (&s2)[L2])
{
static constexpr size_t len = (L1 < L2) ? L1 : L2;
return strncasecmp(s1, s2, len);
}
template <size_t L1>
int strncasecmp(char (&s1)[L1], const char *const s2)
{
return strncasecmp(s1, s2, L1);
}
#endif // _STRHELPERS_H_