Exemplo n.º 1
0
CString Template::ParseCode(LPCTSTR codePtr, LPCTSTR bolPtr, WWhizTemplate* file)
{
	// Build our master string.
	CharArray buffer;

	// Remove leading whitespace.
	while (*codePtr != 0  &&  *codePtr != '\n'  &&  *codePtr == ' ')
	{
		codePtr++;
	}
		
	TokenHelper helper;
	helper.m_tabSize = 4;
	helper.m_outBolPtr = bolPtr;
	helper.m_file = file;
	helper.m_helper = WNEW TemplateHelper(NULL);
	
	// Get the parameter.
	while (*codePtr != 0)
	{
		if (*codePtr == '@'  &&  *(codePtr + 1) == '@')
		{
			CString out;
			if (ParseTag(codePtr, out, &helper))
			{
				// Move the output string into the buffer.
				for (int i = 0; i < out.GetLength(); i++)
					buffer.Add(out[i]);
			}
		}
		else
		{
			// Copy it straight.
			buffer.Add(*codePtr++);
		}
	}
	buffer.Add(0);

	delete helper.m_helper;
	
	return CString(buffer.GetData());
}
Exemplo n.º 2
0
CString ParseToken(LPCTSTR& codePtr, TokenHelper* helper)
{
	// Build our master string.
	CharArray buffer;

	// Remove leading whitespace.
	while (*codePtr != 0  &&  *codePtr != '\n'  &&  *codePtr == ' ')
	{
		codePtr++;
	}
		
	// Get the parameter.
	bool inQuote = false;
	if (*codePtr == '"')
	{
		inQuote = true;
		codePtr++;
	}

	while (*codePtr != 0)
	{
		if (*codePtr == '\n')
		{
			if (inQuote)
			{
				CString err;
				err.Format("Unexpected end of line while parsing a quoted string.");
				throw TException(TException::UNEXPECTED_EOL, err);
			}
			break;
		}
		else if (*codePtr == '%')
		{
			switch (*(codePtr + 1))
			{
				case '"':
					buffer.Add('"');
					codePtr += 2;
					break;
				case '@':
					buffer.Add('@');
					codePtr += 2;
					break;
				case '%':
					buffer.Add('%');
					codePtr += 2;
					break;
			}
		}
		else if (*codePtr == '"')
		{
			if (inQuote)
			{
				codePtr++;
				break;
			}
			else
			{
				buffer.Add(*codePtr++);
			}
		}
		else if (*codePtr == '\\')
		{
			if (inQuote)
			{
				codePtr++;
			}

			buffer.Add(*codePtr++);
		}
		else if (*codePtr == ' ')
		{
			if (inQuote)
			{
				buffer.Add(*codePtr++);
			}
			else
			{
				codePtr++;
				break;
			}
		}
		else if (helper  &&  *codePtr == '@'  &&  *(codePtr + 1) == '@')
		{
			CString out;
			if (ParseTag(codePtr, out, helper))
			{
				// Move the output string into the buffer.
				for (int i = 0; i < out.GetLength(); i++)
					buffer.Add(out[i]);
			}
		}
		else
		{
			// Copy it straight.
			buffer.Add(*codePtr++);
		}
	}
	buffer.Add(0);

	return CString(buffer.GetData());
}