Splitted StringEntity class and definition functions

This commit is contained in:
anschrammh 2019-04-09 07:57:55 +02:00
parent 8f2d2bcf48
commit 5030d85b98
2 changed files with 68 additions and 0 deletions

33
src/app/StringEntity.cpp Normal file
View File

@ -0,0 +1,33 @@
#include "Dictionary.h"
#include "definition.h"
Dictionary<DictionaryHelper::StringEntity> *DictionaryHelper::StringEntity::split(char character)
{
Dictionary<DictionaryHelper::StringEntity> *ref = NULL;
unsigned int i(0), counter(0);
char *parseBuffer(NULL);
if(_string == NULL)return NULL;
ref = new Dictionary<StringEntity>();
while(_string[i] != '\0')
{
if(_string[i] == character)
{
ref->add(counter++, parseBuffer);
free(parseBuffer);parseBuffer = NULL;
}
else
{
parseBuffer = addChar(parseBuffer, _string[i]);
}
i++;
}
ref->add(counter++,parseBuffer);
free(parseBuffer);parseBuffer = NULL;
return ref;
}

35
src/app/definition.cpp Normal file
View File

@ -0,0 +1,35 @@
#include "definition.h"
char *addChar(char *pointer, const char character)
{
char *tempAddr = NULL;
if(pointer == NULL)
{
tempAddr = (char *) realloc(pointer, 2*sizeof(char));
if(tempAddr == NULL)
return NULL;
else
{
pointer = tempAddr;
pointer[0] = character;
pointer[1] = '\0';
}
}
else
{
tempAddr = (char *) realloc(pointer, (strlen(pointer)+2)*sizeof(char));
if(tempAddr == NULL)
{
free(pointer);
return NULL;
}
else
{
pointer = tempAddr;
pointer[strlen(pointer)+1] = '\0';
pointer[strlen(pointer)] = character;
}
}
return pointer;
}