12#include "helpers/formatstring.h"
31 if (s != NULL && decoration != NULL)
54 return _Decorate(s,
"\x1b[31m%s\x1b[39m");
67 return _Decorate(s,
"\x1b[47m%s\x1b[49m");
99 printf(
"\nDecorator_Exercise\n");
101 const char* text =
"This is raw text";
111 printf(
" Base Text element: \"%s\"\n", text);
112 printf(
" Decorated element: \"%s\"\n", rendering->
string);
DynamicString * UnderlineDecorator(DynamicString *s)
Represents the Underline decorator, which alters the wrapped content to render it as underlined.
DynamicString * RedForegroundDecorator(DynamicString *s)
Represents the RedForeground decorator, which alters the wrapped content to render as red text.
DynamicString * WhiteBackgroundDecorator(DynamicString *s)
Represents the WhiteBackground decorator, which alters the wrapped content to render the background c...
void Decorator_Exercise(void)
Example of using the Decorator Pattern.
DynamicString * _Decorate(DynamicString *s, const char *decoration)
Helper function for applying decorations to the given string.
Declaration of the Decorator_Exercise() function as used in the Decorator Pattern.
void DynamicString_Clear(DynamicString *string)
Clear a DynamicString object, releasing any allocated memory. Resets to an empty string.
void DynamicString_Initialize(DynamicString *string)
Initialize a DynamicString object to an empty string.
bool DynamicString_Set(DynamicString *string, const char *s)
Set the DynamicString object to the specified string, replacing whatever is in the DynamicString obje...
Declaration of the DynamicString structure and supporting functions to work with dynamic strings.
Represents a string that can be grown dynamically.
char * string
The string that can grow.