Example #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();
		};
Example #2
0
		void construct_properties(WeakString &wstr)
		{
			// INLINE CLASS
			class QuotePair
			{
			public:
				enum TYPE : int
				{
					SINGLE = 1,
					DOUBLE = 2
				};

				TYPE type;
				size_t start_index;
				size_t end_index;

				QuotePair(TYPE type, size_t start_index, size_t end_index)
				{
					this->type = type;
					this->start_index = start_index;
					this->end_index = end_index;
				};
			};

			size_t i_begin = wstr.find('<' + tag) + tag.size() + 1;
			size_t i_endSlash = wstr.rfind('/');
			size_t i_endBlock = wstr.find('>', i_begin);

			size_t i_end = calc_min_index({ i_endSlash, i_endBlock });
			if (i_end == std::string::npos || i_begin >= i_end)
				return;

			//<comp label='ABCD' /> : " label='ABCD' "
			WeakString &line = wstr.substring(i_begin, i_end); 

			if (line.find('=') == std::string::npos)
				return;

			std::string label, value;
			std::vector<QuotePair*> helpers;
			bool inQuote = false;
			QuotePair::TYPE type;
			size_t startPoint, equalPoint;
			size_t i;

			for (i = 0; i < line.size(); i++) 
			{
				//Start of quote
				if (inQuote == false && (line[i] == '\'' || line[i] == '"'))
				{
					inQuote = true;
					startPoint = i;

					if (line[i] == '\'')
						type = QuotePair::SINGLE;
					else if (line[i] == '"')
						type = QuotePair::DOUBLE;
				}
				else if
					(
						inQuote == true &&
						(
							(type == QuotePair::SINGLE && line[i] == '\'') ||
							(type == QuotePair::DOUBLE && line[i] == '"')
						)
					)
				{
					helpers.push_back(new QuotePair(type, startPoint, i));
					inQuote = false;
				}
			}
			for (i = 0; i < helpers.size(); i++)
			{
				if (i == 0)
				{
					equalPoint = (long long)line.find('=');
					label = move( line.substring(0, equalPoint).trim().str() );
				}
				else
				{
					equalPoint = line.find('=', helpers[i - 1]->end_index + 1);
					label = line.substring(helpers[i - 1]->end_index + 1, equalPoint).trim().str();
				}
		
				value = 
					move
					(
						decodeProperty
						(
							line.substring
							(
								helpers[i]->start_index + 1,
								helpers[i]->end_index
							)
						)
					);
		
				//INSERT INTO PROPERTY_MAP
				properties.set(label, move(value));
			}
			for (i = 0; i < helpers.size(); i++)
				delete helpers[i];
		};