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:
akva
2011-05-05 13:18:43 +00:00
committed by Knut Morten Okstad
parent 9d7a0b1c0a
commit dc14168e2f
2 changed files with 43 additions and 0 deletions

27
src/Utility/StringUtils.C Normal file
View 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
View 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);