BAM
Abstract Machine for Bottom-Up Evaluation with the Push Method
Macros | Typedefs | Functions
str.h File Reference

Defines type str_t and some useful string functions. More...

Go to the source code of this file.

Macros

#define STR_NULL   (static_cast<str_t>(0))
 
#define STR_ERRMSG_LEN   80
 
#define STR_INT_LEN   11
 
#define STR_PTR_LEN   17
 

Typedefs

typedef const char * str_t
 

Functions

int str_len (register str_t str)
 
void str_cpy (register char *buf, int len, register str_t str)
 
void str_cat (register char *buf, int len, register str_t str)
 
bool str_eq (register str_t str1, register str_t str2)
 
bool str_contains (register char c, register str_t str)
 
str_t str_indent (int n)
 
void str_error (int err_no, char *buf, int buf_size)
 
int str_uint (char *buf, int buf_len, unsigned int n)
 
int str_int (char *buf, int buf_len, int n)
 
str_t str_fill (int n, int field_width)
 
int str_ptr (char *buf, int buf_len, const void *ptr)
 

Detailed Description

Defines type str_t and some useful string functions.

Macro Definition Documentation

#define STR_ERRMSG_LEN   80

Suggested Length of Buffer for System Error Messages.

#define STR_INT_LEN   11

Suggested Length of Buffer for int Values.

#define STR_NULL   (static_cast<str_t>(0))

Typed NULL pointer for strings.

#define STR_PTR_LEN   17

Suggested Length of Buffer for pointer Values.

Typedef Documentation

typedef const char* str_t

Type for pointers to constant strings (compatible with string literals).

Function Documentation

void str_cat ( register char *  buf,
int  len,
register str_t  str 
)

Safe string concatenation.

This is basically the standard C library strcat function, but it has an additional parameter for the buffer length and ensures that never more characters are written to the buffer.

bool str_contains ( register char  c,
register str_t  str 
)

Check whether character appears in string.

void str_cpy ( register char *  buf,
int  len,
register str_t  str 
)

Safe string copy.

This is basically the standard C library strcpy function, but it has an additional parameter for the buffer length and ensures that never more characters are written to the buffer.

bool str_eq ( register str_t  str1,
register str_t  str2 
)

Compare two strings for equality.

This is often a better alternative to the standard C library strcmp function, which returns 0 if the two strings are equal. The value might be interpreted as boolean false, which would be wrong. This function returns the expected boolean value: true if the strings are equal, and false if not.

void str_error ( int  err_no,
char *  buf,
int  buf_size 
)

System Error Message for an Error Number.

str_t str_fill ( int  n,
int  field_width 
)

Returns string of spaces to make integer a given width.

Note that field_width can be at most 12.

str_t str_indent ( int  n)

Returns string of spaces of a given length (at most 75):

int str_int ( char *  buf,
int  buf_len,
int  n 
)

Convert int to text and returns the number of characters.

int str_len ( register str_t  str)

Determine string length.

int str_ptr ( char *  buf,
int  buf_len,
const void *  ptr 
)

Convert pointer to text (hex number) and returns number of characters.

int str_uint ( char *  buf,
int  buf_len,
unsigned int  n 
)

Convert unsigned int to text and returns the number of characters.