mirror of
https://github.com/cc65/cc65.git
synced 2024-12-23 19:29:37 +00:00
Beafed up the string buffer module
git-svn-id: svn://svn.cc65.org/cc65/trunk@2496 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
2541ddd2f6
commit
e08261dff3
@ -102,7 +102,7 @@ void FreeStrBuf (StrBuf* B)
|
||||
|
||||
|
||||
|
||||
void SB_Realloc (StrBuf* B, unsigned NewSize)
|
||||
static void SB_Realloc (StrBuf* B, unsigned NewSize)
|
||||
/* Reallocate the string buffer space, make sure at least NewSize bytes are
|
||||
* available.
|
||||
*/
|
||||
@ -136,6 +136,18 @@ char SB_At (const StrBuf* B, unsigned Index)
|
||||
|
||||
|
||||
|
||||
void SB_Drop (StrBuf* B, unsigned Count)
|
||||
/* Drop characters from the end of the string. */
|
||||
{
|
||||
PRECONDITION (Count <= B->Len);
|
||||
B->Len -= Count;
|
||||
if (B->Index > B->Len) {
|
||||
B->Index = B->Len;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SB_Terminate (StrBuf* B)
|
||||
/* Zero terminate the given string buffer. NOTE: The terminating zero is not
|
||||
* accounted for in B->Len, if you want that, you have to use AppendChar!
|
||||
|
@ -90,11 +90,6 @@ StrBuf* NewStrBuf (void);
|
||||
void FreeStrBuf (StrBuf* B);
|
||||
/* Free a string buffer */
|
||||
|
||||
void SB_Realloc (StrBuf* B, unsigned NewSize);
|
||||
/* Reallocate the string buffer space, make sure at least NewSize bytes are
|
||||
* available. THIS IS NOT A USER CALLABLE FUNCTION!
|
||||
*/
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE unsigned SB_GetLen (StrBuf* B)
|
||||
/* Return the length of the buffer contents */
|
||||
@ -167,14 +162,34 @@ INLINE int SB_IsEmpty (const StrBuf* B)
|
||||
# define SB_IsEmpty(B) ((B)->Len == 0)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE int SB_NotEmpty (const StrBuf* B)
|
||||
/* Return true if the string buffer is not empty */
|
||||
{
|
||||
return (B->Len > 0);
|
||||
}
|
||||
#else
|
||||
# define SB_NotEmpty(B) ((B)->Len > 0)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void SB_Clear (StrBuf* B)
|
||||
/* Clear the string buffer (make it empty) */
|
||||
{
|
||||
B->Len = 0;
|
||||
B->Len = B->Index = 0;
|
||||
}
|
||||
#else
|
||||
# define SB_Clear(B) ((B)->Len = 0)
|
||||
# define SB_Clear(B) ((B)->Len = (B)->Index = 0)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void SB_Reset (StrBuf* B)
|
||||
/* Reset the string buffer index to zero */
|
||||
{
|
||||
B->Index = 0;
|
||||
}
|
||||
#else
|
||||
# define SB_Reset(B) ((B)->Index = 0)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
@ -190,7 +205,7 @@ INLINE char SB_Get (StrBuf* B)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE char SB_Peek (StrBuf* B)
|
||||
INLINE char SB_Peek (const StrBuf* B)
|
||||
/* Look at the next character from the string without incrementing Index.
|
||||
* Returns NUL if the end of the string is reached.
|
||||
*/
|
||||
@ -201,6 +216,30 @@ INLINE char SB_Peek (StrBuf* B)
|
||||
# define SB_Peek(B) (((B)->Index < (B)->Len)? (B)->Buf[(B)->Index] : '\0')
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE char SB_LookAt (const StrBuf* B, unsigned Index)
|
||||
/* Look at a specific character from the string. Returns NUL if the given
|
||||
* index is greater than the size of the string.
|
||||
*/
|
||||
{
|
||||
return (Index < B->Len)? B->Buf[Index] : '\0';
|
||||
}
|
||||
#else
|
||||
# define SB_Peek(B,Index) (((Index) < (B)->Len)? (B)->Buf[(Index)] : '\0')
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE char SB_LookAtLast (const StrBuf* B)
|
||||
/* Look at the last character from the string. Returns NUL if the string buffer
|
||||
* is empty.
|
||||
*/
|
||||
{
|
||||
return (B->Len > 0)? B->Buf[B->Len-1] : '\0';
|
||||
}
|
||||
#else
|
||||
# define SB_LookAtLast(B) (((B)->Len > 0)? (B)->Buf[(B)->Len-1] : '\0')
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE void SB_Skip (StrBuf* B)
|
||||
/* Skip the next character in the string buffer if this is possible. */
|
||||
@ -213,6 +252,9 @@ INLINE void SB_Skip (StrBuf* B)
|
||||
# define SB_Skip(B) do { if ((B)->Index < (B)->Len) ++(B)->Index; } while (0)
|
||||
#endif
|
||||
|
||||
void SB_Drop (StrBuf* B, unsigned Count);
|
||||
/* Drop characters from the end of the string. */
|
||||
|
||||
void SB_Terminate (StrBuf* B);
|
||||
/* Zero terminate the given string buffer. NOTE: The terminating zero is not
|
||||
* accounted for in B->Len, if you want that, you have to use AppendChar!
|
||||
|
Loading…
Reference in New Issue
Block a user