PandA-2024.02
string_manipulation.hpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
40 #ifndef STRING_MANIPULATION_HPP
41 #define STRING_MANIPULATION_HPP
42 
43 #include <boost/lexical_cast.hpp>
44 #include <string>
45 #include <type_traits>
46 #include <vector>
47 
51 #ifndef STR
52 #define STR(s) boost::lexical_cast<std::string>(s)
53 #endif
54 
61 const std::vector<std::string> SplitString(const std::string& input, const std::string& separators);
62 
68 void add_escape(std::string& ioString, const std::string& to_be_escaped);
69 
74 void remove_escaped(std::string& ioString);
75 
76 std::string TrimSpaces(const std::string& value);
77 
78 std::string cxa_demangle(const std::string& input);
79 
80 std::string cxa_rename_mangled(const std::string& signature, const std::string& new_fname);
81 
82 std::string cxa_prefix_mangled(const std::string& signature, const std::string& prefix);
83 
84 std::string capitalize(const std::string& str);
85 
86 std::string& capitalize(std::string& str);
87 
88 inline bool starts_with(const std::string& str, const std::string& pattern)
89 {
90  return str.find(pattern) == 0;
91 }
92 
93 inline bool ends_with(const std::string& str, const std::string& pattern)
94 {
95  const auto pos = str.rfind(pattern);
96  return pos != std::string::npos && (pos + pattern.size()) == str.size();
97 }
98 
106 inline std::string NumberToString(const T number, const size_t precision, const size_t size)
107 {
108  std::stringstream return_stream;
109  return_stream.width(static_cast<std::streamsize>(size));
110  return_stream.fill(' ');
111  return_stream.setf(std::ios::fixed, std::ios::floatfield);
112  return_stream.precision(static_cast<std::streamsize>(precision));
113  return_stream << static_cast<long double>(number);
114  return return_stream.str();
115 }
116 
123 inline std::string NumberToString(const T number, const size_t precision)
124 {
125  std::stringstream return_stream;
126  return_stream.setf(std::ios::fixed, std::ios::floatfield);
127  return_stream.precision(static_cast<std::streamsize>(precision));
128  return_stream << static_cast<long double>(number);
129  return return_stream.str();
130 }
131 
138 inline std::string NumberToBinaryString(const T number, const size_t precision = 0)
139 {
140  std::string ret;
141  auto temp_number = number;
142  while(temp_number > 0)
143  {
144  auto bit = temp_number % 2;
145  if(bit == 0)
146  {
147  ret = "0" + ret;
148  }
149  else
150  {
151  ret = "1" + ret;
152  }
153  temp_number = temp_number / 2;
154  }
155  if(precision > 0)
156  {
157  while(ret.size() < precision)
158  {
159  ret = "0" + ret;
160  }
161  }
162  return ret;
163 }
164 
168 std::string convert_fp_to_string(std::string num, unsigned long long precision);
169 
173 unsigned long long convert_fp_to_bits(std::string num, unsigned long long precision);
174 
178 #define GET_CLASS(obj) cxa_demangle(typeid(obj).name())
179 
187 std::string ConvertInBinary(const std::string& C_value, unsigned long long precision, const bool real_type,
188  bool unsigned_type);
189 
190 std::string FixedPointReinterpret(const std::string& FP_vector, const std::string& fp_typename);
191 
192 unsigned long long ac_type_bitwidth(const std::string& intType, bool& is_signed, bool& is_fixed);
193 #endif
std::string capitalize(const std::string &str)
unsigned long long convert_fp_to_bits(std::string num, unsigned long long precision)
convert a real number stored in a string into bits with a given precision
struct definition of the real_type tree node.
Definition: tree_node.hpp:4039
int input[SIZE]
Definition: hash.h:1
std::string cxa_rename_mangled(const std::string &signature, const std::string &new_fname)
std::string NumberToString(const T number, const size_t precision, const size_t size)
Function with print number in desired format.
std::string NumberToBinaryString(const T number, const size_t precision=0)
Function which print number in binary format.
bool starts_with(const std::string &str, const std::string &pattern)
std::string cxa_prefix_mangled(const std::string &signature, const std::string &prefix)
void remove_escaped(std::string &ioString)
Function converting all the escaped characters in the associated character.
std::string convert_fp_to_string(std::string num, unsigned long long precision)
convert a real number stored in a string into a string of bits with a given precision ...
bool ends_with(const std::string &str, const std::string &pattern)
std::string TrimSpaces(const std::string &value)
const std::vector< std::string > SplitString(const std::string &input, const std::string &separators)
Function which splits a string into tokens.
void add_escape(std::string &ioString, const std::string &to_be_escaped)
Function which adds escape to selected characters.
unsigned long long ac_type_bitwidth(const std::string &intType, bool &is_signed, bool &is_fixed)
std::string ConvertInBinary(const std::string &C_value, unsigned long long precision, const bool real_type, bool unsigned_type)
Convert a string storing a number in decimal format into a string in binary format.
char str[25]
Definition: fixedptc.c:8
std::string cxa_demangle(const std::string &input)
std::string FixedPointReinterpret(const std::string &FP_vector, const std::string &fp_typename)

Generated on Mon Feb 12 2024 13:02:56 for PandA-2024.02 by doxygen 1.8.13