Advertisement
shout1232131

Untitled

Jul 2nd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1.  
  2. void FileManager::LoadContent(std::string fileName, std::vector<std::vector<std::string>> &attributes, std::vector<std::vector<std::string>> &content, std::string id)
  3. {
  4.     attributes.clear();
  5.     content.clear();
  6.  
  7.     std::ifstream openFile(fileName.c_str());
  8.  
  9.     idFound = false;
  10.     if (openFile.is_open())
  11.     {
  12.         while (!openFile.eof())
  13.         {
  14.             std::string line;
  15.             std::getline(openFile, line);
  16.  
  17.             //line.erase(std::remove(line.begin(), line.end(), ' '), line.end());
  18.  
  19.             if(line.find("Start=[" + id + "]") != std::string::npos) // npos zwraca true jeśli nie znajdzie żadnego tekstu w pliku
  20.             {
  21.                 idFound = true;
  22.                 continue;
  23.             }
  24.             else if (line.find("End=") != std::string::npos && line.find(id) != std::string::npos)
  25.             {
  26.                 idFound = false;
  27.                 break;
  28.             }
  29.  
  30.             if (idFound)
  31.             {
  32.                 if (line.find("Load=") != std::string::npos)
  33.                 {
  34.                     state = ATTRIBUTES;
  35.                     line.erase(0, line.find('=') + 1);
  36.                     tempAttributes.clear();
  37.                 }
  38.                 else
  39.                 {
  40.                     state = CONTENTS;
  41.                     tempContents.clear();
  42.                 }
  43.                 line.erase(std::remove(line.begin(), line.end(), '['), line.end());
  44.                 std::stringstream str(line);
  45.                 while (str)
  46.                 {
  47.                     std::getline(str, line, ']');
  48.                     if (line != "")
  49.                     {
  50.                         if (state == ATTRIBUTES)
  51.                         {
  52.                             tempAttributes.push_back(line);
  53.                         }
  54.                         else
  55.                         {
  56.                             tempContents.push_back(line);
  57.                         }
  58.                         std::cout << line << std::endl;
  59.                     }
  60.                 }
  61.                 if (state == CONTENTS && tempContents.size()>0)
  62.                 {
  63.                     attributes.push_back(tempAttributes);
  64.                     content.push_back(tempContents);
  65.                 }
  66.             }
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement