mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-13 17:02:13 -05:00
Add realization filtering based on text string
Add unit tests and support min max range specifications. Example string "-5, 5, 8-10, 12-"
This commit is contained in:
1 parent
691b73d7f4
commit
785871cae3
8 files changed
+245
-4
No files matched your search
@@ -157,3 +157,11 @@ QString RiaDefines::summaryCalculated()
|
||||
{
|
||||
return "Calculated";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::summaryRealizationNumber()
|
||||
{
|
||||
return "RI:REALIZATION_NUM";
|
||||
}
|
||||
@@ -52,4 +52,6 @@ QString summaryLgrWell();
|
||||
QString summaryLgrBlock();
|
||||
QString summaryCalculated();
|
||||
|
||||
QString summaryRealizationNumber();
|
||||
|
||||
}; // namespace RiaDefines
|
||||
@@ -17,9 +17,12 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RiaStdStringTools.h"
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "fast_float/include/fast_float/fast_float.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <charconv>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
@@ -301,3 +304,118 @@ std::string RiaStdStringTools::removeHtmlTags( const std::string& s )
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::set<int> RiaStdStringTools::valuesFromRangeSelection( const std::string& s )
|
||||
{
|
||||
try
|
||||
{
|
||||
std::set<int> result;
|
||||
std::istringstream stringStream( s );
|
||||
std::string token;
|
||||
|
||||
while ( std::getline( stringStream, token, ',' ) )
|
||||
{
|
||||
token = RiaStdStringTools::trimString( token );
|
||||
|
||||
std::istringstream tokenStream( token );
|
||||
int startIndex, endIndex;
|
||||
char dash;
|
||||
|
||||
if ( tokenStream >> startIndex )
|
||||
{
|
||||
if ( tokenStream >> dash && dash == '-' && tokenStream >> endIndex )
|
||||
{
|
||||
if ( startIndex > endIndex )
|
||||
{
|
||||
// If start is greater than end, swap them
|
||||
std::swap( startIndex, endIndex );
|
||||
}
|
||||
|
||||
for ( int i = startIndex; i <= endIndex; ++i )
|
||||
{
|
||||
result.insert( i );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result.insert( startIndex );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch ( const std::exception& e )
|
||||
{
|
||||
QString str = QString( "Failed to convert text string \" %1 \" to list of integers : " ).arg( QString::fromStdString( s ) ) +
|
||||
QString::fromStdString( e.what() );
|
||||
RiaLogging::error( str );
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
QString str =
|
||||
QString( "Failed to convert text string \" %1 \" to list of integers : Caught unknown exception" ).arg( QString::fromStdString( s ) );
|
||||
RiaLogging::error( str );
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::set<int> RiaStdStringTools::valuesFromRangeSelection( const std::string& s, int minVal, int maxVal )
|
||||
{
|
||||
try
|
||||
{
|
||||
std::set<int> result;
|
||||
std::stringstream stringStream( s );
|
||||
std::string token;
|
||||
|
||||
while ( std::getline( stringStream, token, ',' ) )
|
||||
{
|
||||
token = RiaStdStringTools::trimString( token );
|
||||
|
||||
// Check for range
|
||||
size_t dashPos = token.find( '-' );
|
||||
if ( dashPos != std::string::npos )
|
||||
{
|
||||
int startIndex = ( dashPos == 0 ) ? minVal : std::stoi( token.substr( 0, dashPos ) );
|
||||
int endIndex = ( dashPos == token.size() - 1 ) ? maxVal : std::stoi( token.substr( dashPos + 1 ) );
|
||||
if ( startIndex > endIndex )
|
||||
{
|
||||
// If start is greater than end, swap them
|
||||
std::swap( startIndex, endIndex );
|
||||
}
|
||||
for ( int i = startIndex; i <= endIndex; ++i )
|
||||
{
|
||||
result.insert( i );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check for individual numbers
|
||||
result.insert( std::stoi( token ) );
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch ( const std::exception& e )
|
||||
{
|
||||
QString str = QString( "Failed to convert text string \" %1 \" to list of integers : " ).arg( QString::fromStdString( s ) ) +
|
||||
QString::fromStdString( e.what() );
|
||||
RiaLogging::error( str );
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
QString str =
|
||||
QString( "Failed to convert text string \" %1 \" to list of integers : Caught unknown exception" ).arg( QString::fromStdString( s ) );
|
||||
RiaLogging::error( str );
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <numeric>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -60,6 +61,13 @@ public:
|
||||
|
||||
static std::string removeHtmlTags( const std::string& s );
|
||||
|
||||
// Convert the string "1,2,5-8,10" to {1, 2, 5, 6, 7, 8, 10}
|
||||
static std::set<int> valuesFromRangeSelection( const std::string& s );
|
||||
|
||||
// Convert the range string with support for open ended expressions. minimum and maximum value will be used to limit the ranges.
|
||||
// The input "-3,5-8,10-", min:1, max:12 will produce {1, 2, 3, 5, 6, 7, 8, 10, 11, 12}
|
||||
static std::set<int> valuesFromRangeSelection( const std::string& s, int minimumValue, int maximumValue );
|
||||
|
||||
private:
|
||||
template <class Container>
|
||||
static void splitByDelimiter( const std::string& str, Container& cont, char delimiter = ' ' );
|
||||
|
||||
Reference in new issue
Block a user