mCRL2
Loading...
Searching...
No Matches
split.h
Go to the documentation of this file.
1// Author(s): Wieger Wesselink
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
11
12#ifndef MCRL2_UTILITIES_DETAIL_SPLIT_H
13#define MCRL2_UTILITIES_DETAIL_SPLIT_H
14
16#include <map>
17
18namespace mcrl2 {
19
20namespace utilities {
21
22namespace detail {
23
24 // Splits a text into non-empty sections. The sections are trimmed.
25 inline
26 std::vector<std::string> split_text(const std::string& text, const std::string& keyword)
27 {
28 std::vector<std::string> result;
29 std::vector<std::string> sections = utilities::regex_split(text, keyword);
30 for (std::string& section: sections)
31 {
32 boost::trim(section);
33 if (!section.empty())
34 {
35 result.push_back(section);
36 }
37 }
38 return result;
39 }
40
41 // Splits a text into sections based on keywords. The result maps keywords to the corresponding text.
42 inline
43 std::map<std::string, std::string> split_text_using_keywords(const std::string& text, const std::vector<std::string>& keywords)
44 {
45 std::map<std::string, std::string> result;
46 std::string text1 = text;
47 for (auto i = keywords.begin(); i != keywords.end(); ++i)
48 {
49 const std::string& keyword = *i;
50 std::pair<std::string, std::string> p = separate_keyword_section(text1, keyword, keywords);
51 result[keyword] = p.first;
52 text1 = p.second;
53 }
54 return result;
55 }
56
57 // Splits a text into nonempty lines, and returns them. The lines are trimmed.
58 inline
59 std::vector<std::string> nonempty_lines(const std::string& text)
60 {
61 std::vector<std::string> lines = utilities::regex_split(text, "\\n");
62 std::vector<std::string> result;
63 for (std::string& line: lines)
64 {
65 boost::trim(line);
66 if (!line.empty())
67 {
68 result.push_back(line);
69 }
70 }
71 return result;
72 }
73
74} // namespace detail
75
76} // namespace utilities
77
78} // namespace mcrl2
79
80#endif // MCRL2_UTILITIES_DETAIL_SPLIT_H
std::map< std::string, std::string > split_text_using_keywords(const std::string &text, const std::vector< std::string > &keywords)
Definition split.h:43
std::vector< std::string > nonempty_lines(const std::string &text)
Definition split.h:59
std::pair< std::string, std::string > separate_keyword_section(const std::string &text1, const std::string &keyword, const std::vector< std::string > &all_keywords, bool repeat_keyword=false)
std::vector< std::string > split_text(const std::string &text, const std::string &keyword)
Definition split.h:26
std::vector< std::string > regex_split(const std::string &text, const std::string &sep)
Split a string using a regular expression separator.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
add your file description here.