From: ageay Date: Fri, 12 Aug 2011 07:45:46 +0000 (+0000) Subject: Bug correction X-Git-Tag: V6_main_FINAL~992 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d3aa190dc4f5b6abf24774d1982e4d65e8a0da1d;p=tools%2Fmedcoupling.git Bug correction --- diff --git a/src/MEDLoader/MEDLoaderBase.cxx b/src/MEDLoader/MEDLoaderBase.cxx index 20cd511f8..3ff67c2e3 100644 --- a/src/MEDLoader/MEDLoaderBase.cxx +++ b/src/MEDLoader/MEDLoaderBase.cxx @@ -86,6 +86,11 @@ void MEDLoaderBase::splitIntoNameAndUnit(const std::string& s, std::string& name void MEDLoaderBase::strip(std::string& s) { std::string::size_type f1=s.find_first_not_of(' '); + if(f1==std::string::npos) + { + s=""; + return ; + } std::string::size_type f2=s.find_last_not_of(' '); s=s.substr(f1,f2-f1+1); } diff --git a/src/MEDLoader/Test/MEDLoaderTest.cxx b/src/MEDLoader/Test/MEDLoaderTest.cxx index 00bf51d14..ae93d5d1c 100644 --- a/src/MEDLoader/Test/MEDLoaderTest.cxx +++ b/src/MEDLoader/Test/MEDLoaderTest.cxx @@ -495,6 +495,30 @@ void MEDLoaderTest::testLittleStrings1() CPPUNIT_ASSERT(s=="azertty"); } +void MEDLoaderTest::testSplitIntoNameAndUnit1() +{ + std::string s(" []"); + std::string c,u; + MEDLoaderBase::splitIntoNameAndUnit(s,c,u); + CPPUNIT_ASSERT(c.empty()); + CPPUNIT_ASSERT(u.empty()); + s=" lmmm kki jjj "; + MEDLoaderBase::strip(s); + CPPUNIT_ASSERT(s=="lmmm kki jjj"); + s=" "; + MEDLoaderBase::strip(s); + CPPUNIT_ASSERT(s.empty()); + s=""; + MEDLoaderBase::strip(s); + CPPUNIT_ASSERT(s.empty()); + s=" "; + MEDLoaderBase::strip(s); + CPPUNIT_ASSERT(s.empty()); + s=" pp"; + MEDLoaderBase::strip(s); + CPPUNIT_ASSERT(s=="pp"); +} + void MEDLoaderTest::testMesh3DSurfShuffleRW() { const char fileName[]="file15.med"; diff --git a/src/MEDLoader/Test/MEDLoaderTest.hxx b/src/MEDLoader/Test/MEDLoaderTest.hxx index d91ebaaea..4605e9e36 100644 --- a/src/MEDLoader/Test/MEDLoaderTest.hxx +++ b/src/MEDLoader/Test/MEDLoaderTest.hxx @@ -45,6 +45,7 @@ namespace ParaMEDMEM CPPUNIT_TEST( testFieldGaussRW1 ); CPPUNIT_TEST( testFieldGaussNERW1 ); CPPUNIT_TEST( testLittleStrings1 ); + CPPUNIT_TEST( testSplitIntoNameAndUnit1 ); CPPUNIT_TEST( testMesh3DSurfShuffleRW ); CPPUNIT_TEST( testFieldShuffleRW1 ); CPPUNIT_TEST( testMultiFieldShuffleRW1 ); @@ -68,6 +69,7 @@ namespace ParaMEDMEM void testFieldGaussRW1(); void testFieldGaussNERW1(); void testLittleStrings1(); + void testSplitIntoNameAndUnit1(); void testMesh3DSurfShuffleRW(); void testFieldShuffleRW1(); void testMultiFieldShuffleRW1();