# Написание калькулятора с разбором выражений, страница 9

{

if (OutText.text[i] == '\r')

while (OutText.text[i++ + 1] == ' ')

;

while (OutText.text[i] == ' ')

i++;

if (i < OutText.length)

if (!IsPriority (OutText.text [i]))

{

result = (char*)realloc (result, pos + 1);

if (SPACE)

{

result [pos++] = ' ';

result = (char*)realloc (result, pos + 1);

}

while (OutText.text [i] != ' ' && i < OutText.length)

{

result [pos++] = OutText.text [i++];

result = (char*)realloc (result, pos + 1);

}

}

else

{

result = (char*)realloc (result, pos + 1);

result[pos++] = OutText.text[i++];

}

SPACE = false;

if (isalpha (result [pos-1]) || isdigit (result [pos-1]))

SPACE = true;

}

free (OutText.text);

OutText.text = result;

OutText.length = pos;

}

/* END OF 'ReduceSumbol' METHOD */

/* THIS METHOD CREATE SINGLE LINE FROM ORIGINAL TEXT */

void DeleteLines (void)

{

char *result = (char*) malloc (0);

int pos = 0, i = 0;

while (i < OutText.length)

{

if (OutText.text[i] != 10 && OutText.text[i] != 13)

{

result = (char*)realloc (result, pos + 1);

result[pos] = OutText.text[i];

pos++;

i++;

}

else

i++;

}

result [pos] = '\0';

free (OutText.text);

OutText.text = result;

OutText.length = pos;

}

/* END OF 'DeleteSymbols' METHOD */

/* THIS METHOD CONVERTS CString TO char* */

char* ConvertCStringToChar (CString S)

{

char *RES;

int len = S.GetLength ();

int i;

BSTR str = S.AllocSysString ();

RES = (char*)malloc (len);

for (i = 0; i <= len; i++)

RES[i] = (char)str[i];

return RES;

}

/* END OF 'ConvertCStringToChar' METHOD */

/********************************************************************

END OF PRIVATE MEMBERS DEFINITIONS

********************************************************************/

/********************************************************************

PUBLIC MEMBERS DEFINITIONS

********************************************************************/

public:

ITextFormatter ()

{

BuildedText = false;

POSITION = 0;

}

~ITextFormatter ()

{

}

public:

//

/* THIS METHOD SET TEXT FOR BUILDING*/

void SetText (CString CS)

{

FirstText.length = CS.GetLength ();

FirstText.text = (char*)malloc (FirstText.length);

memmove (FirstText.text, ConvertCStringToChar (CS), FirstText.length);

BuildedText = false;

}

/* END OF 'SetText' METHOD */

/* THIS IS OVERLOAD OF 'SetText' METHOD */

void SetText (char *text)

{

FirstText.length = (int)strlen (text);

FirstText.text = (char*)malloc (FirstText.length);

memmove (FirstText.text, text, FirstText.length);

BuildedText = false;