mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-03 04:00:57 -06:00
The file had DOS line endings (\t\n) which where not properly trimmed on linux. Fixes #8652.
This commit is contained in:
parent
80234ca105
commit
86ea679871
@ -23,15 +23,32 @@
|
||||
#include <cctype>
|
||||
#include <charconv>
|
||||
|
||||
const std::string WHITESPACE = " \n\r\t\f\v";
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::string RiaStdStringTools::leftTrimString( const std::string& s )
|
||||
{
|
||||
size_t start = s.find_first_not_of( WHITESPACE );
|
||||
return ( start == std::string::npos ) ? "" : s.substr( start );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::string RiaStdStringTools::rightTrimString( const std::string& s )
|
||||
{
|
||||
size_t end = s.find_last_not_of( WHITESPACE );
|
||||
return ( end == std::string::npos ) ? "" : s.substr( 0, end + 1 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::string RiaStdStringTools::trimString( const std::string& s )
|
||||
{
|
||||
auto sCopy = s.substr( 0, s.find_last_not_of( ' ' ) + 1 );
|
||||
sCopy = sCopy.substr( sCopy.find_first_not_of( ' ' ) );
|
||||
|
||||
return sCopy;
|
||||
return rightTrimString( leftTrimString( s ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -31,7 +31,10 @@ class RiaStdStringTools
|
||||
{
|
||||
public:
|
||||
static std::string trimString( const std::string& s );
|
||||
static bool isNumber( const std::string& s, char decimalPoint );
|
||||
static std::string rightTrimString( const std::string& s );
|
||||
static std::string leftTrimString( const std::string& s );
|
||||
|
||||
static bool isNumber( const std::string& s, char decimalPoint );
|
||||
|
||||
static int16_t toInt16( const std::string& s );
|
||||
static int toInt( const std::string& s );
|
||||
|
@ -89,7 +89,7 @@ void RifSurfaceImporter::readGocadFile( const QString& filename, RigGocadData* g
|
||||
auto tokens = RiaStdStringTools::splitString( line, ' ' );
|
||||
|
||||
std::string firstToken;
|
||||
if ( !tokens.empty() ) firstToken = tokens.front();
|
||||
if ( !tokens.empty() ) firstToken = RiaStdStringTools::trimString( tokens.front() );
|
||||
|
||||
if ( isInTfaceSection )
|
||||
{
|
||||
|
@ -59,6 +59,72 @@ TEST( RiaStdStringToolsTest, TrimStrings )
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( RiaStdStringToolsTest, TrimString )
|
||||
{
|
||||
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" ),
|
||||
std::make_pair( "\tbla\v", "bla" ),
|
||||
std::make_pair( "bla", "bla" ),
|
||||
std::make_pair( "", "" ),
|
||||
};
|
||||
|
||||
for ( auto [input, expectedText] : testData )
|
||||
{
|
||||
EXPECT_EQ( RiaStdStringTools::trimString( input ), expectedText );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( RiaStdStringToolsTest, LeftTrimString )
|
||||
{
|
||||
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 \n\t" ),
|
||||
std::make_pair( "\tbla\v", "bla\v" ),
|
||||
std::make_pair( "bla", "bla" ),
|
||||
std::make_pair( "", "" ),
|
||||
};
|
||||
|
||||
for ( auto [input, expectedText] : testData )
|
||||
{
|
||||
EXPECT_EQ( RiaStdStringTools::leftTrimString( input ), expectedText );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( RiaStdStringToolsTest, RightTrimString )
|
||||
{
|
||||
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", "\tbla" ),
|
||||
std::make_pair( "\tbla \n\t", "\tbla" ),
|
||||
std::make_pair( "\tbla\v", "\tbla" ),
|
||||
std::make_pair( "bla", "bla" ),
|
||||
std::make_pair( "", "" ),
|
||||
};
|
||||
|
||||
for ( auto [input, expectedText] : testData )
|
||||
{
|
||||
EXPECT_EQ( RiaStdStringTools::rightTrimString( input ), expectedText );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user