12#include "helpers/titlecase.h"
74 const char* tokenAsString =
"";
78 if (token >= 0 && token < numCommonWords)
96 static char buffer[32] = { 0 };
97 int num_chars = snprintf(buffer,
sizeof(buffer),
"<UNKNOWN TOKEN %d>", token);
101 tokenAsString = buffer;
105 int errorCode = errno;
106 printf(
" Error(%d)! snprintf() failed: %s", errorCode, strerror(errorCode));
110 return tokenAsString;
119 bool success =
false;
121 if (tokenList != NULL && output != NULL)
124 for (
size_t tokenIndex = 0; tokenList[tokenIndex] !=
EOL; ++tokenIndex)
127 char* titleString = NULL;
132 if (titleString == NULL)
134 printf(
" Error! titlecase() in Interpreter_Interpret() encountered an out of memory condition!\n");
138 tokenAsString = titleString;
146 if (tokenList[tokenIndex + 2] !=
EOL)
152 printf(
" Error! Out of memory condition adding space separator to output in Interpreter_Interpret()!\n");
159 printf(
" Error! Out of memory condition adding token to output in Interpreter_Interpret()!\n");
static const char * _commonwords[]
The 40 most common words in English (in order but that doesn't really matter here)....
static const char * _InterpretToken(int token)
Helper function to convert the token into its corresponding word or punctuation mark.
bool Interpreter_Interpret(const int *tokenList, DynamicString *output)
This function is a simple interpreter.
Declaration of the Interpreter_Interpret() function used in the Interpreter Pattern.
@ EOL
Marker for end of a token list.
bool DynamicString_Append(DynamicString *string, const char *s)
Append the specified string to the DynamicString object.
Represents a string that can be grown dynamically.
char * titlecase(const char *s)
Convert the first word (or only word) in the given string to lowercase then make the first letter upp...