Commit 34ba6f99 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Add a helper for splitting a std::string

GnuPG-bug-id: 5666
parent be41844d
......@@ -53,6 +53,7 @@ target_sources(KF5Libkleo PRIVATE
utils/hex.cpp
utils/compat.cpp
utils/cryptoconfig.cpp
utils/stringutils.cpp
utils/test.cpp
)
ecm_qt_declare_logging_category(KF5Libkleo HEADER libkleo_debug.h IDENTIFIER LIBKLEO_LOG CATEGORY_NAME org.kde.pim.libkleo
......@@ -183,6 +184,7 @@ ecm_generate_headers(libkleo_CamelCase_utils_HEADERS
Formatting
GnuPG
Compat
StringUtils
Test
REQUIRED_HEADERS libkleo_utils_HEADERS
PREFIX Libkleo
......
/*
utils/string.cpp
This file is part of libkleopatra
SPDX-FileCopyrightText: 2021 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <config-libkleo.h>
#include "stringutils.h"
std::vector<std::string> Kleo::split(const std::string &s, char c)
{
std::vector<std::string> result;
auto start = 0;
auto end = s.find(c, start);
while (end != s.npos) {
result.push_back(s.substr(start, end - start));
start = end + 1;
end = s.find(c, start);
}
result.push_back(s.substr(start));
return result;
}
/*
utils/string.h
This file is part of libkleopatra
SPDX-FileCopyrightText: 2021 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <string>
#include <vector>
#include "kleo_export.h"
namespace Kleo
{
/** Splits the string @p s into substrings wherever the character @p c occurs,
* and returns the list of those strings. */
KLEO_EXPORT std::vector<std::string> split(const std::string &s, char c);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment