From dc14168e2f39144bb9e812484c6071380c4f8beb Mon Sep 17 00:00:00 2001 From: akva Date: Thu, 5 May 2011 13:18:43 +0000 Subject: [PATCH] added: a class for general string utilities git-svn-id: http://svn.sintef.no/trondheim/IFEM/trunk@926 e10b68d5-8a6e-419e-a041-bce267b0401d --- src/Utility/StringUtils.C | 27 +++++++++++++++++++++++++++ src/Utility/StringUtils.h | 16 ++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/Utility/StringUtils.C create mode 100644 src/Utility/StringUtils.h diff --git a/src/Utility/StringUtils.C b/src/Utility/StringUtils.C new file mode 100644 index 00000000..d6951083 --- /dev/null +++ b/src/Utility/StringUtils.C @@ -0,0 +1,27 @@ +//============================================================================== +//! +//! \file StringUtils.C +//! +//! \date Feb 17 2011 +//! +//! \author Arne Morten Kvarving / SINTEF +//! +//! \brief Some general string manipulation functions +//! +//============================================================================== + +#include + +// 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; +} diff --git a/src/Utility/StringUtils.h b/src/Utility/StringUtils.h new file mode 100644 index 00000000..b1956566 --- /dev/null +++ b/src/Utility/StringUtils.h @@ -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 + +std::string& replaceAll(std::string& context, + const std::string& from, const std::string& to);