Ref T633 Simplify whitespace in X-Plane flyable model strings.

This commit is contained in:
Mat Sutcliffe
2019-06-18 20:21:51 +01:00
parent 61439a48e0
commit 359bd1ab15

View File

@@ -129,6 +129,22 @@ namespace BlackMisc
return s; 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 //! Extract ACF properties from an aircraft file
inline AcfProperties extractAcfProperties(const std::string &filePath) inline AcfProperties extractAcfProperties(const std::string &filePath)
{ {
@@ -184,7 +200,7 @@ namespace BlackMisc
} }
fs.close(); fs.close();
acfProperties.modelString = stringForFlyableModel(acfProperties, filePath); acfProperties.modelString = simplifyWhitespace(stringForFlyableModel(acfProperties, filePath));
return acfProperties; return acfProperties;
} }
} }