Back to index

php5  5.3.10
Defines | Functions | Variables
simplestring.c File Reference
#include <stdlib.h>
#include <string.h>
#include "simplestring.h"

Go to the source code of this file.

Defines

#define SIMPLESTRING_INCR   32
#define my_free(thing)   if(thing) {free(thing); thing = 0;}

Functions

void simplestring_init (simplestring *string)
static void simplestring_init_str (simplestring *string)
void simplestring_clear (simplestring *string)
void simplestring_free (simplestring *string)
void simplestring_addn (simplestring *target, const char *source, int add_len)
void simplestring_add (simplestring *target, const char *source)

Variables

static const char rcsid [] = "#(@) $Id: simplestring.c 146618 2003-12-16 21:00:21Z sniper $"

Define Documentation

#define my_free (   thing)    if(thing) {free(thing); thing = 0;}

Definition at line 85 of file simplestring.c.

#define SIMPLESTRING_INCR   32

Definition at line 37 of file simplestring.c.


Function Documentation

void simplestring_add ( simplestring target,
const char *  source 
)

Definition at line 238 of file simplestring.c.

                                                                {
   if(target && source) {
      simplestring_addn(target, source, strlen(source));
   }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void simplestring_addn ( simplestring target,
const char *  source,
int  add_len 
)

Definition at line 193 of file simplestring.c.

                                                                              {
   if(target && source) {
      if(!target->str) {
         simplestring_init_str(target);
      }
      if(target->len + add_len + 1 > target->size) {
         /* newsize is current length + new length */
         int newsize = target->len + add_len + 1;
         int incr = target->size * 2;

         /* align to SIMPLESTRING_INCR increments */
         newsize = newsize - (newsize % incr) + incr;
         target->str = (char*)realloc(target->str, newsize);

         target->size = target->str ? newsize : 0;
      }

      if(target->str) {
         if(add_len) {
            memcpy(target->str + target->len, source, add_len);
         }
         target->len += add_len;
         target->str[target->len] = 0; /* null terminate */
      }
   }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void simplestring_clear ( simplestring string)

Definition at line 142 of file simplestring.c.

                                              {
   if(string->str) {
      string->str[0] = 0;
   }
   string->len = 0;
}

Here is the caller graph for this function:

void simplestring_free ( simplestring string)

Definition at line 167 of file simplestring.c.

                                             {
   if(string && string->str) {
      my_free(string->str);
      string->len = 0;
   }
}

Here is the caller graph for this function:

void simplestring_init ( simplestring string)

Definition at line 108 of file simplestring.c.

                                             {
   memset(string, 0, sizeof(simplestring));
}

Here is the caller graph for this function:

static void simplestring_init_str ( simplestring string) [static]

Definition at line 113 of file simplestring.c.

                                                        {
   string->str = (char*)malloc(SIMPLESTRING_INCR);
   if(string->str) {
      string->str[0] = 0;
      string->len = 0;
      string->size = SIMPLESTRING_INCR;
   }
   else {
      string->size = 0;
   }
}

Here is the caller graph for this function:


Variable Documentation

const char rcsid[] = "#(@) $Id: simplestring.c 146618 2003-12-16 21:00:21Z sniper $" [static]

Definition at line 34 of file simplestring.c.