Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void trim(string *s) {
- for (int i = 0; i < s->size(); i++) {
- if ((*s)[i] == ' ') {
- s->erase(i, 1);
- }
- }
- }
- string cut(string* s, int n, int l) {
- string t = s->substr(n, l);
- s->erase(n, l);
- return t;
- }
- bool scontains(string &s, char c) {
- for (int i = 0; i < s.length(); i++)
- if (s[i] == c) return true;
- return false;
- }
- string F::toString() {
- ostringstream oss;
- oss << name;
- if (FA.size() > 0) {
- oss << "(";
- for (int i = 0; i < FA.size() - 1; i++) {
- oss << FA[i].toString();
- oss << ", ";
- }
- oss << FA[FA.size() - 1].toString();
- oss << ")";
- }
- return oss.str();
- }
- F F::stringToF(string s) {
- if (!scontains(s, '(')) return F(s);
- int i = 0;
- while (s[i++] != '(');
- string name = s.substr(0, i - 1);
- int c = 1;
- int j = i;
- while (c != 0) (s[++j] == '(') ? c++ : (s[j] == ')') ? c-- : 0;
- string content = s.substr(i, j - i);
- vector<string> sv;
- sv.reserve(3);
- c = 0;
- int o = 0;
- for (int i = 0; i < content.size(); i++) {
- if (content[i] == '(') c++;
- else if (content[i] == ')') c--;
- if (c == 0 && content[i] == ',') {
- o++;
- sv.push_back(cut(&content, 0, i));
- content.erase(0, 1);
- i = 0;
- }
- }
- sv.push_back(content);
- F f(name);
- f.FA.reserve(sv.size());
- for (int i = 0; i < sv.size(); i++)
- f.FA.push_back(f.stringToF(sv[i]));
- return f;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement