[Companion] Move CHECK_IN_ARRAY() to macros.h; Change DIM() return type; Refactor/fix removeAccents() to handle uppercase.
This commit is contained in:
@@ -140,8 +140,11 @@ const int Boards::getFlashSize(Type board)
|
||||
}
|
||||
}
|
||||
|
||||
const SwitchInfo Boards::getSwitchInfo(Board::Type board, unsigned index)
|
||||
const SwitchInfo Boards::getSwitchInfo(Board::Type board, int index)
|
||||
{
|
||||
if (index < 0)
|
||||
return {SWITCH_NOT_AVAILABLE, CPN_STR_UNKNOWN_ITEM};
|
||||
|
||||
if (IS_TARANIS_XLITE(board)) {
|
||||
const Board::SwitchInfo switches[] = {
|
||||
{SWITCH_3POS, "SA"},
|
||||
@@ -202,7 +205,7 @@ const SwitchInfo Boards::getSwitchInfo(Board::Type board, unsigned index)
|
||||
return switches[index];
|
||||
}
|
||||
|
||||
return {SWITCH_NOT_AVAILABLE, "???"};
|
||||
return {SWITCH_NOT_AVAILABLE, CPN_STR_UNKNOWN_ITEM};
|
||||
}
|
||||
|
||||
const int Boards::getCapability(Board::Type board, Board::Capability capability)
|
||||
@@ -301,9 +304,12 @@ const QString Boards::getAxisName(int index)
|
||||
return tr("Unknown");
|
||||
}
|
||||
|
||||
const QString Boards::getAnalogInputName(Board::Type board, unsigned index)
|
||||
const QString Boards::getAnalogInputName(Board::Type board, int index)
|
||||
{
|
||||
if ((int)index < getBoardCapability(board, Board::Sticks)) {
|
||||
if (index < 0)
|
||||
return CPN_STR_UNKNOWN_ITEM;
|
||||
|
||||
if (index < getBoardCapability(board, Board::Sticks)) {
|
||||
const QString sticks[] = {
|
||||
tr("Rud"),
|
||||
tr("Ele"),
|
||||
@@ -376,7 +382,7 @@ const QString Boards::getAnalogInputName(Board::Type board, unsigned index)
|
||||
return pots[index];
|
||||
}
|
||||
|
||||
return "???";
|
||||
return CPN_STR_UNKNOWN_ITEM;
|
||||
}
|
||||
|
||||
const bool Boards::isBoardCompatible(Type board1, Type board2)
|
||||
|
||||
@@ -157,18 +157,18 @@ class Boards
|
||||
const uint32_t getFourCC() const { return getFourCC(m_boardType); }
|
||||
const int getEEpromSize() const { return getEEpromSize(m_boardType); }
|
||||
const int getFlashSize() const { return getFlashSize(m_boardType); }
|
||||
const Board::SwitchInfo getSwitchInfo(unsigned index) const { return getSwitchInfo(m_boardType, index); }
|
||||
const Board::SwitchInfo getSwitchInfo(int index) const { return getSwitchInfo(m_boardType, index); }
|
||||
const int getCapability(Board::Capability capability) const { return getCapability(m_boardType, capability); }
|
||||
const QString getAnalogInputName(unsigned index) const { return getAnalogInputName(m_boardType, index); }
|
||||
const QString getAnalogInputName(int index) const { return getAnalogInputName(m_boardType, index); }
|
||||
const bool isBoardCompatible(Board::Type board2) const { return isBoardCompatible(m_boardType, board2); }
|
||||
|
||||
static uint32_t getFourCC(Board::Type board);
|
||||
static const int getEEpromSize(Board::Type board);
|
||||
static const int getFlashSize(Board::Type board);
|
||||
static const Board::SwitchInfo getSwitchInfo(Board::Type board, unsigned index);
|
||||
static const Board::SwitchInfo getSwitchInfo(Board::Type board, int index);
|
||||
static const int getCapability(Board::Type board, Board::Capability capability);
|
||||
static const QString getAxisName(int index);
|
||||
static const QString getAnalogInputName(Board::Type board, unsigned index);
|
||||
static const QString getAnalogInputName(Board::Type board, int index);
|
||||
static const bool isBoardCompatible(Board::Type board1, Board::Type board2);
|
||||
static const QString getBoardName(Board::Type board);
|
||||
|
||||
|
||||
@@ -418,8 +418,6 @@ inline int calcRESXto100(int x)
|
||||
return divRoundClosest(x*100, 1024);
|
||||
}
|
||||
|
||||
#define CHECK_IN_ARRAY(T, index) ((unsigned int)index < DIM(T) ? T[(unsigned int)index] : CPN_STR_UNKNOWN_ITEM)
|
||||
|
||||
extern QList<EEPROMInterface *> eepromInterfaces;
|
||||
|
||||
|
||||
|
||||
@@ -28,29 +28,30 @@
|
||||
|
||||
QString removeAccents(const QString & str)
|
||||
{
|
||||
QString result = str;
|
||||
|
||||
// UTF-8 ASCII Table
|
||||
const QString tA[] = { "á", "â", "ã", "à", "ä" };
|
||||
const QString tE[] = { "é", "è", "ê", "ě" };
|
||||
const QString tI[] = { "í" };
|
||||
const QString tO[] = { "ó", "ô", "õ", "ö" };
|
||||
const QString tU[] = { "ú", "ü" };
|
||||
const QString tC[] = { "ç" };
|
||||
const QString tY[] = { "ý" };
|
||||
const QString tS[] = { "š" };
|
||||
const QString tR[] = { "ř" };
|
||||
|
||||
for (unsigned int i = 0; i < DIM(tA); i++) result.replace(tA[i], "a");
|
||||
for (unsigned int i = 0; i < DIM(tE); i++) result.replace(tE[i], "e");
|
||||
for (unsigned int i = 0; i < DIM(tI); i++) result.replace(tI[i], "i");
|
||||
for (unsigned int i = 0; i < DIM(tO); i++) result.replace(tO[i], "o");
|
||||
for (unsigned int i = 0; i < DIM(tU); i++) result.replace(tU[i], "u");
|
||||
for (unsigned int i = 0; i < DIM(tC); i++) result.replace(tC[i], "c");
|
||||
for (unsigned int i = 0; i < DIM(tY); i++) result.replace(tY[i], "y");
|
||||
for (unsigned int i = 0; i < DIM(tS); i++) result.replace(tS[i], "s");
|
||||
for (unsigned int i = 0; i < DIM(tR); i++) result.replace(tR[i], "r");
|
||||
static const QHash<QString, QVariant> map = {
|
||||
{"a", QRegularExpression("[áâãàä]")},
|
||||
{"A", QRegularExpression("[ÁÂÃÀÄ]")},
|
||||
{"e", QRegularExpression("[éèêě]")},
|
||||
{"E", QRegularExpression("[ÉÈÊĚ]")},
|
||||
{"o", QRegularExpression("[óôõö]")},
|
||||
{"O", QRegularExpression("[ÓÔÕÖ]")},
|
||||
{"u", QRegularExpression("[úü]")},
|
||||
{"U", QRegularExpression("[ÚÜ]")},
|
||||
{"i", "í"}, {"I", "Í"},
|
||||
{"c", "ç"}, {"C", "Ç"},
|
||||
{"y", "ý"}, {"Y", "Ý"},
|
||||
{"s", "š"}, {"S", "Š"},
|
||||
{"r", "ř"}, {"R", "Ř"}
|
||||
};
|
||||
|
||||
QString result(str);
|
||||
for (QHash<QString, QVariant>::const_iterator it = map.cbegin(), en = map.cend(); it != en; ++it) {
|
||||
if (it.value().canConvert<QRegularExpression>())
|
||||
result.replace(it.value().toRegularExpression(), it.key());
|
||||
else
|
||||
result.replace(it.value().toString(), it.key());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,18 +21,19 @@
|
||||
#ifndef _MACROS_H_
|
||||
#define _MACROS_H_
|
||||
|
||||
#include "constants.h"
|
||||
#include <QDataStream>
|
||||
#include <iterator>
|
||||
|
||||
// #define DIM(arr) (sizeof((arr))/sizeof((arr)[0]))
|
||||
// new way for c++11
|
||||
#define DIM(arr__) ((size_t)(std::end((arr__)) - std::begin((arr__))))
|
||||
#define DIM(arr__) (std::end(arr__) - std::begin(arr__))
|
||||
|
||||
#ifndef CONCATENATE
|
||||
#define CONCATENATE_IMPL(A, B) A ## B
|
||||
#define CONCATENATE(A, B) CONCATENATE_IMPL(A, B)
|
||||
#endif
|
||||
|
||||
#define CHECK_IN_ARRAY(T, index) ((index) >= 0 && int(index) < DIM(T) ? T[(index)] : CPN_STR_UNKNOWN_ITEM)
|
||||
|
||||
#define CREATE_ENUM_STREAM_OPS3(functype, type, datatype) \
|
||||
functype QDataStream& operator << (QDataStream &out, type &e) { return out << (datatype&)e; } \
|
||||
functype QDataStream& operator >> (QDataStream &in, type &e) { in >> (datatype&)e; return in; }
|
||||
|
||||
Reference in New Issue
Block a user