-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.cpp
79 lines (69 loc) · 1.83 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*=============================================================================
#
# Author: carbon - ecras_y@163.com
#
# QQ : 1330186768
#
# Last modified: 2016-05-09 11:11
#
# Filename: test.cpp
#
# Description: demo for testing test.ini
#
=============================================================================*/
#include <iostream>
#include "ini.h"
#include "stdstring.h"
CStdString GetFileName(const CStdString& filepath)
{
CStdString strName = filepath;
int nfind = strName.ReverseFind(CHAR_SLASH);
if (nfind != -1)
{
strName = strName.Mid(nfind + 1);
}
return strName;
}
CStdString GetFilePath(const CStdString& filepath)
{
CStdString strPath = filepath;
int nfind = strPath.ReverseFind(CHAR_SLASH);
if (nfind != -1)
{
strPath = strPath.Mid(0, nfind + 1);
}
return strPath;
}
CStdString GetFileExt(const CStdString& filepath)
{
CStdString strExt;
int nfind = filepath.ReverseFind('.');
if (nfind != -1)
{
strExt = filepath.Mid(nfind + 1);
}
return strExt;
}
int main(int argc, char* argv[])
{
CStdString filepath = "/home/liuhuan/test/ini/test.ini";
std::cout << GetFileName(filepath).c_str() << "\n";
std::cout << GetFilePath(filepath).c_str() << "\n";
std::cout << GetFileExt(filepath).c_str() << "\n";
CIniParser cp("/home/liuhuan/test/ini/test.ini");
if(cp.Parse())
{
cp.DumpIni();
if(argc > 1)
{
cp.SetValue(_T("carbon"), _T("vol"), _T("setvol"));
cp.SetValue(_T("god"), _T("vol"), _T("setvol"));
cp.SetValue(_T("new"), _T("vol"), _T("setvol"));
cp.SetValue(_T("new"), _T("hello"), _T("setvol"));
cp.RemoveKey(_T("carbon"), _T("joke"));
cp.RemoveSection(_T("remove"));
cp.DumpIni();
}
}
return 0;
}