forked from mirrors/nixpkgs
92 lines
2.7 KiB
Diff
92 lines
2.7 KiB
Diff
|
diff --git a/include/openspace/util/distanceconversion.h b/include/openspace/util/distanceconversion.h
|
||
|
index 80a3a96..7059752 100755
|
||
|
--- a/include/openspace/util/distanceconversion.h
|
||
|
+++ b/include/openspace/util/distanceconversion.h
|
||
|
@@ -159,24 +159,34 @@ constexpr const char* nameForDistanceUnit(DistanceUnit unit, bool pluralForm = f
|
||
|
}
|
||
|
|
||
|
constexpr DistanceUnit distanceUnitFromString(const char* unitName) {
|
||
|
+ int result = -1;
|
||
|
+
|
||
|
int i = 0;
|
||
|
for (const char* val : DistanceUnitNamesSingular) {
|
||
|
if (ghoul::equal(unitName, val)) {
|
||
|
- return static_cast<DistanceUnit>(i);
|
||
|
+ result = i;
|
||
|
+ break;
|
||
|
}
|
||
|
++i;
|
||
|
}
|
||
|
|
||
|
- i = 0;
|
||
|
- for (const char* val : DistanceUnitNamesPlural) {
|
||
|
- if (ghoul::equal(unitName, val)) {
|
||
|
- return static_cast<DistanceUnit>(i);
|
||
|
+ if (result == -1) {
|
||
|
+ i = 0;
|
||
|
+ for (const char* val : DistanceUnitNamesPlural) {
|
||
|
+ if (ghoul::equal(unitName, val)) {
|
||
|
+ result = i;
|
||
|
+ break;
|
||
|
+ }
|
||
|
+ ++i;
|
||
|
}
|
||
|
- ++i;
|
||
|
}
|
||
|
|
||
|
- ghoul_assert(false, "Unit name is not a valid name");
|
||
|
- throw ghoul::MissingCaseException();
|
||
|
+ if (result != -1)
|
||
|
+ return static_cast<DistanceUnit>(result);
|
||
|
+ else {
|
||
|
+ ghoul_assert(false, "Unit name is not a valid name");
|
||
|
+ throw ghoul::MissingCaseException();
|
||
|
+ }
|
||
|
}
|
||
|
|
||
|
|
||
|
diff --git a/include/openspace/util/timeconversion.h b/include/openspace/util/timeconversion.h
|
||
|
index a36c92a..699bca9 100755
|
||
|
--- a/include/openspace/util/timeconversion.h
|
||
|
+++ b/include/openspace/util/timeconversion.h
|
||
|
@@ -142,23 +142,32 @@ constexpr const char* nameForTimeUnit(TimeUnit unit, bool pluralForm = false) {
|
||
|
}
|
||
|
|
||
|
constexpr TimeUnit timeUnitFromString(const char* unitName) {
|
||
|
+ int result = -1;
|
||
|
+
|
||
|
int i = 0;
|
||
|
for (const char* val : TimeUnitNamesSingular) {
|
||
|
if (ghoul::equal(unitName, val)) {
|
||
|
- return static_cast<TimeUnit>(i);
|
||
|
+ result = i;
|
||
|
+ break;
|
||
|
}
|
||
|
++i;
|
||
|
}
|
||
|
|
||
|
- i = 0;
|
||
|
- for (const char* val : TimeUnitNamesPlural) {
|
||
|
- if (ghoul::equal(unitName, val)) {
|
||
|
- return static_cast<TimeUnit>(i);
|
||
|
+ if (result == -1) {
|
||
|
+ i = 0;
|
||
|
+ for (const char* val : TimeUnitNamesPlural) {
|
||
|
+ if (ghoul::equal(unitName, val)) {
|
||
|
+ result = i;
|
||
|
+ break;
|
||
|
+ }
|
||
|
+ ++i;
|
||
|
}
|
||
|
- ++i;
|
||
|
}
|
||
|
|
||
|
- throw ghoul::MissingCaseException();
|
||
|
+ if (result != -1)
|
||
|
+ return static_cast<TimeUnit>(result);
|
||
|
+ else
|
||
|
+ throw ghoul::MissingCaseException();
|
||
|
}
|
||
|
|
||
|
std::pair<double, std::string> simplifyTime(double seconds,
|