forked from whhxp/getPF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstr2complex.cpp
More file actions
38 lines (33 loc) · 1.19 KB
/
str2complex.cpp
File metadata and controls
38 lines (33 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "str2complex.h"
Str2complex::Str2complex(std::__cxx11::string str)
{
}
std::complex<float> Str2complex::str2complex(std::__cxx11::string str)
{
std::smatch m;
std::regex e("(-?\\d+.?\\d*)\\s([+|-])\\s(\\d+.?\\d*)i"); // matches words beginning by "sub"
// std::cout << "Target sequence: " << str << std::endl;
std::complex<float> result;
std::string real, img, opt;
// std::cout << "Regular expression: (-?\\d+.?\\d*)\\s*(+|-?\\d+.?\\d*)i" << std::endl;
// std::cout << "The following matches and submatches were found:" << std::endl;
while (std::regex_search(str, m, e))
{
// for (auto x = m.begin(); x != m.end(); x++)
// {
// std::cout << x->str() << " ";
// }
// std::cout << "--> ([^ ]*) match " << m.format("$2") << std::endl;
//
real = m.format("$1");
opt = m.format("$2");
img = m.format("$3");
// std::cout<<"real="<<real<<" opt="<<opt<<" img="<<img<<std::endl<<"--------"<<std::endl;
str = m.suffix().str();
}
result.real(stof(real));
if (opt[0] == '-')
img.insert(0,"-");
result.imag(stof(img));
return result;
}