Programming Utilities

A set of functions which are useful for general purpose, portable programming is provided. These include such basic areas as strings, time, file IO, etc. Many parts of the BIC Volume IO Library refer to the programming utilities, and it is advisable that users of the BIC Volume IO Library try to use these functions whenever convenient. The following is a list of all the programming utilities, grouped into related areas, and ordered alphabetically.

Strings

Some simple string manipulation techniques are provided. Strings are arbitrarily long NULL-terminated character arrays, which are allocated and deleted as needed. The type STRING is defined as:

typedef  char   *STRING;

The basic string creation and deletion routines are:

public  STRING  alloc_string(
    int   length )
public  STRING  create_string(
    STRING    initial )

The function alloc_string allocates storage for a string of the desired length (by allocating length+1 bytes), without assigning any value to the string. The function create_string creates an allocated string with the value equal to initial. If initial is a NULL pointer an empty string (``'') is created.

public  void  delete_string(
    STRING   string )

The storage associated with a string may be deleted with this function.

public  int  string_length(
    STRING   string )

Returns the length of the string.

public  BOOLEAN  equal_strings(
    STRING   str1,
    STRING   str2 )

Returns TRUE if the two strings are exactly equal.

public  void  replace_string(
    STRING   *string,
    STRING   new_string )

A convenience function which deletes the string argument, and reassigns it to the new_string. It does not copy the value of new_string, but merely sets the string to the pointer new_string.

public  void  concat_char_to_string(
    STRING   *string,
    char     ch )

Concatenates a character to the end of the string.

public  STRING  concat_strings(
    STRING   str1,
    STRING   str2 )

Creates and returns a string which is the concatenation of the two arguments, without changing the string arguments.

public  void  concat_to_string(
    STRING   *string,
    STRING   str2 )

Replaces the argument string with the concatenation of the arguments string and str2.

public  BOOLEAN  is_lower_case(
    char  ch )

Returns TRUE if the character is a lower case letter.

public  BOOLEAN  is_upper_case(
    char  ch )

Returns TRUE if the character is a upper case letter.

public  char  get_lower_case(
    char   ch )

If the character is upper case, returns the lower case version of the character, otherwise, returns the character itself.

public  char  get_upper_case(
    char   ch )

If the character is lower case, returns the upper case version of the character, otherwise, returns the character itself.

public  BOOLEAN  string_ends_in(
    STRING   string,
    STRING   ending )

Determines if the string ends in the specified ending. For instance, passing the arguments, "rainfall" and "fall" returns TRUE.

public    STRING   strip_outer_blanks(
    STRING  str )

Returns a string which is the argument str without any leading or trailing blanks.

public  void  make_string_upper_case(
    STRING    string )

Converts the string to an all upper case string. Modifies the string in place.

public  int  find_character(
    STRING  string,
    char    ch )

Searches for the given character in the given string, returning the index where it was found, or -1 if it was not found.

public  BOOLEAN  blank_string(
    STRING   string )

Returns true if the string is empty or consists of only space, tab, and newline characters.