C4 Engine
C4 Engine API Documentation


Defined in:  TSData.h
Reads an identifier from a text string.

DataResult ReadIdentifier(const char *text, int32 *textLength);

DataResult ReadIdentifier(const char *text, int32 *textLength, char *restrict identifier);

text A pointer to a text string.
textLength A pointer to the location that receives the length of the identifier.
identifier A pointer to a buffer that will receive the identifier string. If this is omitted, then the identifier string itself is not returned.
The ReadIdentifier function reads an identifier from the text string specified by the text parameter and returns the number of characters that were read in the location specified by the textLength parameter.

An identifier is made up of a sequence of consecutive characters from the set {A-Z, a-z, 0-9, _}, that is, all uppercase and lowercase letters, all numbers, and the underscore. An identifier may not begin with a number.

If no error occurs, then the return value is kDataOkay. Otherwise, the ReadIdentifier function returns kDataIdentifierEmpty if there are no characters in the identifier or kDataIdentifierIllegalChar if an illegal character is encountered (or if the first character is a number). The return value depends only upon the contents of the text string.

If the identifier parameter is not nullptr, then the characters composing the identifier are copied into the buffer that it points to, and a zero byte terminator is added to the end. The ReadIdentifier function can be called with the identifier parameter set to nullptr to determine the length of the identifier, and then it can be called a second time after allocating a buffer of the necessary size to actually read the identifier. Note that the returned length does not include the zero byte terminator, so any buffer allocated should be one byte larger than the returned length.
See Also