-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathFio.cpp
More file actions
81 lines (66 loc) · 1.26 KB
/
Copy pathFio.cpp
File metadata and controls
81 lines (66 loc) · 1.26 KB
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
79
80
81
#include "Fio.h"
#include <stdlib.h>
FBuffer::FBuffer()
{
__m_nline = 1;
__m_buffer = NULL;
}
FBuffer::~FBuffer()
{
if (__m_buffer)
free(__m_buffer);
}
bool FBuffer::load(const char * path)
{
FILE *pf = fopen(path, "rb");
if (!pf)
return false;
fseek(pf, 0, SEEK_END);
long lSize = ftell(pf);
__m_buffer = (char*)malloc(lSize + 1);
if (!__m_buffer)
return false;
rewind(pf); //Ö¸ÕëÖØÐÂÖ¸ÏòÎļþ¿ªÊ¼
fread(__m_buffer, sizeof(char), lSize, pf);
__m_buffer[lSize] = '\0';
fclose(pf);
// set
__m_p = __m_buffer;
__m_lastp = __m_p;
__m_filename = path;
__m_current = *__m_p;
return true;
}
void FBuffer::nextline()
{
int old = __m_current;
next();
if (currIsNewline() && __m_current != old)
next();
__m_nline++;
}
char FBuffer::next()
{
__m_p++;
__m_current = *__m_p;
return __m_current;
}
std::string getFileNameByFilePath(const std::string filepath)
{
int l_idx = filepath.rfind('\\');
if (l_idx == std::string::npos)
{
l_idx = filepath.rfind('/');
}
int r_idx = filepath.rfind('.');
return filepath.substr(l_idx + 1, r_idx - l_idx - 1);
}
std::string getFileDir(const std::string filepath)
{
int l_idx = filepath.rfind('\\');
if (l_idx == std::string::npos)
{
l_idx = filepath.rfind('/');
}
return filepath.substr(0, l_idx + 1);
}