mirror of
https://github.com/cc65/cc65.git
synced 2024-09-29 17:56:21 +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:
parent
689202057c
commit
0e4493f075
@ -1,12 +1,12 @@
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* */
|
/* */
|
||||||
/* strbuf.c */
|
/* strbuf.c */
|
||||||
/* */
|
/* */
|
||||||
/* Variable sized string buffers */
|
/* Variable sized string buffers */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 2001 Ullrich von Bassewitz */
|
/* (C) 2001-2002 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* Wacholderweg 14 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70597 Stuttgart */
|
||||||
/* EMail: uz@musoftware.de */
|
/* EMail: uz@musoftware.de */
|
||||||
@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Data */
|
/* Data */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
@ -63,6 +63,7 @@ StrBuf* InitStrBuf (StrBuf* B)
|
|||||||
{
|
{
|
||||||
B->Allocated = 0;
|
B->Allocated = 0;
|
||||||
B->Len = 0;
|
B->Len = 0;
|
||||||
|
B->Index = 0;
|
||||||
B->Buf = 0;
|
B->Buf = 0;
|
||||||
return B;
|
return B;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 2001 Ullrich von Bassewitz */
|
/* (C) 2001-2002 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* Wacholderweg 14 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70597 Stuttgart */
|
||||||
/* EMail: uz@musoftware.de */
|
/* EMail: uz@musoftware.de */
|
||||||
@ -55,16 +55,17 @@
|
|||||||
|
|
||||||
typedef struct StrBuf StrBuf;
|
typedef struct StrBuf StrBuf;
|
||||||
struct StrBuf {
|
struct StrBuf {
|
||||||
unsigned Allocated;
|
unsigned Allocated; /* Size of allocated memory */
|
||||||
unsigned Len;
|
unsigned Len; /* Length of the string */
|
||||||
char* Buf;
|
unsigned Index; /* Used for reading (Get and friends) */
|
||||||
|
char* Buf; /* Pointer to buffer */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* An empty string buf */
|
/* An empty string buf */
|
||||||
extern const StrBuf EmptyStrBuf;
|
extern const StrBuf EmptyStrBuf;
|
||||||
|
|
||||||
/* Initializer for static string bufs */
|
/* 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 */
|
/* Initializer for auto string bufs */
|
||||||
#define AUTO_STRBUF_INITIALIZER EmptyStrBuf
|
#define AUTO_STRBUF_INITIALIZER EmptyStrBuf
|
||||||
@ -104,6 +105,16 @@ INLINE unsigned SB_GetLen (StrBuf* B)
|
|||||||
# define SB_GetLen(B) (B)->Len
|
# define SB_GetLen(B) (B)->Len
|
||||||
#endif
|
#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)
|
#if defined(HAVE_INLINE)
|
||||||
INLINE const char* SB_GetConstBuf (const StrBuf* B)
|
INLINE const char* SB_GetConstBuf (const StrBuf* B)
|
||||||
/* Return a buffer pointer */
|
/* Return a buffer pointer */
|
||||||
@ -166,6 +177,30 @@ INLINE void SB_Clear (StrBuf* B)
|
|||||||
# define SB_Clear(B) ((B)->Len = 0)
|
# define SB_Clear(B) ((B)->Len = 0)
|
||||||
#endif
|
#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);
|
void SB_Terminate (StrBuf* B);
|
||||||
/* Zero terminate the given string buffer. NOTE: The terminating zero is not
|
/* 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!
|
* accounted for in B->Len, if you want that, you have to use AppendChar!
|
||||||
|
Loading…
Reference in New Issue
Block a user