forked from gildor2/UEViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextContainer.cpp
More file actions
43 lines (32 loc) · 915 Bytes
/
Copy pathTextContainer.cpp
File metadata and controls
43 lines (32 loc) · 915 Bytes
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
#include "Core.h"
#include "TextContainer.h"
CTextRec *CTextContainer::Add(const char *text)
{
if (!text || !*text) return NULL; // empty text
if (!filled)
{ // 1st record - perform initialization
lastRec = NULL;
fillPos = 0;
}
CTextRec *rec = (CTextRec*) &textBuf[fillPos];
int len = strlen(text);
if (!len) return NULL;
int size = recSize + len + 1;
if (fillPos + size > bufSize) return NULL; // out of buffer space
memset(rec, 0, recSize);
rec->text = (char*) OffsetPointer(rec, recSize);
memcpy(rec->text, text, len+1);
if (lastRec) lastRec->next = rec;
lastRec = rec;
fillPos += size;
filled = true;
return rec;
}
void CTextContainer::Enumerate(void (*func) (const CTextRec *rec))
{
guard(CTextContainer::Enumerate);
if (!filled) return;
for (CTextRec *rec = (CTextRec*) textBuf; rec; rec = rec->next)
func(rec);
unguard;
}