added: a class for general string utilities
git-svn-id: http://svn.sintef.no/trondheim/IFEM/trunk@926 e10b68d5-8a6e-419e-a041-bce267b0401d
This commit is contained in:
27
src/Utility/StringUtils.C
Normal file
27
src/Utility/StringUtils.C
Normal file
@@ -0,0 +1,27 @@
|
||||
//==============================================================================
|
||||
//!
|
||||
//! \file StringUtils.C
|
||||
//!
|
||||
//! \date Feb 17 2011
|
||||
//!
|
||||
//! \author Arne Morten Kvarving / SINTEF
|
||||
//!
|
||||
//! \brief Some general string manipulation functions
|
||||
//!
|
||||
//==============================================================================
|
||||
|
||||
#include <StringUtils.h>
|
||||
|
||||
// taken from cppreference.com ::replace documentation
|
||||
std::string& replaceAll(std::string& context, const std::string& from,
|
||||
const std::string& to)
|
||||
{
|
||||
size_t lookHere = 0;
|
||||
size_t foundHere;
|
||||
while((foundHere = context.find(from, lookHere)) != std::string::npos)
|
||||
{
|
||||
context.replace(foundHere, from.size(), to);
|
||||
lookHere = foundHere + to.size();
|
||||
}
|
||||
return context;
|
||||
}
|
||||
16
src/Utility/StringUtils.h
Normal file
16
src/Utility/StringUtils.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
//==============================================================================
|
||||
//!
|
||||
//! \file StringUtils.h
|
||||
//!
|
||||
//! \date Feb 17 2011
|
||||
//!
|
||||
//! \author Arne Morten Kvarving / SINTEF
|
||||
//!
|
||||
//! \brief Some general string manipulation functions
|
||||
//!
|
||||
//==============================================================================
|
||||
#include <string>
|
||||
|
||||
std::string& replaceAll(std::string& context,
|
||||
const std::string& from, const std::string& to);
|
||||
Reference in New Issue
Block a user