mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-31 17:17:50 -05:00
Improves string trimming and parsing
Refactors string trimming functions for improved performance by using a lookup table for whitespace characters. Also adds a function to split a string into two tokens at the first whitespace.
This commit is contained in:
1 parent
efc8735a76
commit
2305a73908
3 files changed
+126
-9
No files matched your search
@@ -95,6 +95,7 @@ TEST( RiaStdStringToolsTest, LeftTrimString )
|
||||
std::make_pair( "\tbla\v", "bla\v" ),
|
||||
std::make_pair( "bla", "bla" ),
|
||||
std::make_pair( "", "" ),
|
||||
std::make_pair( "\t\t\t\t\t\t\t\t", "" ),
|
||||
};
|
||||
|
||||
for ( auto [input, expectedText] : testData )
|
||||
@@ -117,6 +118,7 @@ TEST( RiaStdStringToolsTest, RightTrimString )
|
||||
std::make_pair( "\tbla\v", "\tbla" ),
|
||||
std::make_pair( "bla", "bla" ),
|
||||
std::make_pair( "", "" ),
|
||||
std::make_pair( "\t\t\t\t\t\t\t\t", "" ),
|
||||
};
|
||||
|
||||
for ( auto [input, expectedText] : testData )
|
||||
@@ -139,6 +141,8 @@ TEST( RiaStdStringToolsTest, RemoveWhitespace )
|
||||
std::make_pair( "\tbla\v", "bla" ),
|
||||
std::make_pair( "bla", "bla" ),
|
||||
std::make_pair( "", "" ),
|
||||
std::make_pair( "\t\t\t\t\t\t\t\t", "" ),
|
||||
|
||||
};
|
||||
|
||||
for ( auto [input, expectedText] : testData )
|
||||
@@ -147,6 +151,29 @@ TEST( RiaStdStringToolsTest, RemoveWhitespace )
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( RiaStdStringToolsTest, StringInTwoTokens )
|
||||
{
|
||||
std::vector<std::pair<std::string, 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( "bla", "bla" ) ),
|
||||
std::make_pair( " bla bla ", std::make_pair( "bla", "bla" ) ),
|
||||
std::make_pair( "\tbla\tbla\t", std::make_pair( "bla", "bla" ) ),
|
||||
std::make_pair( "\tbla\v bla\v", std::make_pair( "bla", "bla" ) ),
|
||||
std::make_pair( "", std::make_pair( "", "" ) ),
|
||||
std::make_pair( "\t\t\t\t\t\t\t\t", std::make_pair( "", "" ) ),
|
||||
};
|
||||
|
||||
for ( auto [input, expectedText] : testData )
|
||||
{
|
||||
const auto& [first, second] = RiaStdStringTools::splitAtWhitespace( input );
|
||||
EXPECT_EQ( first, expectedText.first );
|
||||
EXPECT_EQ( second, expectedText.second );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user