Ejemplo n.º 1
0
bool xRegex::Match(const xString& input, xMatch& match)
{
	bool result = false;
	if (pImpl->mCompiledPattern)
	{	
		int offsets[OFFSET_COUNT];
			
		int rc = pcre_exec(pImpl->mCompiledPattern, 0, input.c_str(), 0, input.Length(), 0, offsets, OFFSET_COUNT);          
		if (rc > 0)
		{
			if (!result)
				match.Groups.mGroups.Clear();
			result = true;
			match.mSuccess = true;
			for (int i = 0; i < rc; i++)
			{
				xGroup* group;
				if (i == 0)
					group = &match;
				else
					group = new xGroup();
						
				group->mIndex = offsets[2*i];
				group->mLength = offsets[2*i+1] - offsets[2*i];
				group->mValue.Set(input.c_str() + offsets[2*i], offsets[2*i+1] - offsets[2*i]);

				if (i > 0)
					match.Groups.mGroups.AddBack(group);
			}
		}
	}
	
	return result;
}
Ejemplo n.º 2
0
//##############################################################################
//# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
//##############################################################################
xString xTime::format(xString format)
{
	int formatBaseSize = 16;
	xchar* buffer;
	size_t bufferSize;
	for(int i = 1;;i++)
	{
		bufferSize = format.size() + (formatBaseSize * i);
		buffer = (xchar*) malloc(bufferSize * sizeof(xchar));
		buffer[0] = _T('\1');
		
		#ifndef XTK_UNICODE
			size_t ret = strftime(buffer,bufferSize,format.c_str(),&m_time);
		#else
			size_t ret = wcsftime(buffer,bufferSize,format.c_str(),&m_time);
		#endif
		
		if(((ret < bufferSize) && ret != 0) || (ret == 0 && buffer[0] == _T('\0')))
		{
			xString s(buffer,ret);
			free((void*) buffer);
			return s;
		}
	}
}
Ejemplo n.º 3
0
xString xRegex::Replace(const xString& input, const xString replacement)
{
	xString result;
	if (pImpl->mCompiledPattern)
	{	
		int offsets[OFFSET_COUNT];

		unsigned int offset = 0;
		unsigned int len = input.Length();
	
		while (offset < len)
		{
			int rc = pcre_exec(pImpl->mCompiledPattern, 0, input.c_str(), len, offset, 0, offsets, OFFSET_COUNT);          
			if (rc > 0)
			{
				const char* s1 = input.c_str() + offset;
				result += xString(input.c_str() + offset, offsets[0] - offset) + replacement;
				offset = offsets[1];
			}
			else
			{
				result += xString(input.c_str() + offset, len - offset);
				break;
			}
			
		}
	}
	return result;
}
Ejemplo n.º 4
0
//##############################################################################
//# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
//##############################################################################
void xSystem::xSTDWriter::write(xString s) throw(xIOException)
{
	#ifndef XTK_UNICODE
		if(printf(_T("%s"),s.c_str()) < 0)
			throw xIOException(_T("Error writing to stdout"),getSysErrorCode());
	#else
		if(wprintf(_T("%ls"),s.c_str()) < 0)
			throw xIOException(_T("Error writing to stdout"),getSysErrorCode());
	#endif
}
Ejemplo n.º 5
0
bool xRegex::IsMatch(const xString& input)
{
	if (pImpl->mCompiledPattern)
	{
		int offsets[3];
		if (pcre_exec(pImpl->mCompiledPattern, 0, input.c_str(), input.Length(), 0, 0, offsets, 3) > 0)
			return true;
	}

	return false;
}
Ejemplo n.º 6
0
//##############################################################################
//# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
//##############################################################################
//##############################################################################
//# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
//##############################################################################
bool xSystem::getEnv(xString name,OUT xString& value)
{
#if defined(XTK_UNICODE) && defined(XTK_OS_WINDOWS)
    xchar* arg = ::_wgetenv(name.c_str());
#else
    char* arg = ::getenv(name.mb_str());
#endif

    if(arg == NULL)
        return false;

    value = xString::getFromOS(arg);
    return true;
}
Ejemplo n.º 7
0
//##############################################################################
//# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
//##############################################################################
void xSystem::xSTDWriter::write(xString s) throw(xIOException)
{
    synchronizeStart();

#ifndef XTK_UNICODE
    if(puts(s.c_str()) == EOF)
        throw xIOException(_T("Error writing to stdout"),getSysErrorCode());
#else
    if(fputws(s.c_str(),stdout) == (int)WEOF)
        throw xIOException(_T("Error writing to stdout"),getSysErrorCode());
#endif

    synchronizeEnd();
}
Ejemplo n.º 8
0
void xConsole::Print(const xString& text, xConsoleColor::Enum color)
{
	switch (color)
	{
    case xConsoleColor::Black:
        printf("\033[22;30m");
	    break;
    case xConsoleColor::Red:
        printf("\033[22;31m");
	    break;
    case xConsoleColor::Green:
        printf("\033[22;32m");
	    break;
    case xConsoleColor::Yellow:
        printf("\033[22;33m");
	    break;
    case xConsoleColor::Blue:
        printf("\033[22;34m");
	    break;
    case xConsoleColor::Purple:
        printf("\033[22;35m");
	    break;
    case xConsoleColor::Cyan:
        printf("\033[22;36m");
	    break;
    case xConsoleColor::White:
        printf("\033[22;37m");
	    break;
	}
    printf("%s", text.c_str());
    printf("\033[22;37m");
}
Ejemplo n.º 9
0
void Application::AddFailure(const xString& condition, const xString& test_name, const xString& filename, int line)
{
	mConsole->Print("\nCondition: ");
	mConsole->Print(condition + "\n",  xConsoleColor::Red);
	mConsole->Print(xString::Format("File:      %s(%d)\n", filename.c_str(), line));
	mLastTestSuccessful = false;
}
Ejemplo n.º 10
0
bool xRegex::Matches(const xString& input, xMatchCollection& matches)
{
	bool result = false;
	if (pImpl->mCompiledPattern)
	{	
		int offsets[OFFSET_COUNT];

		unsigned int offset = 0;
		unsigned int len = input.Length();
			
		while (offset < len)
		{
			int rc = pcre_exec(pImpl->mCompiledPattern, 0, input.c_str(), len, offset, 0, offsets, OFFSET_COUNT);          
			if (rc > 0)
			{
				if (!result)
					matches.mMatches.Clear();
				result = true;
				xMatch* match = new xMatch();
				match->mSuccess = true;
				for (int i = 0; i < rc; i++)
				{
					xGroup* group;
					if (i == 0)
						group = match;
					else
						group = new xGroup();
						
					group->mIndex = offsets[2*i];
					group->mLength = offsets[2*i+1] - offsets[2*i];
					group->mValue.Set(input.c_str() + offsets[2*i], offsets[2*i+1] - offsets[2*i]);

					if (i > 0)
						match->Groups.mGroups.AddBack(group);
				}
				matches.mMatches.AddBack(match);
				offset = offsets[1];
			}
			else
				break;
			
		}
	}
	
	return result;
}
Ejemplo n.º 11
0
///////////////////////////////////////////////
// CXml
//
///////////////////////////////////////////////
CXml::CXml( xString path )
{
	rootNode = NULL;
	_ClearDocument();

  pugi::xml_document doc;
  pugi::xml_parse_result result = doc.load_file(path.c_str());
  if(result) {
    rootNode = new CXmlNode(NULL, doc.first_child());
  }
}
Ejemplo n.º 12
0
xRegex::xRegex(const xString& pattern, xRegexOptions::Flags options)
{
	pImpl = new Impl;

	const char* error;
	int   erroffset;
	int	opts = 0;
	if (options && xRegexOptions::Multiline)
		opts |= PCRE_MULTILINE;
	if (options & xRegexOptions::IgnoreCase)
		opts |= PCRE_CASELESS;
	
	pImpl->mCompiledPattern = pcre_compile(pattern.c_str(), opts,  &error, &erroffset, 0);
}
Ejemplo n.º 13
0
void xBinaryWriter::WriteString(const xString& string)
{
	xUInt16 length = (xUInt16)string.Length();
	WriteUInt16(length);
	mStream->Write((void*)string.c_str(), length);
}