Splitted StringEntity class and definition functions
This commit is contained in:
parent
8f2d2bcf48
commit
5030d85b98
33
src/app/StringEntity.cpp
Normal file
33
src/app/StringEntity.cpp
Normal 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
35
src/app/definition.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user