diff --git a/components/compiler/lineparser.cpp b/components/compiler/lineparser.cpp index 2d551348d..602bb826f 100644 --- a/components/compiler/lineparser.cpp +++ b/components/compiler/lineparser.cpp @@ -557,7 +557,7 @@ namespace Compiler mExplicit.clear(); } - void GetArgumentsFromMessageFormat::visitedPlaceholder(Placeholder placeholder, char /*padding*/, int /*width*/, int /*precision*/) + void GetArgumentsFromMessageFormat::visitedPlaceholder(Placeholder placeholder, char /*padding*/, int /*width*/, int /*precision*/, Notation /*notation*/) { switch (placeholder) { diff --git a/components/compiler/lineparser.hpp b/components/compiler/lineparser.hpp index d92c4895e..8f7f64bf2 100644 --- a/components/compiler/lineparser.hpp +++ b/components/compiler/lineparser.hpp @@ -83,7 +83,7 @@ namespace Compiler std::string mArguments; protected: - virtual void visitedPlaceholder(Placeholder placeholder, char padding, int width, int precision); + virtual void visitedPlaceholder(Placeholder placeholder, char padding, int width, int precision, Notation notation); virtual void visitedCharacter(char c) {} public: diff --git a/components/interpreter/miscopcodes.hpp b/components/interpreter/miscopcodes.hpp index 20a1b52be..03b7e186f 100644 --- a/components/interpreter/miscopcodes.hpp +++ b/components/interpreter/miscopcodes.hpp @@ -24,7 +24,7 @@ namespace Interpreter Runtime& mRuntime; protected: - virtual void visitedPlaceholder(Placeholder placeholder, char padding, int width, int precision) + virtual void visitedPlaceholder(Placeholder placeholder, char padding, int width, int precision, Notation notation) { std::ostringstream out; out.fill(padding); @@ -58,8 +58,34 @@ namespace Interpreter float value = mRuntime[0].mFloat; mRuntime.pop(); - out << std::fixed << value; - mFormattedMessage += out.str(); + if (notation == FixedNotation) + { + out << std::fixed << value; + mFormattedMessage += out.str(); + } + else if (notation == ShortestNotation) + { + std::string scientific; + std::string fixed; + + out << std::scientific << value; + + scientific = out.str(); + + out.str(std::string()); + out.clear(); + + out << std::fixed << value; + + fixed = out.str(); + + mFormattedMessage += fixed.length() < scientific.length() ? fixed : scientific; + } + else + { + out << std::scientific << value; + mFormattedMessage += out.str(); + } } break; default: diff --git a/components/misc/messageformatparser.cpp b/components/misc/messageformatparser.cpp index 3a35c83ea..6f0e47132 100644 --- a/components/misc/messageformatparser.cpp +++ b/components/misc/messageformatparser.cpp @@ -49,11 +49,15 @@ namespace Misc width = (widthSet) ? width : -1; if (m[i] == 'S' || m[i] == 's') - visitedPlaceholder(StringPlaceholder, pad, width, precision); - else if (m[i] == 'g' || m[i] == 'G') - visitedPlaceholder(IntegerPlaceholder, pad, width, precision); + visitedPlaceholder(StringPlaceholder, pad, width, precision, FixedNotation); + else if (m[i] == 'd' || m[i] == 'i') + visitedPlaceholder(IntegerPlaceholder, pad, width, precision, FixedNotation); else if (m[i] == 'f' || m[i] == 'F') - visitedPlaceholder(FloatPlaceholder, pad, width, precision); + visitedPlaceholder(FloatPlaceholder, pad, width, precision, FixedNotation); + else if (m[i] == 'e' || m[i] == 'E') + visitedPlaceholder(FloatPlaceholder, pad, width, precision, ScientificNotation); + else if (m[i] == 'g' || m[i] == 'G') + visitedPlaceholder(FloatPlaceholder, pad, width, precision, ShortestNotation); } } } diff --git a/components/misc/messageformatparser.hpp b/components/misc/messageformatparser.hpp index c12b9352a..db2a8b0af 100644 --- a/components/misc/messageformatparser.hpp +++ b/components/misc/messageformatparser.hpp @@ -15,7 +15,14 @@ namespace Misc FloatPlaceholder }; - virtual void visitedPlaceholder(Placeholder placeholder, char padding, int width, int precision) = 0; + enum Notation + { + FixedNotation, + ScientificNotation, + ShortestNotation + }; + + virtual void visitedPlaceholder(Placeholder placeholder, char padding, int width, int precision, Notation notation) = 0; virtual void visitedCharacter(char c) = 0; public: