Libkleo

stringutils.h
1 /*
2  utils/stringutils.h
3 
4  This file is part of libkleopatra
5  SPDX-FileCopyrightText: 2021 g10 Code GmbH
6  SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
7 
8  SPDX-License-Identifier: GPL-2.0-or-later
9 */
10 
11 #pragma once
12 
13 #include "kleo_export.h"
14 
15 #include <string>
16 #include <string_view>
17 #include <vector>
18 
19 namespace Kleo
20 {
21 
22 /** Splits the string @p s into substrings wherever the character @p c occurs,
23  * and returns the list of those strings. */
24 KLEO_EXPORT std::vector<std::string> split(const std::string &s, char c);
25 
26 /**
27  * Returns true if the string @p sv begins with the string @p prefix, false
28  * otherwise.
29  */
30 inline bool startsWith(std::string_view sv, std::string_view prefix)
31 {
32 #ifdef __cpp_lib_starts_ends_with
33  return sv.starts_with(prefix);
34 #else
35  return sv.substr(0, prefix.size()) == prefix;
36 #endif
37 }
38 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Thu Feb 15 2024 03:56:14 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.