-
Notifications
You must be signed in to change notification settings - Fork 5
/
LxContextBuf.cpp
89 lines (82 loc) · 2.16 KB
/
LxContextBuf.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
79
80
81
82
83
84
85
86
87
88
89
#include "stdafx.h"
#include "LxContextBuf.h"
TrivalStrBuf::TrivalStrBuf() : size_(0) {}
TrivalStrBuf::~TrivalStrBuf() {}
void TrivalStrBuf::store_stream(FILE* file)
{
if( size_ > 0 )
fwrite(str_buf,sizeof(TCHAR),size_,file);
}
size_t TrivalStrBuf::Insert(size_t position, TCHAR ch)
{
if( remaining_capacity() == 0 ) return 0;
if( position > size_ ) return 0;
if( position == size_ )
{
str_buf[size_++]=ch;
return 1;
}
memmove(str_buf+position+1,str_buf+position,size_-position);
str_buf[position]=ch;
size_++;
return 1;
}
size_t TrivalStrBuf::Insert(size_t position, TCHAR* str, size_t count)
{
if( remaining_capacity() < count ) return 0;
if( position > size_ ) return 0;
if( position == size_ )
{
memcpy(str_buf+position,str,count);
size_+=count;
return count;
}
memmove(str_buf+position+count,str_buf+position,size_-position);
memcpy(str_buf+position,str,count);
size_+=count;
return count;
}
size_t TrivalStrBuf::Delete(size_t section_begin, size_t section_end)
{
if( section_begin > section_end ) return 0;
if( section_begin >= size_ ) return 0;
if( section_end >= size_-1 )
{
size_t deleted=size_-section_begin;
size_-=deleted;
return deleted;
}
memmove(str_buf+section_begin,str_buf+section_end+1,size_-1-section_end);
size_-=section_end-section_begin+1;
return section_end-section_begin+1;
}
RandomAccessStrBuf::RandomAccessStrBuf() {}
RandomAccessStrBuf::~RandomAccessStrBuf()
{
auto it_b=str_buffer_list.begin();
auto it_e=str_buffer_list.end();
for(;it_b != it_e;it_b++)
delete *it_b;
str_buffer_list.clear();
}
void RandomAccessStrBuf::store_stream(FILE* file)
{
auto it_b=str_buffer_list.begin();
auto it_e=str_buffer_list.end();
for(;it_b != it_e;it_b++)
(*it_b)->store_stream(file);
}
void RandomAccessStrBuf::Insert(size_t position, TCHAR ch)
{
size_t cursor=0;
auto it_b=str_buffer_list.begin();
auto it_e=str_buffer_list.end();
for(;it_b != it_e;it_b++)
cursor+=(*it_b)->size();
}
void RandomAccessStrBuf::Insert(size_t position, TCHAR* str, size_t count)
{
}
void RandomAccessStrBuf::Delete(size_t section_begin, size_t section_end)
{
}