本文整理汇总了C++中CUtlString类的典型用法代码示例。如果您正苦于以下问题:C++ CUtlString类的具体用法?C++ CUtlString怎么用?C++ CUtlString使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CUtlString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Length
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;
}
示例2: Unserialize
bool Unserialize( CUtlBuffer &buf, CUtlString &dest )
{
int nLen = buf.PeekDelimitedStringLength( s_pConv );
dest.SetLength( nLen - 1 ); // -1 because the length returned includes space for \0
buf.GetDelimitedString( s_pConv, dest.Get(), nLen );
return buf.IsValid();
}
示例3: OnCommand
//=============================================================================
void DownloadCampaign::OnCommand(const char *command)
{
if ( Q_stricmp( command, "Continue" ) == 0 )
{
CUtlString dest;
if ( V_strnicmp( "http:", m_webSite.Get(), 4 ) != 0 || V_strnicmp( "https:", m_webSite.Get(), 4 ) != 0 )
{
dest = "http://";
dest += m_webSite;
}
else
{
dest = m_webSite;
}
system()->ShellExecute("open", dest.Get() );
NavigateBack();
}
else if ( Q_stricmp( command, "Back" ) == 0 )
{
CBaseModPanel::GetSingleton().PlayUISound( UISOUND_BACK );
NavigateBack();
}
else
{
BaseClass::OnCommand( command );
}
}
示例4: MEM_ALLOC_CREDIT
void CBaseGameStats_Driver::PossibleMapChange( void )
{
#ifdef GAME_DLL
//detect and copy map changes
if ( Q_stricmp( m_PrevMapName.String(), STRING( gpGlobals->mapname ) ) )
{
MEM_ALLOC_CREDIT();
CUtlString PrevMapBackup = m_PrevMapName;
m_PrevMapName = STRING( gpGlobals->mapname );
gamestats->Event_MapChange( PrevMapBackup.String(), STRING( gpGlobals->mapname ) );
if ( gamestats->UseOldFormat() )
{
if( gamestats->AutoSave_OnMapChange() )
gamestats->SaveToFileNOW();
if( gamestats->AutoUpload_OnMapChange() )
gamestats->UploadStatsFileNOW();
}
}
#endif
}
示例5: mapInfo
void C_HudMapInfo::LevelInitPostEntity()
{
KeyValuesAD mapInfo("MapInfo");
MapData *pData = g_pMapCache->GetCurrentMapData();
if (pData)
{
mapInfo->SetString("mapName", pData->m_szMapName);
CUtlString authors;
if (pData->GetCreditString(&authors, CREDIT_AUTHOR))
{
mapInfo->SetString("authors", authors.Get());
m_pMapAuthorLabel->SetText(CConstructLocalizedString(m_wMapAuthors, (KeyValues*)mapInfo));
}
mapInfo->SetInt("difficulty", pData->m_MainTrack.m_iDifficulty);
m_pMapDifficultyLabel->SetText(CConstructLocalizedString(m_wMapDifficulty, (KeyValues*)mapInfo));
}
else
{
mapInfo->SetString("mapName", g_pGameRules->MapName());
m_pMapAuthorLabel->SetText("");
m_pMapDifficultyLabel->SetText("");
}
m_pMapNameLabel->SetText(CConstructLocalizedString(m_wMapName, (KeyValues*)mapInfo));
}
示例6: Assert
CUtlString CUtlString::Replace( const char *pszFrom, const char *pszTo ) const
{
Assert( pszTo ); // Can be 0 length, but not null
Assert( pszFrom && *pszFrom ); // Must be valid and have one character.
const char *pos = V_strstr( String(), pszFrom );
if ( !pos )
{
return *this;
}
const char *pFirstFound = pos;
// count number of search string
int nSearchCount = 0;
int nSearchLength = V_strlen( pszFrom );
while ( pos )
{
nSearchCount++;
int nSrcOffset = ( pos - String() ) + nSearchLength;
pos = V_strstr( String() + nSrcOffset, pszFrom );
}
// allocate the new string
int nReplaceLength = V_strlen( pszTo );
int nAllocOffset = nSearchCount * ( nReplaceLength - nSearchLength );
size_t srcLength = Length();
CUtlString strDest;
size_t destLength = srcLength + nAllocOffset;
strDest.SetLength( destLength );
// find and replace the search string
pos = pFirstFound;
int nDestOffset = 0;
int nSrcOffset = 0;
while ( pos )
{
// Found an instance
int nCurrentSearchOffset = pos - String();
int nCopyLength = nCurrentSearchOffset - nSrcOffset;
V_strncpy( strDest.GetForModify() + nDestOffset, String() + nSrcOffset, nCopyLength + 1 );
nDestOffset += nCopyLength;
V_strncpy( strDest.GetForModify() + nDestOffset, pszTo, nReplaceLength + 1 );
nDestOffset += nReplaceLength;
nSrcOffset = nCurrentSearchOffset + nSearchLength;
pos = V_strstr( String() + nSrcOffset, pszFrom );
}
// making sure that the left over string from the source is the same size as the left over dest buffer
Assert( destLength - nDestOffset == srcLength - nSrcOffset );
if ( destLength - nDestOffset > 0 )
{
V_strncpy( strDest.GetForModify() + nDestOffset, String() + nSrcOffset, destLength - nDestOffset + 1 );
}
return strDest;
}
示例7: V_UnqualifiedFileName
CUtlString CUtlString::StripFilename() const
{
const char *pFilename = V_UnqualifiedFileName( Get() ); // NOTE: returns 'Get()' on failure, never NULL
int nCharsToCopy = pFilename - Get();
CUtlString result;
result.SetDirect( Get(), nCharsToCopy );
result.StripTrailingSlash();
return result;
}
示例8: Replace
CUtlString CUtlString::Replace( char cFrom, char cTo )
{
CUtlString ret = *this;
int len = ret.Length();
for ( int i=0; i < len; i++ )
{
if ( ret.m_Storage[i] == cFrom )
ret.m_Storage[i] = cTo;
}
return ret;
}
示例9: GetBaseConditions
pfnConditionsMet CInstructor::GetBaseConditions(const CUtlString& sConditions)
{
if (sConditions == "WhoCares")
return WhoCaresConditions;
else if (sConditions == "ValidPlayer")
return ValidPlayerConditions;
else if (sConditions == "PlayerAlive")
return PlayerAliveConditions;
else if (sConditions == "PlayerDead")
return PlayerDeadConditions;
else if (sConditions == "PlayerCanReload")
return PlayerCanReloadConditions;
else if (sConditions == "PlayerOutOfAmmoAndMultipleWeapons")
return PlayerOutOfAmmoAndMultipleWeaponsConditions;
else if (sConditions == "PlayerHasMultipleWeapons")
return PlayerHasMultipleWeaponsConditions;
else if (sConditions == "PlayerActiveWeaponHasAimIn")
return PlayerActiveWeaponHasAimInConditions;
else if (sConditions == "PlayerHasGrenades")
return PlayerHasGrenadesConditions;
else if (sConditions == "PlayerHasSlowMo")
return PlayerHasSlowMoConditions;
else if (sConditions == "PlayerInThirdPerson")
return PlayerInThirdPersonConditions;
Assert(false);
Error(std::string("Couldn't find lesson condition '").append(sConditions.Get()).append("'\n").c_str());
return NULL;
}
示例10: CUtlString
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;
}
示例11: Q_strcmp
bool CUtlString::operator==( const CUtlString &src ) const
{
if ( IsEmpty() )
{
if ( src.IsEmpty() )
{
return true;
}
return false;
}
else
{
if ( src.IsEmpty() )
{
return false;
}
return Q_strcmp( m_pString, src.m_pString ) == 0;
}
}
示例12: CreateTempFile
static HANDLE CreateTempFile( CUtlString &WritePath, CUtlString &FileName )
{
char tempFileName[MAX_PATH];
if ( WritePath.IsEmpty() )
{
// use a safe name in the cwd
char *pBuffer = tmpnam( NULL );
if ( !pBuffer )
{
return INVALID_HANDLE_VALUE;
}
if ( pBuffer[0] == '\\' )
{
pBuffer++;
}
if ( pBuffer[strlen( pBuffer )-1] == '.' )
{
pBuffer[strlen( pBuffer )-1] = '\0';
}
V_snprintf( tempFileName, sizeof( tempFileName ), "_%s.tmp", pBuffer );
}
else
{
// generate safe name at the desired prefix
char uniqueFilename[MAX_PATH];
SYSTEMTIME sysTime; \
GetLocalTime( &sysTime );
sprintf( uniqueFilename, "%d_%d_%d_%d_%d.tmp", sysTime.wDay, sysTime.wHour, sysTime.wMinute, sysTime.wSecond, sysTime.wMilliseconds ); \
V_ComposeFileName( WritePath.String(), uniqueFilename, tempFileName, sizeof( tempFileName ) );
}
FileName = tempFileName;
HANDLE hFile = CreateFile( tempFileName, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
return hFile;
}
示例13: DisplayLesson
void CInstructor::DisplayLesson(const CUtlString& sLesson)
{
if (!lesson_enable.GetBool())
return;
if (!m_bActive)
return;
if (sLesson.Length() == 0 || m_apLessons.Find(sLesson) == -1)
{
int iLesson = m_apLessons.Find(m_sCurrentLesson);
if (m_apLessons[iLesson] && m_apLessons[iLesson]->m_bKillOnFinish)
SetActive(false);
HideLesson();
return;
}
HideLesson();
m_sCurrentLesson = sLesson;
m_sLastLesson = m_sCurrentLesson;
CLesson* pLesson = m_apLessons[m_apLessons.Find(sLesson)];
C_SDKPlayer *pLocalPlayer = C_SDKPlayer::GetLocalSDKPlayer();
if (pLesson->m_iLearningMethod == CLesson::LEARN_DISPLAYING)
pLocalPlayer->Instructor_LessonLearned(sLesson);
pLocalPlayer->Instructor_LessonShowed(sLesson);
int iLessonTrainings = pLocalPlayer->Instructor_GetLessonTrainings(sLesson);
if (pLesson->m_sSideHintText.Length() && iLessonTrainings == 0)
{
CHudElement* pLessonPanel = gHUD.FindElement("CHudSideHintPanel");
static_cast<CHudSideHintPanel*>(pLessonPanel)->SetLesson(pLesson);
m_bSideHintShowing = true;
}
else
{
CHudElement* pLessonPanel = gHUD.FindElement("CHudLessonPanel");
static_cast<CHudLessonPanel*>(pLessonPanel)->SetLesson(pLesson);
}
}
示例14: OnTick
virtual void OnTick()
{
BaseClass::OnTick();
double ultotal = 0.0;
double ulnow = 0.0;
if ( YouTube_GetUploadProgress( m_uploadHandle, ultotal, ulnow ) == false )
{
Close();
ShowMessageBox( "#YouTube_Upload_Title", "#YouTube_Upload_Failure", "#GameUI_OK" );
}
else if ( YouTube_IsUploadFinished( m_uploadHandle ) )
{
bool bSuccess = true;
CUtlString strURLToVideo;
CUtlString strURLToVideoStats;
if ( YouTube_GetUploadResults( m_uploadHandle, bSuccess, strURLToVideo, strURLToVideoStats ) && bSuccess )
{
// mark movie uploaded
m_pMovie->SetUploaded( true );
m_pMovie->SetUploadURL( strURLToVideoStats.Get() );
g_pReplayMovieManager->FlagMovieForFlush( m_pMovie, true );
// update the UI
CReplayDetailsPanel *pDetailsPanel = dynamic_cast< CReplayDetailsPanel *>( GetParent() );
if ( pDetailsPanel )
{
pDetailsPanel->InvalidateLayout( true, false );
}
ShowMessageBox( "#YouTube_Upload_Title", "#YouTube_Upload_Success", "#GameUI_OK", NULL, GetParent() );
// notify the GC
uint64 uSessionId = g_pClientReplayContext->GetServerSessionId( m_pMovie->GetReplayHandle() );
if ( uSessionId != 0 )
{
GCSDK::CProtoBufMsg< CMsgReplayUploadedToYouTube > msg( k_EMsgGCReplay_UploadedToYouTube );
msg.Body().set_youtube_url( strURLToVideoStats.Get() );
msg.Body().set_youtube_account_name( YouTube_GetLoginName() );
msg.Body().set_session_id( uSessionId );
GCClientSystem()->BSendMessage( msg );
}
surface()->PlaySound( "replay\\youtube_uploadfinished.wav" );
UploadOgsData( m_pMovie, true, "completed" );
// share on Steam Community
if ( steamapicontext && steamapicontext->SteamRemoteStorage() )
{
CUtlString strPreviewFileName;
AppId_t nConsumerAppId = steamapicontext->SteamUtils()->GetAppID();
ERemoteStoragePublishedFileVisibility eVisibility = k_ERemoteStoragePublishedFileVisibilityPublic;
SteamParamStringArray_t tags;
tags.m_ppStrings = NULL;
tags.m_nNumStrings = 0;
// don't bother waiting for result
SteamAPICall_t hSteamAPICall = steamapicontext->SteamRemoteStorage()->PublishVideo(
k_EWorkshopVideoProviderNone, "",
strURLToVideo.Get(),
strPreviewFileName.Get(),
nConsumerAppId,
m_strTitle.Get(),
m_strDescription.Get(),
eVisibility,
&tags
);
hSteamAPICall;
}
}
else
{
ShowMessageBox( "#YouTube_Upload_Title", "#YouTube_Upload_Failure", "#GameUI_OK" );
surface()->PlaySound( "replay\\youtube_uploadfailed.wav" );
UploadOgsData( m_pMovie, true, "failed" );
}
// close wait dialog
YouTube_ClearUploadResults( m_uploadHandle );
Close();
}
else
{
float flProgress = MIN( ulnow / MAX( ultotal, 1.0 ), 1.0f );
int iProgress = int( 100.0 * flProgress );
int ulnow_kb = uint32( ulnow / 1024 );
int ultotal_kb = uint32( ultotal / 1024 );
if ( ulnow_kb == ultotal_kb )
{
// we tick at 500 ms, so this should be ok
m_iTick = ( m_iTick + 1 ) % 4;
switch ( m_iTick )
{
case 0: SetDialogVariable( "duration", g_pVGuiLocalize->Find( "YouTube_UploadFinishing1" ) ); break;
case 1: SetDialogVariable( "duration", g_pVGuiLocalize->Find( "YouTube_UploadFinishing2" ) ); break;
case 2: SetDialogVariable( "duration", g_pVGuiLocalize->Find( "YouTube_UploadFinishing3" ) ); break;
case 3: SetDialogVariable( "duration", g_pVGuiLocalize->Find( "YouTube_UploadFinishing4" ) ); break;
}
}
//.........这里部分代码省略.........
示例15: GetToken
//.........这里部分代码省略.........
}
// copy token to buffer
token_p = token;
if (*script->script_p == '"')
{
// quoted token
script->script_p++;
while (*script->script_p != '"')
{
*token_p++ = *script->script_p++;
if (script->script_p == script->end_p)
break;
if (token_p == &token[MAXTOKEN])
Error ("Token too large on line %i\n",scriptline);
}
script->script_p++;
}
else if ( g_bCheckSingleCharTokens && !g_sSingleCharTokens.IsEmpty() && strchr( g_sSingleCharTokens.String(), *script->script_p ) != NULL )
{
*token_p++ = *script->script_p++;
}
else // regular token
while ( *script->script_p > 32 && *script->script_p != ';')
{
if ( !ExpandMacroToken( token_p ) )
{
if ( !ExpandVariableToken( token_p ) )
{
*token_p++ = *script->script_p++;
if (script->script_p == script->end_p)
break;
if (token_p == &token[MAXTOKEN])
Error ("Token too large on line %i\n",scriptline);
}
}
}
// add null to end of token
*token_p = 0;
// check for other commands
if ( !stricmp( token, "$include" ) )
{
GetToken( false );
bool bFallbackToToken = true;
CUtlVector< CUtlString > expandedPathList;
if ( CmdLib_ExpandWithBasePaths( expandedPathList, token ) > 0 )
{
for ( int i = 0; i < expandedPathList.Count(); ++i )
{
CUtlVector< CUtlString > findFileList;
FindFileAbsoluteList( findFileList, expandedPathList[i].String() );
if ( findFileList.Count() > 0 )
{
bFallbackToToken = false;
// Only add the first set of glob matches from the first base path
for ( int j = 0; j < findFileList.Count(); ++j )
{
AddScriptToStack( const_cast< char * >( findFileList[j].String() ) );
}
break;
}
}
}
if ( bFallbackToToken )
{
AddScriptToStack( token );
}
return GetToken( crossline );
}
else if (!stricmp (token, "$definemacro"))
{
GetToken (false);
DefineMacro(token);
return GetToken (crossline);
}
else if (!stricmp (token, "$definevariable"))
{
GetToken (false);
DefineVariable(token);
return GetToken (crossline);
}
else if (AddMacroToStack( token ))
{
return GetToken (crossline);
}
return true;
}