From 359bd1ab15f79ef733b3517a716b3cce77080b68 Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Tue, 18 Jun 2019 20:21:51 +0100 Subject: [PATCH] Ref T633 Simplify whitespace in X-Plane flyable model strings. --- src/blackmisc/simulation/xplane/qtfreeutils.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/blackmisc/simulation/xplane/qtfreeutils.h b/src/blackmisc/simulation/xplane/qtfreeutils.h index 6986920a4..d21cf3806 100644 --- a/src/blackmisc/simulation/xplane/qtfreeutils.h +++ b/src/blackmisc/simulation/xplane/qtfreeutils.h @@ -129,6 +129,22 @@ namespace BlackMisc return s; } + //! Trim whitespace from the beginning and end, and replace sequences of whitespace with single space characters + inline std::string simplifyWhitespace(const std::string &s) + { + std::string result; + for (char c : s) + { + if (std::isspace(c)) + { + if (!result.empty() && result.back() != ' ') { result.push_back(' '); } + } + else { result.push_back(c); } + } + while (!result.empty() && result.back() == ' ') { result.pop_back(); } + return result; + } + //! Extract ACF properties from an aircraft file inline AcfProperties extractAcfProperties(const std::string &filePath) { @@ -184,7 +200,7 @@ namespace BlackMisc } fs.close(); - acfProperties.modelString = stringForFlyableModel(acfProperties, filePath); + acfProperties.modelString = simplifyWhitespace(stringForFlyableModel(acfProperties, filePath)); return acfProperties; } }