From e74cf22c717e722ce27c3770d8b2c778460a6a0a Mon Sep 17 00:00:00 2001 From: anschrammh Date: Tue, 7 Jan 2020 12:20:10 +0100 Subject: [PATCH] Added the setString method to the string entity object --- src/app/Dictionary.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/app/Dictionary.h b/src/app/Dictionary.h index 45436e5..c72cd0e 100644 --- a/src/app/Dictionary.h +++ b/src/app/Dictionary.h @@ -34,7 +34,22 @@ namespace DictionaryHelper strcpy(_string, Object._string); } ~StringEntity(){free(_string);} - char *getString(){return _string;} + const char *getString(){return _string;} + void setString(const char *string = NULL) + { + free(_string);_string = NULL; + + if(string == NULL) + { + _string = (char *) malloc((sizeof(char))); + _string[0] = '\0'; + } + else + { + _string = (char *) malloc((strlen(string) * sizeof(char)) + 1); //+1 for the string terminating character + strcpy(_string, string); + } + } Dictionary *split(char character); private: char *_string;