mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-13 00:24:12 +00:00
[util] Add a means to open a gap in a text buffer
for loading files into the buffer.
This commit is contained in:
parent
63a2204fa5
commit
4dbf280012
2 changed files with 29 additions and 0 deletions
|
@ -59,6 +59,20 @@ txtbuffer_t *TextBuffer_Create (void);
|
||||||
*/
|
*/
|
||||||
void TextBuffer_Destroy (txtbuffer_t *buffer);
|
void TextBuffer_Destroy (txtbuffer_t *buffer);
|
||||||
|
|
||||||
|
/** Open a gap for writing at the specified offset.
|
||||||
|
|
||||||
|
Text after the offset is moved to be after the opened gap.
|
||||||
|
The buffer is resized as necessary.
|
||||||
|
|
||||||
|
\param buffer The buffer to be updated
|
||||||
|
\param offset The offset in the buffer at which to insert the text block
|
||||||
|
\param text_len The size of the gap to be opened
|
||||||
|
\return Pointr to beginning of gap if successful, 0 if failure
|
||||||
|
(offset not valid or out of memory)
|
||||||
|
*/
|
||||||
|
char *TextBuffer_OpenGap (txtbuffer_t *buffer, size_t offset,
|
||||||
|
size_t text_len);
|
||||||
|
|
||||||
/** Insert a block of text at the specified offset.
|
/** Insert a block of text at the specified offset.
|
||||||
|
|
||||||
Text after the offset is moved to be after the inserted block of text.
|
Text after the offset is moved to be after the inserted block of text.
|
||||||
|
|
|
@ -159,6 +159,21 @@ TextBuffer_Destroy (txtbuffer_t *buffer)
|
||||||
FREE (txtbuffers, buffer);
|
FREE (txtbuffers, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VISIBLE char *
|
||||||
|
TextBuffer_OpenGap (txtbuffer_t *buffer, size_t offset, size_t text_len)
|
||||||
|
{
|
||||||
|
char *dst;
|
||||||
|
|
||||||
|
if (offset > buffer->textSize) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
dst = txtbuffer_open_gap (buffer, offset, text_len);
|
||||||
|
if (!dst) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
VISIBLE int
|
VISIBLE int
|
||||||
TextBuffer_InsertAt (txtbuffer_t *buffer, size_t offset,
|
TextBuffer_InsertAt (txtbuffer_t *buffer, size_t offset,
|
||||||
const char *text, size_t text_len)
|
const char *text, size_t text_len)
|
||||||
|
|
Loading…
Reference in a new issue