mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/unit] Add restriction to some input prefixes
The symbol for pint (_pt) conflicts with the symbol for pico-tonne. To solve that, prefixes for tonnes are now restricted to the positive prefixes : k, M, G, T. Change-Id: Ie968374bbb5e0ebd2c0f08e4b1bdc1708eb6a041
This commit is contained in:
committed by
Émilie Feral
parent
b2f81db4a9
commit
284c501532
@@ -53,7 +53,8 @@ public:
|
||||
* input, whereas the allowed output prefixes are prescribed manually. */
|
||||
enum class Prefixable {
|
||||
No,
|
||||
Yes
|
||||
Yes,
|
||||
PositiveOnly
|
||||
};
|
||||
enum class OutputSystem {
|
||||
None,
|
||||
@@ -73,7 +74,7 @@ public:
|
||||
}
|
||||
const char * rootSymbol() const { return m_rootSymbol; }
|
||||
const char * definition() const { return m_definition; }
|
||||
bool isPrefixable() const { return m_prefixable == Prefixable::Yes; }
|
||||
bool isPrefixable() const { return m_prefixable != Prefixable::No; }
|
||||
const Prefix * const * outputPrefixes() const { return m_outputPrefixes; }
|
||||
size_t outputPrefixesLength() const { return m_outputPrefixesLength; }
|
||||
bool canParse(const char * symbol, size_t length,
|
||||
@@ -334,7 +335,7 @@ public:
|
||||
NegativeLongScalePrefixes,
|
||||
Representative::OutputSystem::Metric),
|
||||
Representative("t", "1000_kg",
|
||||
Representative::Prefixable::Yes,
|
||||
Representative::Prefixable::PositiveOnly,
|
||||
NoPrefix,
|
||||
Representative::OutputSystem::Metric),
|
||||
Representative("Da", "(6.02214076*10^23*1000)^-1*_kg",
|
||||
|
||||
@@ -31,9 +31,10 @@ bool UnitNode::Representative::canParse(const char * symbol, size_t length,
|
||||
*prefix = &Unit::EmptyPrefix;
|
||||
return length == 0;
|
||||
}
|
||||
size_t numberOfPrefixes = sizeof(Unit::AllPrefixes)/sizeof(Unit::Prefix *);
|
||||
const Prefix * const * prefixesList = (m_prefixable == Prefixable::PositiveOnly) ? Unit::PositiveLongScalePrefixes : Unit::AllPrefixes;
|
||||
size_t numberOfPrefixes = ((m_prefixable == Prefixable::PositiveOnly) ? sizeof(Unit::PositiveLongScalePrefixes) : sizeof(Unit::AllPrefixes))/sizeof(Unit::Prefix *);
|
||||
for (size_t i = 0; i < numberOfPrefixes; i++) {
|
||||
const Prefix * pre = Unit::AllPrefixes[i];
|
||||
const Prefix * pre = prefixesList[i];
|
||||
const char * prefixSymbol = pre->symbol();
|
||||
if (strncmp(symbol, prefixSymbol, length) == 0 &&
|
||||
prefixSymbol[length] == 0)
|
||||
|
||||
Reference in New Issue
Block a user