本文整理汇总了C++中CStr::GetAt方法的典型用法代码示例。如果您正苦于以下问题:C++ CStr::GetAt方法的具体用法?C++ CStr::GetAt怎么用?C++ CStr::GetAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CStr
的用法示例。
在下文中一共展示了CStr::GetAt方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetVariable
BOOL SetVariable( CStr &varName, CValue value )
{
VarError.Empty();
int pos;
CValue *val;
if ( varName.GetLength() > 0 && varName.GetAt(0) == L'[' )
{
CStr expression = varName.Mid( 1 );
CInterpreter parser;
CValue result = parser.EvaluateExpression( expression, FALSE );
int subPos = parser.GetErrorPosition();
if ( parser.GetError() != 0 )
{
VarError = CStr( L"Error in variable reference: " ) + parser.GetErrorMessage();
return FALSE;
}
if ( expression[subPos] != L']' )
{
VarError = L"Variable reference not closed (missing ']')";
return FALSE;
}
val = GetVariable( (CStr)result, TRUE, &pos );
}
else{
val = GetVariable( varName, TRUE, &pos );
}
val->CopyFrom( value );
return (pos != -1);
}
示例2: CreateFile
BOOL
CIniFile::WriteFile( LPCTSTR filename, CStr &content, BOOL append, UINT cp )
{
HANDLE file;
char *buffer = NULL;
char *tmpStr = NULL;
ULONG iLen, feLen;
BOOL rc = TRUE, comPort = FALSE;
if ( filename[wcslen(filename)-1] == ':' )
{
file = CreateFile( filename, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL );
if ( file != INVALID_HANDLE_VALUE )
SetComPort( filename, file );
comPort = TRUE;
}
else
{
CStr fileWithPath;
fileWithPath = filename;
if ( CurrentInterpreter != NULL && ( fileWithPath.GetLength() < 2 || ( fileWithPath.GetAt(0) != '\\' && fileWithPath.GetAt(1) != ':' ) ) )
{
int len = CurrentInterpreter->ScriptFile.ReverseFind('\\');
if ( len == -1 )
fileWithPath = L"\\" + fileWithPath;
else
fileWithPath = CurrentInterpreter->ScriptFile.Left( len+1 ) + fileWithPath;
}
if ( append )
{
file = CreateFile( fileWithPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
if ( SetFilePointer( file, 0, NULL, FILE_END ) == 0 )
append = FALSE;
}
else
file = CreateFile( fileWithPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
}
if ( file == INVALID_HANDLE_VALUE ) rc = FALSE;
if ( rc == TRUE )
{
iLen = content.GetLength();
if ( cp != CP_UNICODE )
{
tmpStr = new char[iLen*2+1]; // special characters might use 2 bytes!
if ( tmpStr == NULL ) rc = FALSE;
}
else
tmpStr = NULL;
}
if ( rc == TRUE )
{
ULONG written;
int stat;
if ( cp != CP_UNICODE && cp != CP_UNICODE_PREFIX )
{
if ( cp == CP_UTF8_PREFIX )
{
if ( ! comPort && ! append )
::WriteFile( file, (void*)"\xEF\xBB\xBF", 3, &written, NULL ); // omit the \0!
cp = CP_UTF8;
}
feLen = WideCharToMultiByte( cp, 0, (LPCTSTR)content, -1, tmpStr, iLen*2+1, NULL, NULL );
if ( !comPort )
stat = ::WriteFile( file, (void*)tmpStr, feLen-1, &written, NULL ); // omit the \0!
else
{
stat = 1, written = 1;
for ( ULONG i=0; i<feLen-1 && stat != 0 && written == 1; i++ )
{
stat = ::WriteFile( file, (void*)&(tmpStr[i]), 1, &written, NULL ); // omit the \0!
}
}
}
else
{
if ( cp == CP_UNICODE_PREFIX )
{
if ( ! comPort && ! append )
::WriteFile( file, (void*)"\xFF\xFE", 2, &written, NULL ); // omit the \0!
}
stat = ::WriteFile( file, (void*)(LPCTSTR)content, (content.GetLength())*2, &written, NULL ); // omit the \0!
}
if ( stat == 0 ) rc = FALSE;
}
if ( file != NULL ) CloseHandle( file );
if ( buffer != NULL ) content.ReleaseBuffer();
if ( tmpStr != NULL ) delete[] tmpStr;
return rc;
}
示例3: CMapStrToString
void
CIniFile::Parse( LPCTSTR cont )
{
CStr content = cont;
CStr sectionName, key, value;
CMapStrToString *section = NULL;
BOOL hasEmptySection = FALSE;
Sections.RemoveAll();
while ( content.GetLength() > 0 )
{
CStr line;
int pos = content.Find( _T("\n") );
if ( pos != -1 )
{
line = content.Left( pos );
content = content.Mid( pos+1 );
}
else
{
line = content;
content = _T("");
}
line.TrimLeft(); line.TrimRight();
if ( line.GetLength() > 0 && line.GetAt(0) != '#' && line.GetAt(0) != ';' )
{
if ( line.GetAt(0) == '[' && line.Right(1) == L"]" )
{
sectionName = line.Mid( 1, line.GetLength()-2 );
sectionName.MakeLower();
section = new CMapStrToString();
Sections.SetAt( sectionName, section );
}
else
{
int eqPos = line.Find( '=' );
if ( eqPos != -1 )
{
key = line.Left( eqPos );
key.TrimLeft(); key.TrimRight();
value = line.Mid( eqPos+1 );
value.TrimLeft(); value.TrimRight();
if ( value.Left(1) == L"\"" && value.Right(1) == L"\"" )
{
value = value.Mid( 1, value.GetLength()-2 );
}
key.MakeLower();
if ( section == NULL && hasEmptySection == FALSE )
{
section = new CMapStrToString();
Sections.SetAt( L"", section );
hasEmptySection = TRUE;
}
section->SetAt( key, value );
}
}
}
}
}
示例4: if
int
CIniFile::ReadFile( LPCTSTR filename, CStr &content, int size, int cp )
{
HANDLE file = NULL;
char *buffer = NULL;
char *tmpStr = NULL;
ULONG fileSize, readSize;
ULONG bufSize;
BOOL rc = 0, com;
int timeout;
if ( wcsnicmp( filename, L"COM", 3 ) == 0 && filename[wcslen(filename)-1] == ':' )
{
file = CreateFile( filename, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL );
if ( file != INVALID_HANDLE_VALUE )
{
timeout = SetComPort( filename, file );
}
com = TRUE;
}
else
{
CStr fileWithPath;
fileWithPath = filename;
if ( CurrentInterpreter != NULL && ( fileWithPath.GetLength() < 2 || ( fileWithPath.GetAt(0) != '\\' && fileWithPath.GetAt(1) != ':' ) ) )
{
int len = CurrentInterpreter->ScriptFile.ReverseFind('\\');
if ( len == -1 )
fileWithPath = L"\\" + fileWithPath;
else
fileWithPath = CurrentInterpreter->ScriptFile.Left( len+1 ) + fileWithPath;
}
file = CreateFile( fileWithPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
com = FALSE;
}
if ( file == INVALID_HANDLE_VALUE )
{
int error = GetLastError();
rc = -2;
}
if ( rc == 0 )
{
if ( size <= 0 )
{
fileSize = GetFileSize( file, NULL );
}
else
{
fileSize = size;
}
if ( fileSize > 1024 * 1024 || fileSize == -1 )
{
// Too big
rc = -3;
}
}
if ( rc == 0 )
{
bufSize = (fileSize+1)*sizeof(TCHAR);
buffer = (char*)content.GetBufferSetLength( bufSize );
if ( buffer == NULL ) rc = -4;
}
if ( rc == 0 )
{
tmpStr = new char[fileSize+2]; // if it's unicode, two binary zeroes are required at the end
if ( tmpStr == NULL ) rc = -4;
}
if ( rc == 0 )
{
if ( ! com )
{
int stat = ::ReadFile( file, (void*)tmpStr, fileSize, &readSize, NULL );
if ( stat == 0 )
{
int error = GetLastError();
rc = -5;
}
}
else
{
comPort = &file;
comTargetSize = fileSize+1;
comTargetBuffer = tmpStr;
DWORD dwThreadID;
HANDLE readThread = CreateThread( NULL, 0, PortReadThread, 0, 0, &dwThreadID );
if ( readThread != NULL )
{
WaitForSingleObject( readThread, timeout );
TerminateThread( readThread, 0 );
CloseHandle( readThread );
SetCommMask( file, 0 );
readSize = comReadSize;
//.........这里部分代码省略.........