// ---------------------------------------------------------------------------
// CSdpCodecParseUtil::ParseMediaLevelL
// ---------------------------------------------------------------------------
//
RPointerArray<CSdpMediaField>*
CSdpCodecParseUtil::ParseMediaLevelL()
{
    RStringF headername = iPool.StringF( SdpCodecStringConstants::EMedia,
                                         SdpCodecStringConstants::Table );
    TInt linestartPosition = 0;
    TInt lineEndPosition = 0;
    CSdpMediaField* mediafield = NULL;
    TBool endloop = EFalse;
    while(iData.Length() > 0 && !endloop)
    {
        linestartPosition = iData.FindF(headername.DesC());
        if(linestartPosition != KErrNotFound)
        {
            TPtrC8 firstline(iData.Mid(linestartPosition));
            TPtrC8 templine(iData.Mid(linestartPosition + 1));
            HBufC8* searchString =
                HBufC8::NewLC(KCRLFStr().Length() +
                              headername.DesC().Length());
            TPtr8 strPtr(searchString->Des());
            strPtr.Append(KCRLFStr);
            strPtr.Append(headername.DesC());
            lineEndPosition = templine.FindF(strPtr);
            CleanupStack::PopAndDestroy(searchString);
            if(lineEndPosition == KErrNotFound)
            {
                mediafield =
                    CSdpMediaField::DecodeLC(iData.Mid(linestartPosition));
                User::LeaveIfError(iMediaFields->Append(mediafield));
                CleanupStack::Pop();//mediafield
                mediafield = 0;
                iElementArray.Reset();
                iLineArray.Reset();
                endloop = ETrue;
            }
            else
            {
                mediafield =
                    CSdpMediaField::DecodeLC(firstline.Left(
                                                 lineEndPosition+1+KCRLFStr().Length()));
                User::LeaveIfError(iMediaFields->Append(mediafield));
                CleanupStack::Pop();//mediafield
                mediafield = 0;
                iData.Set(firstline.Mid(lineEndPosition+1));
            }
        }
        else
        {
            endloop = ETrue;
        }
    }
    RPointerArray<CSdpMediaField>* array = iMediaFields;
    iMediaFields = 0;
    return array;
}
void Translator::toElvish(char translatedLine[], const char lineToTranslate[]) const
{
    if(strlen(lineToTranslate) == 0)
    {
        strcpy(translatedLine, lineToTranslate);
        return;
    }

	std::string templine(lineToTranslate); //Initialise a temp line with the char array of line to change
	std::string tempword, translatedsen, translatedword, lastletter; //have a tempword and a string to put it in
	int startpos = 0, endpos, j, linesize = templine.size();//positions and vector/array sizes
	bool noendspace = false, iscapbool = false, translationbool = false;
	int firstletternum, lastletternum;

    if(templine.find_last_of(" .,'\"?!;") != templine.size() - 1)
    {
        templine.append(" ");
        noendspace = true;
    }

	while(startpos != linesize)//loop until the startposition = the linesize
    {
        translationbool = false;
        if(templine.find_first_of(" .,'\"?!;", startpos) == -1)
            break;
        else if(templine.find_first_of(" .,'\"?!;", startpos) == startpos)
        {
            translatedsen += templine.at(startpos);
            startpos++;
            continue;
        }


        endpos = templine.find_first_of(" .,'\"?!;", startpos);//find a space,comma, fulstop

        tempword = templine.substr(startpos,endpos - startpos);
		if(tempword.at(0) == '-')
		{
			translatedsen += "*" + tempword + "* ";
			startpos = endpos + 1 ;
			continue;
		}

        if(tempword.at(0) >= 'A' && tempword.at(0) <= 'Z')//IF THE CAPTURED WORD STARTS WITH A CAP
        {
            tempword.at(0) = tempword.at(0) + 32;
            iscapbool = true;
        }

        transform(tempword.begin(), tempword.end(), tempword.begin(), ::tolower);
        lastletter = templine.at(endpos);
        firstletternum = tempword.at(0) - 'a';
        lastletternum = tempword.at(tempword.size() -1) - 'a';

        for(j = 0; j < engword_eng[firstletternum][lastletternum].size()
	      && engword_eng[firstletternum][lastletternum].size() != 0
	      && firstletternum >= 0 && lastletternum >= 0; j++)
        {
            if(tempword.compare(engword_eng[firstletternum][lastletternum][j]) == 0)//TRANSLATE
            {
                translationbool = true;
                if(iscapbool)//IF IT STARTS WITH A CAP
                {
                    translatedword = elfword_eng[firstletternum][lastletternum][j];
                    translatedword.at(0) = translatedword.at(0) - 32;
                    translatedsen.append(translatedword);
                    iscapbool = false;
                }
                else// NO CAP DO THIS
                    {
                        translatedsen.append(elfword_eng[firstletternum][lastletternum][j]);
                    }
                break;
            }
        }

        if(!translationbool)
        {
            if(iscapbool)
            {
                    tempword.at(0) = tempword.at(0) - 32;
                    iscapbool = false;
            }
            translatedsen += "*" + tempword + "*";
        }


        translatedsen += lastletter;
        startpos = endpos + 1 ;
    }

    if(noendspace)
    {
        translatedsen.resize(translatedsen.size() - 1);
    }

    for (int i=0;i< translatedsen.size();i++)
        {
            translatedLine[i]= translatedsen[i];
        }
    translatedLine[translatedsen.size()] = '\0';
}