Select Git revision
-
Lava Block authoredLava Block authored
strops.cpp 4.74 KiB
//SPDX-License-Identifier: LGPL-3.0-or-later
//
// eisgenerator - a shared libary and application to generate EIS spectra
// Copyright (C) 2022-2024 Carl Philipp Klemm <carl@uvos.xyz>
//
// This file is part of eisgenerator.
//
// eisgenerator is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// eisgenerator is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with eisgenerator. If not, see <http://www.gnu.org/licenses/>.
//
#include "strops.h"
#include <algorithm>
#include <cassert>
#include "log.h"
namespace eis
{
char getOpposingBracketChar(const char ch)
{
switch(ch)
{
case '(':
return ')';
case ')':
return '(';
case '{':
return '}';
case '}':
return '{';
case '[':
return ']';
case ']':
return '[';
case '<':
return '>';
default:
eis::Log(eis::Log::ERROR)<<ch<<" is not a valid bracket char";
assert(false);
}
return 'x';
}
std::vector<std::string> tokenize(const std::string& str, const char delim, const char ignBracketStart, const char ignBracketEnd, const char escapeChar)
{
std::vector<std::string> tokens;
std::string token;
size_t bracketCounter = 0;
for(size_t i = 0; i < str.size(); ++i)
{
if(str[i] == delim && bracketCounter == 0 && (i == 0 || str[i-1] != escapeChar))
{
tokens.push_back(token);
token.clear();
}
else
{