Two new functions: Buf_Data() returns a reference to the data in

the buffer and Buf_AppendBuf() appends a copy of one buffer to another
buffer.

Patch:		7.146,7.147

Submitted by:	Max Okumoto <okumoto@ucsd.edu>
This commit is contained in:
Hartmut Brandt 2005-03-22 07:42:51 +00:00
parent ebf3f2a194
commit 9668c011e9
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=143957
2 changed files with 32 additions and 8 deletions

View File

@ -70,6 +70,18 @@ Buf_Size(const Buffer *buf)
return (buf->end - buf->buf);
}
/**
* Returns a reference to the data contained in the buffer.
*
* @note Adding data to the Buffer object may invalidate the reference.
*/
inline char *
Buf_Data(const Buffer *bp)
{
return (bp->buf);
}
/**
* Expand the buffer to hold the number of additional bytes, plus
* space to store a terminating NULL byte.
@ -222,12 +234,23 @@ Buf_Append(Buffer *bp, const char str[])
Buf_AddBytes(bp, strlen(str), str);
}
/**
* Append characters in buf to Buffer object
*/
void
Buf_AppendBuf(Buffer *bp, const Buffer *buf)
{
Buf_AddBytes(bp, Buf_Size(buf), buf->buf);
}
/**
* Append characters between str and end to Buffer object.
*/
void
Buf_AppendRange(Buffer *bp, const char str[], const char *end)
{
Buf_AddBytes(bp, end - str, str);
}

View File

@ -76,16 +76,17 @@ typedef struct Buffer {
void Buf_AddByte(Buffer *, Byte);
void Buf_AddBytes(Buffer *, size_t, const Byte *);
Byte *Buf_GetAll(Buffer *, size_t *);
void Buf_Clear(Buffer *);
size_t Buf_Size(const Buffer *);
Buffer *Buf_Init(size_t);
void Buf_Destroy(Buffer *, Boolean);
void Buf_ReplaceLastByte(Buffer *, Byte);
char *Buf_Peel(Buffer *);
void Buf_Append(Buffer *, const char []);
void Buf_AppendBuf(Buffer *, const Buffer *);
void Buf_AppendRange(Buffer *, const char [], const char *);
void Buf_Clear(Buffer *);
char *Buf_Data(const Buffer *);
void Buf_Destroy(Buffer *, Boolean);
Byte *Buf_GetAll(Buffer *, size_t *);
Buffer *Buf_Init(size_t);
char *Buf_Peel(Buffer *);
void Buf_ReplaceLastByte(Buffer *, Byte);
size_t Buf_Size(const Buffer *);
void Buf_StripNewlines(Buffer *);
#endif /* buf_h_a61a6812 */