Added the setString method to the string entity object

This commit is contained in:
anschrammh 2020-01-07 12:20:10 +01:00
parent 78231e9228
commit e74cf22c71

View File

@ -34,7 +34,22 @@ namespace DictionaryHelper
strcpy(_string, Object._string); strcpy(_string, Object._string);
} }
~StringEntity(){free(_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<StringEntity> *split(char character); Dictionary<StringEntity> *split(char character);
private: private:
char *_string; char *_string;