⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inifile.cpp

📁 C++轻量级分析器
💻 CPP
字号:
#include "..\..\..\Library\Platform\VL_Console.h"
#include "..\..\..\Library\Data\Data\VL_Data_List.h"
#include "..\..\..\Library\Data\Grammar2\Combinator\VL_CpKernel.h"
#include "..\..\..\Library\Data\Grammar2\Combinator\VL_CpRegex.h"

using namespace vl;
using namespace vl::platform;
using namespace vl::grammar;
using namespace vl::collection;

#define LINE(CONTENT) L#CONTENT L"\r\n"

PCWChar IniFile_Content=
LINE([Section One])
LINE(KeyA=ValueA)
LINE(KeyB=ValueB)
LINE([Section Two])
LINE(KeyC=ValueC)
LINE(KeyD=ValueD)
;

typedef VL_CpPair<PCWChar , VInt>						IniString;
typedef VL_CpList<VL_CpPair<IniString , IniString>>		IniKeyValues;
typedef VL_CpList<VL_CpPair<IniString , IniKeyValues>>	IniStructure;

VUnicodeString ToString(IniString s)
{
	return VUnicodeString(s.First,s.Second);
}

void IniFile_Main()
{
	GetConsole()->WriteLine(L"开始分析以下INI文件内容:");
	GetConsole()->WriteLine(IniFile_Content);

	VL_CpParser<PCWChar , IniStructure> IniParser = 
		**(
			(_Regex(L"\\[") > _Regex(L"[^\\[\\]\\r\\n]+") < _Regex(L"\\]")) +
			(
				_Regex(L"[\\r\\n]+") >
				**(
					_Regex(L"[^=\\r\\n]+") + (_Regex(L"=") > _Regex(L"[^\\r\\n]+")) <
					Optx(_Regex(L"[\\r\\n]+"))
				)
			)
		);

	IniStructure Ini=IniParser.Parse(IniFile_Content).Head->Data.First;

	IniStructure::Node::Ptr SectionPtr=Ini.Head;
	while(SectionPtr)
	{
		GetConsole()->WriteLine(L"节名:"+ToString(SectionPtr->Data.First));
		IniKeyValues::Node::Ptr PairPtr=SectionPtr->Data.Second.Head;
		while(PairPtr)
		{
			GetConsole()->WriteLine(L"\t键("+ToString(PairPtr->Data.First)+L") = 值("+ToString(PairPtr->Data.Second)+L")");
			PairPtr=PairPtr->Next;
		}
		SectionPtr=SectionPtr->Next;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -