Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
StringUtils.hxx
Go to the documentation of this file.
1/// \file ROOT/StringUtils.hxx
2/// \author Jonas Rembser <jonas.rembser@cern.ch>
3/// \date 2021-08-09
4
5/*************************************************************************
6 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#ifndef ROOT_StringUtils
14#define ROOT_StringUtils
15
16#include <string_view>
17
18#include <string>
19#include <vector>
20#include <numeric>
21#include <iterator>
22
23namespace ROOT {
24
25std::vector<std::string> Split(std::string_view str, std::string_view delims, bool skipEmpty = false);
26
27/**
28 * \brief Concatenate a list of strings with a separator
29 * \tparam StringCollection_t Any container of strings (vector, initializer_list, ...)
30 * \param[in] sep Separator inbetween the strings.
31 * \param[in] strings container of strings
32 * \return the sep-delimited concatenation of strings
33 */
34template <class StringCollection_t>
35std::string Join(const std::string &sep, StringCollection_t &&strings)
36{
37 if (strings.empty())
38 return "";
39 return std::accumulate(std::next(std::begin(strings)), std::end(strings), strings[0],
40 [&sep](auto const &a, auto const &b) { return a + sep + b; });
41}
42
43std::string Round(double value, double error, unsigned int cutoff = 1, std::string_view delim = "#pm");
44
45inline bool StartsWith(std::string_view string, std::string_view prefix)
46{
47 return string.size() >= prefix.size() && string.substr(0, prefix.size()) == prefix;
48}
49
50inline bool EndsWith(std::string_view string, std::string_view suffix)
51{
52 return string.size() >= suffix.size() && string.substr(string.size() - suffix.size(), suffix.size()) == suffix;
53}
54
55} // namespace ROOT
56
57#endif
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
bool EndsWith(std::string_view string, std::string_view suffix)
std::string Join(const std::string &sep, StringCollection_t &&strings)
Concatenate a list of strings with a separator.
bool StartsWith(std::string_view string, std::string_view prefix)
std::string Round(double value, double error, unsigned int cutoff=1, std::string_view delim="#pm")
Convert (round) a value and its uncertainty to string using one or two significant digits of the erro...
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.