///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2017 Statoil ASA // // ResInsight is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. // // See the GNU General Public License at // for more details. // ///////////////////////////////////////////////////////////////////////////////// #pragma once #include #include #include #include #include //================================================================================================== // //================================================================================================== class RiaStdStringTools { public: static std::string trimString( 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 ); static double toDouble( const std::string& s ); static bool containsAlphabetic( const std::string& s ); static bool startsWithAlphabetic( const std::string& s ); static bool endsWith( const std::string& mainStr, const std::string& toMatch ); static std::vector splitStringBySpace( const std::string& s ); static int computeEditDistance( const std::string& x, const std::string& y); private: template static void splitByDelimiter( const std::string& str, Container& cont, char delimiter = ' ' ); static size_t findCharMatchCount( const std::string& s, char c ); }; //================================================================================================== // //================================================================================================== template void RiaStdStringTools::splitByDelimiter( const std::string& str, Container& cont, char delimiter ) { std::stringstream ss( str ); std::string token; while ( std::getline( ss, token, delimiter ) ) { if ( token.find_first_not_of( delimiter ) != std::string::npos ) { cont.push_back( token ); } } }