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

📄 ini_file.h

📁 实时监控
💻 H
字号:
#ifndef _INI_FILE_H
#define _INI_FILE_H

#pragma warning(disable:4786)

#include "autobuf_file.h"
#include "list"
#include "string"
typedef std::list<std::string> string_list;
typedef string_list::iterator string_it;
typedef std::string string;

extern void ini_for_each(string_list& s, const char* from, const char* sep /*"\x0d\x0a"*/)
{
	char* f = NULL;
	char* g = NULL;
	int sep_l = strlen(sep);

	for(;;)
	{
		f = strstr(from, sep);
		if( !f )
		{
			if( from[0] )
				s.push_back(from);
			break;
		}
		if( f!=from )
			s.push_back(string(from, f-from));

		from = f + sep_l;
	}
}

extern string ini_get_value(const char* inifile, const char* key, const char* def)
{
	charbuf buf;
	int length = load_file_charbuf(inifile, buf);
	if( !length )
		return "";

	string_list lst;
	ini_for_each(lst, buf.data(), "\x0d\x0a");

	for( string_it it=lst.begin(); it!=lst.end(); it++ )
	{
		string& ref = *it;
		string_list key_and_value;
		ini_for_each(key_and_value, ref.c_str(), "=");

		if( key_and_value.size() != 2 )
			continue;
		
		if( key_and_value.front().compare(key) == 0 )
		{
			return key_and_value.back();
		}
	}

	return def;
}

#endif

⌨️ 快捷键说明

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