byteman  1.3 (Build #225)
Bitstream relocation and manipulation tool
Functions
str::parse Namespace Reference

Functions

std::string allStringWords (std::string s)
 Parses a string s, removes all integers and returns the rest. More...
 
std::string allStringWordsWithoutLastStringWord (std::string s)
 Parses a string s, removes all integers and the last string word. Returns the rest. More...
 
bool arrayOfUints (std::string s, int arrsize, uint32_t *arr)
 Removes all string words from a given string s and returns the parsed arrsize number of integers into arr. More...
 
std::string lastStringWord (std::string s)
 Parses a string s, removes all integers and returns the last of all string words. More...
 
template<typename ... Args>
bool multipleInts (std::string s, Args &... args)
 Parses string s for integer values, that are returned into args. More...
 
template<typename ... Rest>
bool multipleInts (std::stringstream &ss)
 
template<typename ... Rest>
bool multipleInts (std::stringstream &ss, int &x, Rest &... args)
 Parses stringstream ss for integer values, that are returned into x, args. More...
 
template<typename ... Args>
bool multipleUints (std::string s, Args &... args)
 Parses string s for uint32_t values, that are returned into args. More...
 
template<typename ... Rest>
bool multipleUints (std::stringstream &ss)
 
template<typename ... Rest>
bool multipleUints (std::stringstream &ss, uint32_t &x, Rest &... args)
 Parses stringstream ss for uint32_t values, that are returned into x, args. More...
 
bool nthInteger (std::string s, int n, int &x)
 Parses a string s, returns the n-th integer. More...
 
std::string nthStringWord (std::string s, int n)
 Parses a string s, returns the n-th string word that is not an integer. More...
 

Function Documentation

◆ allStringWords()

std::string str::parse::allStringWords ( std::string  s)
inline

Parses a string s, removes all integers and returns the rest.

Definition at line 57 of file parse.h.

58  {
59  std::stringstream ss(s);
60  std::string temp, ret = "";
61  int intFound;
62  while (!ss.eof()) {
63  ss >> quoted(temp);
64  if(temp.empty()) break;
65  try{
66  size_t sz;
67  intFound = stoi(temp, &sz, 0);
68  if(temp.size() != sz)
69  throw std::exception();
70  } catch (const std::exception &e) {
71  if(!ret.empty())
72  ret.append(" ");
73  ret.append(temp);
74  e;
75  }
76  temp.clear();
77  }
78  return ret;
79  }

Referenced by byteman::parseMerge(), and byteman::parseRegion().

Here is the caller graph for this function:

◆ allStringWordsWithoutLastStringWord()

std::string str::parse::allStringWordsWithoutLastStringWord ( std::string  s)
inline

Parses a string s, removes all integers and the last string word. Returns the rest.

Definition at line 105 of file parse.h.

106  {
107  std::stringstream ss(s);
108  std::string ret;
109  ret.clear();
110  std::string temp;
111  std::string temp2;
112  int intFound;
113  while (!ss.eof()) {
114  ss >> quoted(temp);
115  if(temp.empty()) break;
116  try{
117  size_t sz;
118  intFound = stoi(temp, &sz, 0);
119  if(temp.size() != sz)
120  throw std::exception();
121  } catch (const std::exception &e) {
122  if(!ret.empty())
123  ret.append(" ");
124  ret.append(temp2);
125  temp2 = temp;
126  e;
127  }
128  temp.clear();
129  }
130  return ret;
131  }

Referenced by byteman::parseOutput().

Here is the caller graph for this function:

◆ arrayOfUints()

bool str::parse::arrayOfUints ( std::string  s,
int  arrsize,
uint32_t *  arr 
)
inline

Removes all string words from a given string s and returns the parsed arrsize number of integers into arr.

Definition at line 160 of file parse.h.

161  {
162  if (arrsize == 0)
163  return true;
164  std::stringstream ss(s);
165  std::string temp;
166  uint32_t intFound;
167  bool intWasFound = false;
168  for (int i = 0 ; i < arrsize ; i++)
169  {
170  intWasFound = false;
171  while ((!ss.eof()) && (!intWasFound)) {
172  ss >> quoted(temp);
173  if(temp.empty()) break;
174  try{
175  size_t sz;
176  intFound = (uint32_t)(stoll(temp, &sz, 0));
177  if(temp.size() != sz)
178  throw std::exception();
179  arr[i] = intFound;
180  intWasFound = true;
181  } catch (const std::exception &e) {
182  e;
183  }
184  temp.clear();
185  }
186  if(ss.eof() && (!intWasFound))
187  return false;
188  }
189  return true; //success
190  }

Referenced by XilinxSeries7::assemblerAsmTo(), XilinxUltraScale::assemblerAsmTo(), and XilinxUltraScalePlus::assemblerAsmTo().

Here is the caller graph for this function:

◆ lastStringWord()

std::string str::parse::lastStringWord ( std::string  s)
inline

Parses a string s, removes all integers and returns the last of all string words.

Definition at line 81 of file parse.h.

82  {
83  std::stringstream ss(s);
84  std::string ret;
85  ret.clear();
86  std::string temp;
87  int intFound;
88  while (!ss.eof()) {
89  ss >> quoted(temp);
90  if(temp.empty()) break;
91  try{
92  size_t sz;
93  intFound = stoi(temp, &sz, 0);
94  if(temp.size() != sz)
95  throw std::exception();
96  } catch (const std::exception &e) {
97  ret = temp;
98  e;
99  }
100  temp.clear();
101  }
102  return ret;
103  }

Referenced by XilinxSeries7::assemblerParseHeader(), XilinxUltraScale::assemblerParseHeader(), XilinxUltraScalePlus::assemblerParseHeader(), byteman::parseInput(), and byteman::parseOutput().

Here is the caller graph for this function:

◆ multipleInts() [1/3]

template<typename ... Args>
bool str::parse::multipleInts ( std::string  s,
Args &...  args 
)
inline

Parses string s for integer values, that are returned into args.

Definition at line 223 of file parse.h.

224  {
225  std::stringstream ss(s);
226  return multipleInts(ss, args...);
227  }
bool multipleInts(std::string s, Args &... args)
Parses string s for integer values, that are returned into args.
Definition: parse.h:223

References multipleInts().

Here is the call graph for this function:

◆ multipleInts() [2/3]

template<typename ... Rest>
bool str::parse::multipleInts ( std::stringstream &  ss)
inline

◆ multipleInts() [3/3]

template<typename ... Rest>
bool str::parse::multipleInts ( std::stringstream &  ss,
int &  x,
Rest &...  args 
)
inline

Parses stringstream ss for integer values, that are returned into x, args.

Definition at line 197 of file parse.h.

198  {
199  int numArgs = sizeof...(args);
200  std::string temp;
201  int intFound;
202  bool intWasFound = false;
203  while ((!ss.eof()) && (!intWasFound)) {
204  ss >> quoted(temp);
205  if(temp.empty()) break;
206  try{
207  size_t sz;
208  intFound = stoi(temp, &sz, 0);
209  if(temp.size() != sz)
210  throw std::exception();
211  x = intFound;
212  intWasFound = true;
213  } catch (const std::exception &e) {
214  e;
215  }
216  temp.clear();
217  }
218  if(ss.eof() && (!intWasFound))
219  return false;
220  return multipleInts(ss, args...);
221  }

References multipleInts().

Here is the call graph for this function:

◆ multipleUints() [1/3]

template<typename ... Args>
bool str::parse::multipleUints ( std::string  s,
Args &...  args 
)
inline

Parses string s for uint32_t values, that are returned into args.

Definition at line 260 of file parse.h.

261  {
262  std::stringstream ss(s);
263  return multipleUints(ss, args...);
264  }
bool multipleUints(std::string s, Args &... args)
Parses string s for uint32_t values, that are returned into args.
Definition: parse.h:260

References multipleUints().

Here is the call graph for this function:

◆ multipleUints() [2/3]

template<typename ... Rest>
bool str::parse::multipleUints ( std::stringstream &  ss)
inline

Definition at line 229 of file parse.h.

230  {
231  return true;
232  }

Referenced by XilinxSeries7::assemblerAsmTo(), XilinxUltraScale::assemblerAsmTo(), XilinxUltraScalePlus::assemblerAsmTo(), multipleUints(), byteman::parseTest(), and setBitstreamWord().

Here is the caller graph for this function:

◆ multipleUints() [3/3]

template<typename ... Rest>
bool str::parse::multipleUints ( std::stringstream &  ss,
uint32_t &  x,
Rest &...  args 
)
inline

Parses stringstream ss for uint32_t values, that are returned into x, args.

Definition at line 234 of file parse.h.

235  {
236  int numArgs = sizeof...(args);
237  std::string temp;
238  unsigned long uintFound;
239  bool intWasFound = false;
240  while ((!ss.eof()) && (!intWasFound)) {
241  ss >> quoted(temp);
242  if(temp.empty()) break;
243  try{
244  size_t sz;
245  uintFound = stoul(temp, &sz, 0);
246  if(temp.size() != sz)
247  throw std::exception();
248  x = (uint32_t)uintFound;
249  intWasFound = true;
250  } catch (const std::exception &e) {
251  e;
252  }
253  temp.clear();
254  }
255  if(ss.eof() && (!intWasFound))
256  return false;
257  return multipleUints(ss, args...);
258  }

References multipleUints().

Here is the call graph for this function:

◆ nthInteger()

bool str::parse::nthInteger ( std::string  s,
int  n,
int &  x 
)
inline

Parses a string s, returns the n-th integer.

Definition at line 133 of file parse.h.

134  {
135  std::stringstream ss(s);
136  std::string temp;
137  int intFound;
138  int i = 0;
139  while (!ss.eof()) {
140  ss >> quoted(temp);
141  if(temp.empty()) break;
142  try{
143  size_t sz;
144  intFound = stoi(temp, &sz, 0);
145  if(temp.size() != sz)
146  throw std::exception();
147  if(i == n) {
148  x = intFound;
149  return true;
150  }
151  i++;
152  } catch (const std::exception &e) {
153  e;
154  }
155  temp.clear();
156  }
157  return false;
158  }

◆ nthStringWord()

std::string str::parse::nthStringWord ( std::string  s,
int  n 
)
inline

Parses a string s, returns the n-th string word that is not an integer.

Definition at line 33 of file parse.h.

34  {
35  std::stringstream ss(s);
36  std::string temp;
37  int intFound, i = 0;
38  while (!ss.eof()) {
39  ss >> quoted(temp);
40  if(temp.empty()) break;
41  try{
42  size_t sz;
43  intFound = stoi(temp, &sz, 0);
44  if(temp.size() != sz)
45  throw std::exception();
46  } catch (const std::exception &e) {
47  if(i == n)
48  return temp;
49  i++;
50  e;
51  }
52  temp.clear();
53  }
54  return std::string("");
55  }

Referenced by byteman::parseAssembly().

Here is the caller graph for this function: