AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
strings.h
1#ifndef UTILS_STRINGS_H
2#define UTILS_STRINGS_H
3
4#include "downward/utils/exceptions.h"
5
6#include <sstream>
7#include <string>
8#include <vector>
9
10namespace utils {
11extern void lstrip(std::string& s);
12extern void rstrip(std::string& s);
13extern void strip(std::string& s);
14
15/*
16 Split a given string at the first max_splits occurrence of separator. Use
17 the default of -1 for an unlimited amount of splits.
18*/
19extern std::vector<std::string>
20split(const std::string& s, const std::string& separator, int max_splits = -1);
21
22extern bool startswith(const std::string& s, const std::string& prefix);
23
24extern std::string tolower(std::string s);
25
26template <typename Collection>
27std::string join(const Collection& collection, const std::string& delimiter)
28{
29 std::ostringstream oss;
30 bool first_item = true;
31
32 for (const auto& item : collection) {
33 if (first_item)
34 first_item = false;
35 else
36 oss << delimiter;
37 oss << item;
38 }
39 return oss.str();
40}
41
42extern bool is_alpha_numeric(const std::string& s);
43} // namespace utils
44#endif