Beispiel #1
0
void Date::set(const WeakString &wStr)
{
	WeakString val = wStr.trim();

	int year, month, date;

	//시분초까지 있을 때
	if (val.find(" ") != std::string::npos)
		val = val.between(std::string(), " ");

	//년월일 설정
	vector<WeakString> &ymdVec = val.split("-");
	year = stoi(ymdVec[0].str());
	month = stoi(ymdVec[1].str());
	date = stoi(ymdVec[2].str());

	set(year, month, date);
}
Beispiel #2
0
		void construct_key(WeakString &wstr)
		{
			size_t startX = wstr.find("<") + 1;
			size_t endX =
				calc_min_index
				(
					{
						wstr.find(' ', startX),
						wstr.find("\r\n", startX),
						wstr.find('\n', startX),
						wstr.find('\t', startX),
						wstr.find('>', startX),
						wstr.find('/', startX)
					}
				);

			//Determinate the KEY
			tag = move( wstr.substring(startX, endX).str() );
		};
Beispiel #3
0
void IClient::handleString(ByteArray &piece, string &str, shared_ptr<Invoke> &baInvoke, size_t size)
{
	static size_t CLOSED_PARENTHESIS = string("</invoke>").size();

	if (piece.getPosition() >= size)
		return;

	// LIST OF INVOKE MESSAGES
	list<shared_ptr<Invoke>> invokeList;

	// READ STRING
	string &pieceString = piece.read<string>();
	str.append(pieceString);

	WeakString wstr = str;
	vector<WeakString> &wstrArray = wstr.betweens("<invoke ", "</invoke>");

	for (size_t i = 0; i < wstrArray.size(); i++)
	{
		string &message = "<invoke " + wstrArray[i].str() + "</invoke>";

		shared_ptr<Invoke> invoke( new Invoke() );
		invoke->construct(make_shared<XML>(message));

		invokeList.push_back(invoke);
	}

	/*list<shared_ptr<Invoke>> invokeList;
	pair<size_t, size_t> posPair = {-1, -1};
	pair<size_t, size_t> sizePair = {0, 0};
	pair<size_t, size_t> indexPair = {0, 0};

	size_t endIndex = -1;

	while (true)
	{
		// FIND WORDS
		pair<size_t, size_t> myPair = 
		{
			str.find("<invoke ", indexPair.first),
			str.find("</invoke>", indexPair.second)
		};

		// COUNTS
		if (myPair.first != -1)
		{
			sizePair.first++;
			indexPair.first = myPair.first + string("<invoke ").size();
		}
		if (myPair.second != -1)
		{
			sizePair.second++;
			indexPair.second = myPair.second + string("</invoke>").size();
		}
		
		// IF AN INVOKE MESSAGE HAS FOUND
		if (sizePair.first == sizePair.second && sizePair.first != 0)
		{
			if (posPair.first == -1 && posPair.second == -1)
				posPair = myPair;
			else
				posPair.second = myPair.second;

			endIndex = posPair.second + string("</invoke>").size();

			WeakString wstr(str.data() + posPair.first, str.data() + endIndex);
			shared_ptr<XML> xml(new XML(wstr));
			shared_ptr<Invoke> invoke(new Invoke());

			invoke->construct(xml);

			cout << invoke->toXML()->toString() << endl;

			invokeList.push_back(invoke);

			posPair = { -1, -1 };
		}
		else if (myPair.first != -1 && posPair.first == -1)
			posPair.first = myPair.first;
	}*/

	//BASIC DATA
	/*list<shared_ptr<Invoke>> invokeList;
	unique_ptr<pair<size_t, size_t>> indexPair(nullptr);
	pair<size_t, size_t> sizePair = {0, 0};
	size_t startIndex = 0;
	size_t endIndex = 0;

	while (true)
	{
		//FIND WORDS
		pair<size_t, size_t> iPair = 
		{
			str.find("<invoke ", startIndex),
			str.find("</invoke>", endIndex)
		};

		//COUNTS
		if (iPair.first != -1) sizePair.first++;
		if (iPair.second != -1) sizePair.second++;

		//IF IT MEANS THE START,
		if (indexPair.get() != nullptr && sizePair.first == 0)
		{
			//SPECIFY THE STARTING INDEX
			indexPair.reset(new pair<size_t, size_t>(iPair.first, string::npos)); 
		}

		//FAILED TO FIND NOTHING
		if(iPair.first == string::npos || iPair.second == string::npos)
			break;

		//AN INVOKE HAS FOUND
		if(indexPair.get() != nullptr && sizePair.first == sizePair.second)
		{
			//INDEX
			size_t start = indexPair->first;
			size_t end = indexPair->second + string("</invoke>").size();

			//CONSTRUCT INVOKE
			shared_ptr<XML> xml(new XML(str.substr(start, end - start)));
			shared_ptr<Invoke> invoke(new Invoke());
			invoke->construct(xml);

			invokeList.push_back(invoke);

			//CLEAR CURRENT INEX PAIR
			endIndex = end;
			indexPair.reset(nullptr);
		}

		//ADJUST INDEX
		startIndex = (iPair.second == string::npos) ? 
			iPair.first + 1 : iPair.second + 1;
	}

	//ERASE USED CHARACTERS
	if (endIndex != string::npos)
		str = str.substr(endIndex);*/

	if (invokeList.empty() == true)
		return;

	/*str = str.substr(endIndex);
	cout << "#" << invokeList.size() << endl;*/

	// CUT USED STRING
	str = move(str.substr(str.rfind("</invoke>") + CLOSED_PARENTHESIS));

	//CALL REPLY_DATA
	auto last_it = --invokeList.end();
	for (auto it = invokeList.begin(); it != last_it; it++)
		_replyData(*it);
	
	//TEST WHETHER THE LAST CONTAINS BINARY DATA
	shared_ptr<Invoke> &lastInvoke = *last_it;
	for (size_t i = 0; i < lastInvoke->size(); i++)
	{
		//IF HAS, TO HANDLE_BINARY
		if (lastInvoke->at(i)->getType() == "ByteArray")
		{
			baInvoke = lastInvoke;

			piece.setPosition
			(
				piece.getPosition() - 
				(pieceString.size() - (pieceString.rfind("</invoke>") + CLOSED_PARENTHESIS))
			);

			//HANDLING LEFT BINARY PIECE
			handleBinary(piece, str, baInvoke, size);
			return;
		}
	}

	//ELSE, DOES NOT HAVE, CALL REPLY_DATA
	_replyData(lastInvoke);
}
Beispiel #4
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();
		};
Beispiel #5
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];
		};
template<> void InvokeParameter::construct_by_varadic_template(const WeakString &str)
{
	this->type = "string";
	this->str = str.str();
}