Mania++
 All Classes Functions Variables Pages
Formatting.h
1 #ifndef FORMATTING_H_
2 #define FORMATTING_H_
3 
4 #include <regex>
5 #include <string>
6 #include <sstream>
7 
8 #include <boost/algorithm/string/replace.hpp>
9 
10 //* Formatting
15 {
16 public:
23  static std::string StripColors(std::string src, bool forTM = true)
24  {
25  std::regex color = std::regex("([$][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])");
26  src = std::regex_replace(src, color, "");
27 
28  std::regex wrongcolor = std::regex("([$][0-9a-fA-F][0-9a-fA-F])");
29  src = std::regex_replace(src, wrongcolor, "");
30 
31  src = std::regex_replace(src, std::regex("([$][$])"), "\t");
32  std::regex formats = std::regex("([$][^hlp])");
33  src = std::regex_replace(src, formats, "");
34 
35  std::regex links = std::regex("[$][hlp](\\[.*?\\])");
36  src = std::regex_replace(src, links, "");
37  src = std::regex_replace(src, std::regex("([$][hlp])"), "");
38 
39  if(forTM)
40  {
41  boost::replace_all(src, "\t", "$$");
42  }
43  else
44  {
45  boost::replace_all(src, "\t", "$");
46  }
47 
48  return src;
49  }
50 
57  static std::string StripLinks(std::string src, bool forTM = true)
58  {
59  src = std::regex_replace(src, std::regex("([$][$])"), "\t");
60 
61  std::regex links = std::regex("[$][hlp](\\[.*?\\])");
62  src = std::regex_replace(src, links, "");
63  src = std::regex_replace(src, std::regex("([$][hlp])"), "");
64 
65  if(forTM)
66  {
67  boost::replace_all(src, "\t", "$$");
68  }
69  else
70  {
71  boost::replace_all(src, "\t", "$");
72  }
73 
74  return src;
75  }
76 };
77 
78 #endif // FORMATTING_H_
static std::string StripColors(std::string src, bool forTM=true)
Strips all TrackMania colors from a string.
Definition: Formatting.h:23
Formats TM-input to strip colors/formatting.
Definition: Formatting.h:14
static std::string StripLinks(std::string src, bool forTM=true)
Strips all TrackMania links from a string.
Definition: Formatting.h:57