Back to index

libcitadel  8.12
Functions
Create/Replace/Append Content into a StrBuf
Stringbuffer, A class for manipulating strings with dynamic buffers

operations to get your Strings into a StrBuf, manipulating them, or appending More...

Collaboration diagram for Create/Replace/Append Content into a StrBuf:

Functions

long StrBufPeek (StrBuf *Buf, const char *ptr, long nThChar, char PeekValue)
 modifies a Single char of the Buf You can point to it via char* or a zero-based integer
long StrBufPook (StrBuf *Buf, const char *ptr, long nThChar, long nChars, char PookValue)
 modifies a range of chars of the Buf You can point to it via char* or a zero-based integer
void StrBufAppendBuf (StrBuf *Buf, const StrBuf *AppendBuf, unsigned long Offset)
 Append a StringBuffer to the buffer.
void StrBufAppendBufPlain (StrBuf *Buf, const char *AppendBuf, long AppendSize, unsigned long Offset)
 Append a C-String to the buffer.
void StrBufVAppendPrintf (StrBuf *Buf, const char *format, va_list ap)
 sprintf like function appending the formated string to the buffer vsnprintf version to wrap into own calls
void StrBufAppendPrintf (StrBuf *Buf, const char *format,...)
 sprintf like function appending the formated string to the buffer
void StrBufPrintf (StrBuf *Buf, const char *format,...)
 sprintf like function putting the formated string into the buffer
size_t CurlFillStrBuf_callback (void *ptr, size_t size, size_t nmemb, void *stream)
 Callback for cURL to append the webserver reply to a buffer.
void StrBufUpCase (StrBuf *Buf)
 uppercase the contents of a buffer
void StrBufLowerCase (StrBuf *Buf)
 lowercase the contents of a buffer

Detailed Description

operations to get your Strings into a StrBuf, manipulating them, or appending


Function Documentation

size_t CurlFillStrBuf_callback ( void *  ptr,
size_t  size,
size_t  nmemb,
void *  stream 
)

Callback for cURL to append the webserver reply to a buffer.

Parameters:
ptrpre-defined by the cURL API; see man 3 curl for mre info
sizepre-defined by the cURL API; see man 3 curl for mre info
nmembpre-defined by the cURL API; see man 3 curl for mre info
streampre-defined by the cURL API; see man 3 curl for mre info

Definition at line 991 of file stringbuf.c.

{

       StrBuf *Target;

       Target = stream;
       if (ptr == NULL)
              return 0;

       StrBufAppendBufPlain(Target, ptr, size * nmemb, 0);
       return size * nmemb;
}

Here is the call graph for this function:

void StrBufAppendBuf ( StrBuf Buf,
const StrBuf AppendBuf,
unsigned long  Offset 
)

Append a StringBuffer to the buffer.

Parameters:
BufBuffer to modify
AppendBufBuffer to copy at the end of our buffer
OffsetShould we start copying from an offset?

Definition at line 817 of file stringbuf.c.

{
       if ((AppendBuf == NULL) || (AppendBuf->buf == NULL) ||
           (Buf == NULL) || (Buf->buf == NULL))
              return;

       if (Buf->BufSize - Offset < AppendBuf->BufUsed + Buf->BufUsed + 1)
              IncreaseBuf(Buf, 
                         (Buf->BufUsed > 0), 
                         AppendBuf->BufUsed + Buf->BufUsed);

       memcpy(Buf->buf + Buf->BufUsed, 
              AppendBuf->buf + Offset, 
              AppendBuf->BufUsed - Offset);
       Buf->BufUsed += AppendBuf->BufUsed - Offset;
       Buf->buf[Buf->BufUsed] = '\0';
}

Here is the call graph for this function:

Here is the caller graph for this function:

void StrBufAppendBufPlain ( StrBuf Buf,
const char *  AppendBuf,
long  AppendSize,
unsigned long  Offset 
)

Append a C-String to the buffer.

Parameters:
BufBuffer to modify
AppendBufBuffer to copy at the end of our buffer
AppendSizenumber of bytes to copy; set to -1 if we should count it in advance
OffsetShould we start copying from an offset?

Definition at line 844 of file stringbuf.c.

{
       long aps;
       long BufSizeRequired;

       if ((AppendBuf == NULL) || (Buf == NULL))
              return;

       if (AppendSize < 0 )
              aps = strlen(AppendBuf + Offset);
       else
              aps = AppendSize - Offset;

       BufSizeRequired = Buf->BufUsed + aps + 1;
       if (Buf->BufSize <= BufSizeRequired)
              IncreaseBuf(Buf, (Buf->BufUsed > 0), BufSizeRequired);

       memcpy(Buf->buf + Buf->BufUsed, 
              AppendBuf + Offset, 
              aps);
       Buf->BufUsed += aps;
       Buf->buf[Buf->BufUsed] = '\0';
}

Here is the call graph for this function:

Here is the caller graph for this function:

void StrBufAppendPrintf ( StrBuf Buf,
const char *  format,
  ... 
)

sprintf like function appending the formated string to the buffer

Parameters:
BufBuffer to extend by format and Params
formatprintf alike format to add

Definition at line 918 of file stringbuf.c.

{
       size_t BufSize;
       size_t nWritten;
       size_t Offset;
       size_t newused;
       va_list arg_ptr;
       
       if ((Buf == NULL)  || (format == NULL))
              return;

       BufSize = Buf->BufSize;
       nWritten = Buf->BufSize + 1;
       Offset = Buf->BufUsed;
       newused = Offset + nWritten;

       while (newused >= BufSize) {
              va_start(arg_ptr, format);
              nWritten = vsnprintf(Buf->buf + Buf->BufUsed, 
                                 Buf->BufSize - Buf->BufUsed, 
                                 format, arg_ptr);
              va_end(arg_ptr);
              newused = Buf->BufUsed + nWritten;
              if (newused >= Buf->BufSize) {
                     if (IncreaseBuf(Buf, 1, newused) == -1)
                            return; /* TODO: error handling? */
                     newused = Buf->BufSize + 1;
              }
              else {
                     Buf->BufUsed += nWritten;
                     BufSize = Buf->BufSize;
              }

       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void StrBufLowerCase ( StrBuf Buf)

lowercase the contents of a buffer

Parameters:
Bufthe buffer to translate

Definition at line 1197 of file stringbuf.c.

{
       char *pch, *pche;

       if ((Buf == NULL) || (Buf->BufUsed == 0)) return;

       pch = Buf->buf;
       pche = pch + Buf->BufUsed;
       while (pch < pche) {
              *pch = tolower(*pch);
              pch ++;
       }
}

Here is the caller graph for this function:

long StrBufPeek ( StrBuf Buf,
const char *  ptr,
long  nThChar,
char  PeekValue 
)

modifies a Single char of the Buf You can point to it via char* or a zero-based integer

Parameters:
BufThe buffer to manipulate
ptrchar* to zero; use NULL if unused
nThCharzero based pointer into the string; use -1 if unused
PeekValueThe Character to place into the position

Definition at line 771 of file stringbuf.c.

{
       if (Buf == NULL)
              return -1;
       if (ptr != NULL)
              nThChar = ptr - Buf->buf;
       if ((nThChar < 0) || (nThChar > Buf->BufUsed))
              return -1;
       Buf->buf[nThChar] = PeekValue;
       return nThChar;
}

Here is the caller graph for this function:

long StrBufPook ( StrBuf Buf,
const char *  ptr,
long  nThChar,
long  nChars,
char  PookValue 
)

modifies a range of chars of the Buf You can point to it via char* or a zero-based integer

Parameters:
BufThe buffer to manipulate
ptrchar* to zero; use NULL if unused
nThCharzero based pointer into the string; use -1 if unused
nCharshow many chars are to be flushed?
PookValueThe Character to place into that area

Definition at line 793 of file stringbuf.c.

{
       if (Buf == NULL)
              return -1;
       if (ptr != NULL)
              nThChar = ptr - Buf->buf;
       if ((nThChar < 0) || (nThChar > Buf->BufUsed))
              return -1;
       if (nThChar + nChars > Buf->BufUsed)
              nChars =  Buf->BufUsed - nThChar;

       memset(Buf->buf + nThChar, PookValue, nChars);
       /* just to be shure... */
       Buf->buf[Buf->BufUsed] = 0;
       return nChars;
}
void StrBufPrintf ( StrBuf Buf,
const char *  format,
  ... 
)

sprintf like function putting the formated string into the buffer

Parameters:
BufBuffer to extend by format and Parameters
formatprintf alike format to add

Definition at line 960 of file stringbuf.c.

{
       size_t nWritten;
       va_list arg_ptr;
       
       if ((Buf == NULL)  || (format == NULL))
              return;

       nWritten = Buf->BufSize + 1;
       while (nWritten >= Buf->BufSize) {
              va_start(arg_ptr, format);
              nWritten = vsnprintf(Buf->buf, Buf->BufSize, format, arg_ptr);
              va_end(arg_ptr);
              if (nWritten >= Buf->BufSize) {
                     if (IncreaseBuf(Buf, 0, 0) == -1)
                            return; /* TODO: error handling? */
                     nWritten = Buf->BufSize + 1;
                     continue;
              }
              Buf->BufUsed = nWritten ;
       }
}

Here is the call graph for this function:

void StrBufUpCase ( StrBuf Buf)

uppercase the contents of a buffer

Parameters:
Bufthe buffer to translate

Definition at line 1177 of file stringbuf.c.

{
       char *pch, *pche;

       if ((Buf == NULL) || (Buf->BufUsed == 0)) return;

       pch = Buf->buf;
       pche = pch + Buf->BufUsed;
       while (pch < pche) {
              *pch = toupper(*pch);
              pch ++;
       }
}

Here is the caller graph for this function:

void StrBufVAppendPrintf ( StrBuf Buf,
const char *  format,
va_list  ap 
)

sprintf like function appending the formated string to the buffer vsnprintf version to wrap into own calls

Parameters:
BufBuffer to extend by format and Params
formatprintf alike format to add
apva_list containing the items for format

Definition at line 876 of file stringbuf.c.

{
       va_list apl;
       size_t BufSize;
       size_t nWritten;
       size_t Offset;
       size_t newused;

       if ((Buf == NULL)  || (format == NULL))
              return;

       BufSize = Buf->BufSize;
       nWritten = Buf->BufSize + 1;
       Offset = Buf->BufUsed;
       newused = Offset + nWritten;
       
       while (newused >= BufSize) {
              va_copy(apl, ap);
              nWritten = vsnprintf(Buf->buf + Offset, 
                                 Buf->BufSize - Offset, 
                                 format, apl);
              va_end(apl);
              newused = Offset + nWritten;
              if (newused >= Buf->BufSize) {
                     if (IncreaseBuf(Buf, 1, newused) == -1)
                            return; /* TODO: error handling? */
                     newused = Buf->BufSize + 1;
              }
              else {
                     Buf->BufUsed = Offset + nWritten;
                     BufSize = Buf->BufSize;
              }

       }
}

Here is the call graph for this function:

Here is the caller graph for this function: