MeshLib
 
Loading...
Searching...
No Matches
MRMesh/MRString.h
Go to the documentation of this file.
1#pragma once
2#include "MRMeshFwd.h"
3#include <string>
4#include <typeinfo>
5
6namespace MR
7{
8
14[[nodiscard]] MRMESH_API size_t findSubstringCaseInsensitive( const std::string& string, const std::string& substring );
15
20[[nodiscard]] MRMESH_API int calcDamerauLevenshteinDistance( const std::string& stringA, const std::string& stringB,
21 bool caseSensitive = true );
22
28[[nodiscard]] MRMESH_API std::vector<std::string> split( const std::string& string, const std::string& delimiter );
29
30// This version of `split()` passes the segments to a callback, to avoid heap allocations.
31// If the callback returns true, stops immediately and also returns true.
32template <typename F>
33bool split( std::string_view str, std::string_view sep, F&& func )
34{
35 std::size_t index = 0;
36
37 while ( true )
38 {
39 std::size_t newIndex = str.find( sep, index );
40 if ( func( str.substr( index, newIndex - index ) ) )
41 return true;
42 if ( newIndex == std::string_view::npos )
43 break;
44 index = newIndex + sep.size();
45 }
46 return false;
47}
48
50[[nodiscard]] MRMESH_API std::string replace( std::string target, std::string_view from, std::string_view to );
51
53MRMESH_API void replaceInplace( std::string& target, std::string_view from, std::string_view to );
54
55} //namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
MRMESH_API size_t findSubstringCaseInsensitive(const std::string &string, const std::string &substring)
MRMESH_API std::vector< std::string > split(const std::string &string, const std::string &delimiter)
MRMESH_API int calcDamerauLevenshteinDistance(const std::string &stringA, const std::string &stringB, bool caseSensitive=true)
Definition MRCameraOrientationPlugin.h:7
MRMESH_API std::string replace(std::string target, std::string_view from, std::string_view to)
Returns.
MRMESH_API void replaceInplace(std::string &target, std::string_view from, std::string_view to)
Replaces.