mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
RiaStdStringTools: Add method for removing white space
This commit is contained in:
@@ -52,6 +52,16 @@ std::string RiaStdStringTools::trimString( const std::string& s )
|
||||
return rightTrimString( leftTrimString( s ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::string RiaStdStringTools::removeWhitespace( const std::string& line )
|
||||
{
|
||||
std::string s = line;
|
||||
s.erase( std::remove_if( s.begin(), s.end(), isspace ), s.end() );
|
||||
return s;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -33,6 +33,7 @@ public:
|
||||
static std::string trimString( const std::string& s );
|
||||
static std::string rightTrimString( const std::string& s );
|
||||
static std::string leftTrimString( const std::string& s );
|
||||
static std::string removeWhitespace( const std::string& line );
|
||||
|
||||
static bool isNumber( const std::string& s, char decimalPoint );
|
||||
|
||||
|
||||
@@ -125,6 +125,28 @@ TEST( RiaStdStringToolsTest, RightTrimString )
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( RiaStdStringToolsTest, RemoveWhitespace )
|
||||
{
|
||||
std::vector<std::pair<std::string, std::string>> testData = {
|
||||
std::make_pair( " bla ", "bla" ),
|
||||
std::make_pair( "bla ", "bla" ),
|
||||
std::make_pair( " bla", "bla" ),
|
||||
std::make_pair( "\tbla", "bla" ),
|
||||
std::make_pair( "\tbla \n\t ,bla", "bla,bla" ),
|
||||
std::make_pair( "\tbla\v", "bla" ),
|
||||
std::make_pair( "bla", "bla" ),
|
||||
std::make_pair( "", "" ),
|
||||
};
|
||||
|
||||
for ( auto [input, expectedText] : testData )
|
||||
{
|
||||
EXPECT_EQ( RiaStdStringTools::removeWhitespace( input ), expectedText );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user