1 #include <Core/Utils/StringUtils.hpp>
19 std::string getFileExt(
const std::string& str ) {
20 auto pos = str.find_last_of(
'.' );
21 std::string res = pos < str.length() ? str.substr( pos + 1 ) :
"";
25 std::string getDirName(
const std::string& path ) {
27 auto pos = path.find_last_not_of(
'/' );
30 if ( pos >= path.length() ) { pos = path.find_first_of(
"/" ); }
31 std::string res = path.substr( 0, pos + 1 );
34 pos = res.find_last_of(
'/' );
38 if ( pos == 0 ) { res =
"/"; }
39 else if ( pos < res.length() ) { res.resize( pos ); }
45 std::string getBaseName(
const std::string& path,
bool keepExtension ) {
47 auto pos = path.find_last_not_of(
'/' );
49 if ( pos >= path.length() ) { pos = path.find_first_of(
"/" ); }
50 std::string res = path.substr( 0, pos + 1 );
53 pos = res.find_last_of(
'/' );
54 if ( pos < res.length() ) { res = res.substr( pos + 1 ); }
55 if ( !keepExtension ) {
56 pos = res.find_last_of(
'.' );
57 if ( pos < res.length() ) { res.resize( pos ); }
63 std::size_t replaceAllInString( std::string& inout, std::string_view what, std::string_view with ) {
65 for ( std::string::size_type pos {};
66 inout.npos != ( pos = inout.find( what.data(), pos, what.length() ) );
67 pos += with.length(), ++count ) {
68 inout.replace( pos, what.length(), with.data(), with.length() );
73 std::size_t removeAllInString( std::string& inout, std::string_view what ) {
74 return replaceAllInString( inout, what,
"" );