mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
ASCII import dialog. Determine default decimal separator
This commit is contained in:
@@ -371,6 +371,55 @@ QString RifCsvUserDataParser::tryDetermineCellSeparator()
|
||||
return "";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RifCsvUserDataParser::tryDetermineDecimalSeparator(const QString& cellSeparator)
|
||||
{
|
||||
QTextStream* dataStream = openDataStream();
|
||||
std::vector<QString> lines;
|
||||
int iLine = 0;
|
||||
|
||||
int successfulParsesDot = 0;
|
||||
int successfulParsesComma = 0;
|
||||
|
||||
while (iLine < 10 && !dataStream->atEnd())
|
||||
{
|
||||
QString line = dataStream->readLine();
|
||||
if (line.isEmpty()) continue;
|
||||
|
||||
for (QString cellData : splitLineAndTrim(line, cellSeparator))
|
||||
{
|
||||
bool parseOk;
|
||||
QLocale locale;
|
||||
|
||||
locale = localeFromDecimalSeparator(".");
|
||||
locale.toDouble(cellData, &parseOk);
|
||||
if (parseOk) successfulParsesDot++;
|
||||
|
||||
locale = localeFromDecimalSeparator(",");
|
||||
locale.toDouble(cellData, &parseOk);
|
||||
if (parseOk) successfulParsesComma++;
|
||||
}
|
||||
}
|
||||
closeDataStream();
|
||||
|
||||
if (successfulParsesComma > successfulParsesDot) return ",";
|
||||
else return ".";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QLocale RifCsvUserDataParser::localeFromDecimalSeparator(const QString& decimalSeparator)
|
||||
{
|
||||
if (decimalSeparator == ",")
|
||||
{
|
||||
return QLocale::Norwegian;
|
||||
}
|
||||
return QLocale::c();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user