From d0f9f6bbf258afd9a1f6a6f998beac16de1e8e91 Mon Sep 17 00:00:00 2001 From: daleclack Date: Wed, 2 Feb 2022 11:41:35 +0800 Subject: [PATCH] Add cfgfile lib from Xe-Release --- Gtkmm3/cfgfile/cfgfile.cc | 70 +++++++++++++++++++++++++ Gtkmm3/cfgfile/cfgfile.hh | 7 +++ Gtkmm3/gtk123_backprefs2/CMakeLists.txt | 7 ++- Gtkmm3/gtk123_backprefs2/src/MyPrefs.cc | 1 + 4 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 Gtkmm3/cfgfile/cfgfile.cc create mode 100644 Gtkmm3/cfgfile/cfgfile.hh diff --git a/Gtkmm3/cfgfile/cfgfile.cc b/Gtkmm3/cfgfile/cfgfile.cc new file mode 100644 index 0000000..49fcb68 --- /dev/null +++ b/Gtkmm3/cfgfile/cfgfile.cc @@ -0,0 +1,70 @@ +// A Test to read Config files +// This is a modified version +// The Config File Should be a text file +// and the content as follows +// key=value + +#include "cfgfile.hh" + +static void Trim(std::string &str){ + if(str.empty()){//String is empty + return; + } + + size_t i,start_pos,end_pos; + + for(i=0;i=0;i--){//Get End Position + if(!isspace(str[i])){ + break; + } + } + + end_pos=i; + + str=str.substr(start_pos,end_pos+1); +} + +bool readCfgFile(const char * cfgfilePath,const std::string &key,std::string &value){ + //Open The Config File + std::fstream cfgfile; + cfgfile.open(cfgfilePath); + if(!cfgfile.is_open()){ + std::cout<<"Failed to open the file!"<