1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-28 19:29:53 +00:00

Add a user index to class StrBuf

git-svn-id: svn://svn.cc65.org/cc65/trunk@1411 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2002-09-29 19:49:55 +00:00
parent 689202057c
commit 0e4493f075
2 changed files with 44 additions and 8 deletions

View File

@ -1,12 +1,12 @@
/*****************************************************************************/
/* */
/* strbuf.c */
/* strbuf.c */
/* */
/* Variable sized string buffers */
/* */
/* */
/* */
/* (C) 2001 Ullrich von Bassewitz */
/* (C) 2001-2002 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
@ -42,7 +42,7 @@
/*****************************************************************************/
/* Data */
/* Data */
/*****************************************************************************/
@ -63,6 +63,7 @@ StrBuf* InitStrBuf (StrBuf* B)
{
B->Allocated = 0;
B->Len = 0;
B->Index = 0;
B->Buf = 0;
return B;
}

View File

@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 2001 Ullrich von Bassewitz */
/* (C) 2001-2002 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
@ -55,16 +55,17 @@
typedef struct StrBuf StrBuf;
struct StrBuf {
unsigned Allocated;
unsigned Len;
char* Buf;
unsigned Allocated; /* Size of allocated memory */
unsigned Len; /* Length of the string */
unsigned Index; /* Used for reading (Get and friends) */
char* Buf; /* Pointer to buffer */
};
/* An empty string buf */
extern const StrBuf EmptyStrBuf;
/* Initializer for static string bufs */
#define STATIC_STRBUF_INITIALIZER { 0, 0, 0 }
#define STATIC_STRBUF_INITIALIZER { 0, 0, 0, 0 }
/* Initializer for auto string bufs */
#define AUTO_STRBUF_INITIALIZER EmptyStrBuf
@ -104,6 +105,16 @@ INLINE unsigned SB_GetLen (StrBuf* B)
# define SB_GetLen(B) (B)->Len
#endif
#if defined(HAVE_INLINE)
INLINE unsigned SB_GetIndex (StrBuf* B)
/* Return the user index of the string buffer */
{
return B->Index;
}
#else
# define SB_GetIndex(B) (B)->Index
#endif
#if defined(HAVE_INLINE)
INLINE const char* SB_GetConstBuf (const StrBuf* B)
/* Return a buffer pointer */
@ -166,6 +177,30 @@ INLINE void SB_Clear (StrBuf* B)
# define SB_Clear(B) ((B)->Len = 0)
#endif
#if defined(HAVE_INLINE)
INLINE char SB_Get (StrBuf* B)
/* Return the next character from the string incrementing Index. Returns NUL
* if the end of the string is reached.
*/
{
return (B->Index < B->Len)? B->Buf[B->Index++] : '\0';
}
#else
# define SB_Get(B) (((B)->Index < (B)->Len)? (B)->Buf[(B)->Index++] : '\0')
#endif
#if defined(HAVE_INLINE)
INLINE char SB_Peek (StrBuf* B)
/* Look at the next character from the string without incrementing Index.
* Returns NUL if the end of the string is reached.
*/
{
return (B->Index < B->Len)? B->Buf[B->Index] : '\0';
}
#else
# define SB_Peek(B) (((B)->Index < (B)->Len)? (B)->Buf[(B)->Index] : '\0')
#endif
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!