Guest User

Untitled

a guest
Jun 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. #ifndef SYNTAX_H
  2. #define SYNTAX_H
  3.  
  4. #include "headquarter.h"
  5. #include "file.h"
  6.  
  7.  
  8. namespace syntax{
  9. bool CheckBaseSyntax(const std::string Code){
  10. bool state = false;
  11. for(int_u line=0;line < Code.length();line++){
  12. if(Code[line] == '<'){
  13. for(int_u Char=line+1;Char < Code.length();Char++){
  14. if(Code[Char] == '>'){
  15. state = true;
  16. break;
  17. }
  18. else if(Code[Char] == '<'){
  19. state = false;
  20. break;
  21. }
  22. }
  23. if(!state)
  24. return false;
  25. state = false;
  26. }
  27. }
  28. return true;
  29. }
  30. std::string EraseString(const std::string input,const int_u range_1,const int_u range_2){
  31. std::string result;
  32. for(int_u i=0;i<input.length();i++){
  33. if(i < range_1 || i > range_2){
  34. result+=input[i];
  35. }
  36. }
  37. return result;
  38. }
  39. std::string RemoveAdditions(std::string input){
  40. std::string result;
  41. for(int_u i=0;i< input.length();i++){
  42. if((input[i] == ' ' && input[i+1] == ' ') || input[i] == '\n' )
  43. continue;
  44. else
  45. result += input[i];
  46. }
  47. return result;
  48. }
  49. static std::string WordSpliter(std::string input){
  50. int_u first=0;
  51. int_u end=0;
  52. std::string Result;
  53. for(int_u count=0;count < input.length();count++){
  54. if(input[count] == '<')
  55. first = count;
  56. else if(input[count] == '>'){
  57. end = count;
  58. if(first < end)
  59. input = EraseString(input,first,end);
  60. first=end=0;
  61. count=0;
  62. }
  63. }
  64. return input;
  65. }
  66. static bool RunCode(const char* const FileName){
  67. std::string FileData = file::ReadFileData(FileName);
  68. bool Syntax = CheckBaseSyntax(FileData);
  69. if(!Syntax){
  70. std::cout << " -----[ Unfortunately,your Program is having trouble. ]-----\n";
  71. std::cout << " [Type of Error] ~> Wrong HTML Syntax\n";
  72. return false;
  73. }
  74. std::string result = WordSpliter(FileData);
  75. std::cout << "The Operation Was Completed Successfully .\n";
  76. std::cout << "Input ~>\n" << FileData << std::endl;
  77. std::cout << "-----------------------------------------------------\n";
  78. std::cout << "Output ~>\n" << RemoveAdditions(result) << std::endl;
  79. return true;
  80. }
  81. }
  82.  
  83. #endif // SYNTAX_H
Add Comment
Please, Sign In to add comment