This section lists methods for storing text strings in RIFF chunks. While these guidelines may not make sense for all applications, you should follow these conventions if you must make an arbitrary decision regarding string storage.
A NULL-terminated string (ZSTR) consists of a series of characters followed by a terminating NULL character. The ZSTR is better than a simple character sequence (STR) because many programs are easier to write if strings are NULL-terminated. ZSTR is preferred to a string with a size prefix (BSTR or WSTR) because the size of the string is already available as the <ckSize> value, minus one for the terminating NULL character.
In a string table, all strings used in a structure are stored at the end of the structure in packed format. The structure includes fields that specify the offsets from the beginning of the string table to the individual strings. An example follows:
typedef struct
{
INT iWidgetNumber; // the widget number
WORD offszWidgetName; // an offset to a string in <rgchStrTab>
WORD offszWidgetDesc; // an offset to a string in <rgchStrTab>
INT iQuantity; // how many widgets
CHAR rgchStrTab[1]; // string table (allocate as large as needed)
} WIDGET;
If multiple chunks within the file need to reference variable-length strings, you can store the strings in a single chunk that acts as a string table. The chunks that refer to the strings contain offsets relative to the beginning of the data part of the string table chunk.
In a BZSTR series, a series of strings is stored in packed format. Each string is a BZSTR, with a byte size prefix and a NULL terminator. This format retains the ease-of-use characteristics of the ZSTR while providing the string size, allowing the application to quickly skip unneeded strings.
When storing multiline strings, separate lines with a carriage return/line feed pair (ASCII 13/ASCII 10 pair). Although applications vary in their requirements for new line symbols (carriage return only, line feed only, or both), it is generally easier to strip out extra characters than to insert extra ones. Inserting characters might require reallocating memory blocks or pre-scanning the chunk before allocating memory for it.
The following lists guidelines for deciding which storage method is appropriate for your application.
Usage | Recommended Format |
Chunk data contains nothing except a string | ZSTR (NULL-terminated string) format. |
Chunk data contains a number of fields, some of which are variable-length strings | String-table format |
Multiple chunks within the file need to reference variable-length strings | String-table format |
Chunk data stores a sequence of strings, some of which the application may want to skip | BZSTR (NULL-terminated string with byte size prefix) series |
Chunk data contains multiline strings | A multiline string format |