Ejemplo n.º 1
0
		void construct_children(WeakString &wstr)
		{
			if (wstr.find('<') == std::string::npos)
				return;

			size_t startX = wstr.find('<');
			size_t endX = wstr.rfind('>') + 1;
			wstr = wstr.substring(startX, endX);

			/*map<std::string, queue<XML *>> xmlQueueMap;
			queue<XML*> *xmlQueue;
			XML *xml;*/

			int blockStartCount = 0;
			int blockEndCount = 0;
			size_t start = 0;
			size_t end;
			size_t i;

			//FIND BLOCKS, CREATES XML AND PUT IN TEMPORARY CONTAINER
			for (i = 0; i < wstr.size(); i++) 
			{
				if (wstr[i] == '<' && wstr.substr(i, 2) != "</")
					blockStartCount++;
				else if (wstr.substr(i, 2) == "/>" || wstr.substr(i, 2) == "</")
					blockEndCount++;

				if (blockStartCount >= 1 && blockStartCount == blockEndCount) 
				{
					//NO PROBLEM TO AVOID COMMENT
					end = wstr.find('>', i);

					/*xml = new XML(this, wstr.substring(start, end + 1));
					xmlQueueMap[xml->tag].push(xml);*/

					std::shared_ptr<XML> xml(new XML(this, wstr.substring(start, end + 1)));
					push_back(xml);

					i = end; //WHY NOT END+1? 
					start = end + 1;
					blockStartCount = 0;
					blockEndCount = 0;
				}
			}

			//RESERVE
			/*for (auto it = xmlQueueMap.begin(); it != xmlQueueMap.end(); it++)
			{
				std::string tag = move(it->first); //GET KEY
				shared_ptr<XMLList> xmlList(new XMLList());

				xmlQueue = &(it->second);
				xmlList->reserve(xmlQueue->size()); //RESERVE

				//MOVE QUEUE TO XML_LIST
				while (xmlQueue->empty() == false)
				{
					xml = xmlQueue->front();
					xmlList->push_back(shared_ptr<XML>(xml));

					xmlQueue->pop();
				}
				//INSERT IN MAP BY KEY
				insert({ tag, xmlList });
			}*/

			if (size() > 0)
				value.clear();
		};