Exemplo n.º 1
0
CUtlString CUtlString::Slice( int32 nStart, int32 nEnd ) const
{
	int length = Length();
	if ( length == 0 )
	{
		return CUtlString();
	}

	if ( nStart < 0 )
		nStart = length - (-nStart % length);
	else if ( nStart >= length )
		nStart = length;

	if ( nEnd == INT32_MAX )
		nEnd = length;
	else if ( nEnd < 0 )
		nEnd = length - (-nEnd % length);
	else if ( nEnd >= length )
		nEnd = length;
	
	if ( nStart >= nEnd )
		return CUtlString();

	const char *pIn = String();

	CUtlString ret;
	ret.SetDirect( pIn + nStart, nEnd - nStart );
	return ret;
}
Exemplo n.º 2
0
CUtlString CUtlString::Slice( int32 nStart, int32 nEnd )
{
	if ( nStart < 0 )
		nStart = Length() - (-nStart % Length());
	else if ( nStart >= Length() )
		nStart = Length();

	if ( nEnd == 0x7FFFFFFF )
		nEnd = Length();
	else if ( nEnd < 0 )
		nEnd = Length() - (-nEnd % Length());
	else if ( nEnd >= Length() )
		nEnd = Length();
	
	if ( nStart >= nEnd )
		return CUtlString( "" );

	const char *pIn = String();

	CUtlString ret;
	ret.m_Storage.SetLength( nEnd - nStart + 1 );
	char *pOut = (char*)ret.m_Storage.Get();

	memcpy( ret.m_Storage.Get(), &pIn[nStart], nEnd - nStart );
	pOut[nEnd - nStart] = 0;

	return ret;
}
Exemplo n.º 3
0
CUtlString CUtlString::Replace( char cFrom, char cTo ) const
{
	if (!m_pString)
	{
		return CUtlString();
	}

	CUtlString ret = *this;
	int len = ret.Length();
	for ( int i=0; i < len; i++ )
	{
		if ( ret.m_pString[i] == cFrom )
			ret.m_pString[i] = cTo;
	}

	return ret;
}
Exemplo n.º 4
0
CUtlString CUtlString::PathJoin( const char *pStr1, const char *pStr2 )
{
	char szPath[MAX_PATH];
	V_ComposeFileName( pStr1, pStr2, szPath, sizeof( szPath ) );
	return CUtlString( szPath );
}
Exemplo n.º 5
0
CUtlString CUtlString::UnqualifiedFilename()
{
	const char *pFilename = V_UnqualifiedFileName( this->String() );
	return CUtlString( pFilename );
}
Exemplo n.º 6
0
CUtlString CUtlString::AbsPath( const char *pStartingDir )
{
	char szNew[MAX_PATH];
	V_MakeAbsolutePath( szNew, sizeof( szNew ), this->String(), pStartingDir );
	return CUtlString( szNew );
}
Exemplo n.º 7
0
CUtlString CUtlString::GetExtension() const
{
	char szTemp[MAX_PATH];
	V_ExtractFileExtension( String(), szTemp, sizeof( szTemp ) );
	return CUtlString( szTemp );
}
Exemplo n.º 8
0
CUtlString CUtlString::GetBaseFilename() const
{
	char szTemp[MAX_PATH];
	V_FileBase( String(), szTemp, sizeof( szTemp ) );
	return CUtlString( szTemp );
}
Exemplo n.º 9
0
CUtlString CUtlString::StripExtension() const
{
	char szTemp[MAX_PATH];
	V_StripExtension( String(), szTemp, sizeof( szTemp ) );
	return CUtlString( szTemp );
}
Exemplo n.º 10
0
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CDmxEditApp::PrintHelp( bool bWiki /* = false */ )
{
	const CDmxEditLua::LuaFunc_s *pLuaFuncs = CDmxEditLua::GetFunctionList();

	if ( bWiki && pLuaFuncs )
	{
		lua_State *pLuaState = lua_open();
		if ( pLuaState )
		{
			luaL_openlibs( pLuaState );

			CUtlString wikiString;

			for ( int i = 0; i < CDmxEditLua::FunctionCount(); ++i )
			{
				if ( i != 0 )
				{
					Msg( "\n" );
				}
				Msg( ";%s( %s );\n", pLuaFuncs[ i ].m_pFuncName, pLuaFuncs[ i ].m_pFuncPrototype );
				Msg( ":%s\n", Wikize( pLuaState, pLuaFuncs[ i ].m_pFuncDesc ) );
			}

			return;
		}
	}

	Msg( "\n" );
	Msg( "NAME\n" );
	Msg( "    dmxedit - Edit dmx files\n" );
	Msg( "\n" );
	Msg( "SYNOPSIS\n" );
	Msg( "    dmxedit [ -h | -help ] [ -game <$game> ] [ -set $var=val ] [ script.lua ]\n" );
	Msg( "\n" );
	Msg( "    -h | -help :           Prints this information\n" );
	Msg( "    -g | -game <$game> :   Sets the VPROJECT environment variable to the specified game.\n" );
	Msg( "    -s | -set <$var=val> : Sets the lua variable var to the specified val before the script is run.\n" );
	Msg( "\n" );
	Msg( "DESCRIPTION\n" );
	Msg( "    Edits dmx files by executing a lua script of dmx editing functions\n" );
	Msg( "\n" );

	if ( !pLuaFuncs )
		return;

	Msg( "FUNCTIONS\n" );

	const char *pWhitespace = " \t";

	for ( int i = 0; i < CDmxEditLua::FunctionCount(); ++i )
	{
		Msg( "    %s( %s );\n", pLuaFuncs[ i ].m_pFuncName, pLuaFuncs[ i ].m_pFuncPrototype );
		Msg( "      * " );
		
		CUtlString tmpStr;

		const char *pWordBegin = pLuaFuncs[ i ].m_pFuncDesc + strspn( pLuaFuncs[ i ].m_pFuncDesc, pWhitespace );
		const char *pWhiteSpaceBegin = pWordBegin;
		const char *pWordEnd = pWordBegin + strcspn( pWordBegin, pWhitespace );

		bool bNewline = false;
		while ( *pWordBegin )
		{
			if ( pWordEnd - pWhiteSpaceBegin + tmpStr.Length() > 70 )
			{
				if ( bNewline )
				{
					Msg( "        " );
				}
				else
				{
					bNewline = true;
				}
				Msg( "%s\n", tmpStr );
				tmpStr.Set( "" );
			}

			if ( tmpStr.Length() )
			{
				tmpStr += CUtlString( pWhiteSpaceBegin, pWordEnd - pWhiteSpaceBegin + 1);
			}
			else
			{
				tmpStr += CUtlString( pWordBegin, pWordEnd - pWordBegin + 1 );
			}

			pWhiteSpaceBegin = pWordEnd;
			pWordBegin = pWhiteSpaceBegin + strspn( pWhiteSpaceBegin, pWhitespace );
			pWordEnd = pWordBegin + strcspn( pWordBegin, pWhitespace );
		}

		if ( tmpStr.Length() )
		{
			if ( bNewline )
			{
				Msg( "        " );
			}
			Msg( "%s\n", tmpStr );
		}
		Msg( "\n" );
	}

	Msg( "CREDITS\n" );
	Msg( "    Lua Copyright © 1994-2006 Lua.org, PUC-Rio.\n ");

	Msg( "\n" );
}