📄 myinisection.cpp
字号:
// MyIniSection.cpp: implementation of the CMyIniSection class.
//
//////////////////////////////////////////////////////////////////////
#include "MyIniSection.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMyIniSection::CMyIniSection(BOOL bCritical) : m_bCritical(bCritical)
{
}
CMyIniSection::~CMyIniSection()
{
}
//////////////////////////////////////////////////////////////////////
BOOL CMyIniSection::Create (const char* pBuf, DWORD dwBufSize, const char* pszSectionName)
{
if (!pBuf || !pszSectionName)
return FALSE;
char szSection[256] = "";
sprintf(szSection, "[%s]", pszSectionName);
m_strSection = pszSectionName;
DWORD dwOffset = 0;
BOOL bSucFound = FALSE;
while(true)
{
// 取出一行Txt
char szLine[1024] = "";
if (!MemTxtLineGet(pBuf, dwBufSize, dwOffset, szLine, sizeof(szLine)))
break;
// 解析此行, 先寻找SECTION
if (0 != stricmp(szSection, szLine))
continue;
bSucFound = TRUE;
// 搜寻SECTION内容
while (true)
{
char szLine[1024] ="";
if (!MemTxtLineGet(pBuf, dwBufSize, dwOffset, szLine, sizeof(szLine)))
break;
if (strrchr(szLine, '[') && strrchr(szLine, ']'))
break;
char* pszContent = strstr(szLine, "=");
if (!pszContent) // 没有'=', 非法行
continue;
char szTitle[256] = "";
strncpy(szTitle, szLine, pszContent - szLine);
m_setContent[szTitle] = (pszContent + 1);
}
}
return bSucFound;
}
//////////////////////////////////////////////////////////////////////
const char* CMyIniSection::GetString (const char* pszTitle) const
{
std::map< std::string, std::string >::const_iterator iter = m_setContent.find(pszTitle);
if (iter != m_setContent.end())
{
return (*iter).second.c_str();
}
if (m_bCritical)
::ErrorOut("Error: %s not found in %s.", pszTitle, m_strSection.c_str());
else
::DebugMsg("Error: %s not found in %s.", pszTitle, m_strSection.c_str());
return NULL;
}
//////////////////////////////////////////////////////////////////////
int CMyIniSection::GetData (const char* pszTitle) const
{
std::map< std::string, std::string >::const_iterator iter = m_setContent.find(pszTitle);
if (iter != m_setContent.end())
{
return atoi((*iter).second.c_str());
}
if (m_bCritical)
::ErrorOut("Error: %s not found in %s.", pszTitle, m_strSection.c_str());
else
::DebugMsg("Error: %s not found in %s.", pszTitle, m_strSection.c_str());
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -