Symbian 读写 INI 配置文件的方法
2010-04-20 16:06:00 来源:WEB开发网TPtr8 ptr8(bufc->Des());
FGets(ptr8); //?s??????ļ?????
bufc->Des().Append(_L8(“ ”));
TPtrC8 iCursor(bufc->Des()); //ָ???ļ????ݵ?ָ??
TInt iPos = 0;
m_pIniElements = new(ELeave) CArrayPtrFlat
TBuf8<40> szCurSection(_L8(“”));
TBuf8<40> szSection(_L8(“”));
while( ( iPos = iCursor.FindF(_L8(“ ”)) ) >= 0 ) {
iPos = iCursor.FindF(_L8(“ ”));
TPtrC8 result = iCursor.Left(iPos); //ȡ??һ??????
HBufC8 *pTmp = HBufC8::NewL(result.Length());
pTmp->Des().Copy(result);
pTmp->Des().Trim();
if((pTmp->Des().Length() > 0) && pTmp->Des()[0] == ‘[') //????section
{
pTmp->Des().Delete(0, 1);
if( pTmp->Des()[pTmp->Des().Length() -1 ] == ‘]’)
pTmp->Des().Delete(pTmp->Des().Length()-1, 1);
szSection.Copy(pTmp->Des());
if (szCurSection != szSection)
szCurSection = szSection;
} else if( KErrNotFound != pTmp->Des().Find(_L8(“=”)) ) //key=value
{
if (szCurSection.Compare(_L8(“”)) != 0)
{
IniElement *element = new(ELeave) IniElement;
element->_Section.Copy(szCurSection) ;
TPtrC8 ptrKey(pTmp->Des());
TInt iKeyPos=0;
iKeyPos = ptrKey.FindF(_L8(“=”));
TPtrC8 ptrTmpKey = ptrKey.Left(iKeyPos);
element->_Key.Copy(ptrTmpKey);
element->_Key.Trim();
ptrKey.Set( ptrKey.Right(ptrKey.Length() ? iKeyPos -1) );
element->_Value.Copy(ptrKey);
element->_Value.Trim();
m_pIniElements->AppendL(element);
}
} else //ע??,,???е????????
{
if (szCurSection.Compare(_L8(“”)) ==0 ) //û??section??ע?Ϳ???..???ļ???ͷ
更多精彩
赞助商链接