Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- class formation {
- public:
- void formate(string &text)
- {
- system("cls");
- int fig = 0, brack = 0, j, k = 0;
- for (int i = 1; i < text.size(); i++)
- {
- if (text[i - 1] == '{'&&text[i] != '\n')
- text.insert(i, "\n");
- if (text[i - 1] == '\n')
- {
- for (j = 0; (text[i + j] == '\n' || text[i + j] == '\t' || text[i + j] == ' '); j++) {}
- text.erase(i, j);
- if (text[i] == '}')
- {
- k++;
- fig--;
- }
- for (j = 0; j < fig; j++)
- text.insert(i, " \t");
- }
- //cout << text[i];
- switch (text[i])
- {
- case ';':
- if (text[i - 1] == '\n' || text[i - 1] == '\t' || text[i - 1] == ' ')
- {
- for (j = 2; (text[i - j] == '\n' || text[i - j] == '\t' || text[i - j] == ' '); j++) {}
- text.erase(i - j + 1, j - 1);
- i -= j - 1;
- }
- if (text[i + 1] != '\n'&&brack == 0)text.insert(i + 1, "\n"); break;
- case '{':
- fig++; break;
- case '}':
- if (k != 0)
- k--;
- else
- fig--;
- break;
- case '(':
- brack++; break;
- case ')':
- brack--; break;
- case '\"':
- {
- do { ++i; } while (text[i] != '\"' || text[i - 1] == '\\');
- }break;
- case '\'':
- {
- do { ++i; } while (text[i] != '\'' || text[i - 1] == '\\');
- }break;
- }
- }
- system("cls");
- //cout << text;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement