Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include "stdafx.h"
  2. class formation {
  3. public:
  4. void formate(string &text)
  5. {
  6. system("cls");
  7. int fig = 0, brack = 0, j, k = 0;
  8. for (int i = 1; i < text.size(); i++)
  9. {
  10. if (text[i - 1] == '{'&&text[i] != '\n')
  11. text.insert(i, "\n");
  12.  
  13. if (text[i - 1] == '\n')
  14. {
  15. for (j = 0; (text[i + j] == '\n' || text[i + j] == '\t' || text[i + j] == ' '); j++) {}
  16. text.erase(i, j);
  17. if (text[i] == '}')
  18. {
  19. k++;
  20. fig--;
  21. }
  22. for (j = 0; j < fig; j++)
  23. text.insert(i, " \t");
  24. }
  25. //cout << text[i];
  26. switch (text[i])
  27. {
  28. case ';':
  29. if (text[i - 1] == '\n' || text[i - 1] == '\t' || text[i - 1] == ' ')
  30. {
  31. for (j = 2; (text[i - j] == '\n' || text[i - j] == '\t' || text[i - j] == ' '); j++) {}
  32. text.erase(i - j + 1, j - 1);
  33. i -= j - 1;
  34. }
  35. if (text[i + 1] != '\n'&&brack == 0)text.insert(i + 1, "\n"); break;
  36. case '{':
  37. fig++; break;
  38. case '}':
  39. if (k != 0)
  40. k--;
  41. else
  42. fig--;
  43. break;
  44. case '(':
  45. brack++; break;
  46. case ')':
  47. brack--; break;
  48. case '\"':
  49. {
  50. do { ++i; } while (text[i] != '\"' || text[i - 1] == '\\');
  51.  
  52. }break;
  53. case '\'':
  54. {
  55. do { ++i; } while (text[i] != '\'' || text[i - 1] == '\\');
  56. }break;
  57. }
  58. }
  59. system("cls");
  60. //cout << text;
  61. }
  62. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement