Exemple #1
0
void CJSONWriter::Text(const CFSAString &szStr) {
	for (INTPTR ip=0; ip<szStr.GetLength(); ip++) {
		if (szStr[ip]=='\\') m_Stream.WriteText("\\\\");
		else if (szStr[ip]=='\"') m_Stream.WriteText("\\\"");
		else if (szStr[ip]=='\n') m_Stream.WriteText("\\n");
		else if (szStr[ip]=='\r') m_Stream.WriteText("\\r");
		else if (szStr[ip]=='\t') m_Stream.WriteText("\\t");
		else if (szStr[ip]=='\b') m_Stream.WriteText("\\b");
		else if (szStr[ip]=='\f') m_Stream.WriteText("\\f");
		else m_Stream.WriteChar(szStr[ip]);
	}
}
Exemple #2
0
void CONV_HTML_UC2::ConvToUc(
    CFSWString& wStr,
    const CFSAString& aStr,
    const PFSCODEPAGE koodiTabel
)
{
    wStr.Empty();
    if(koodiTabel!=PFSCP_HTMLEXT) // Krutime Renee algoritmi j�rgi
    {
        wStr = FSStrAtoW(aStr, koodiTabel); // Kui teisendus k�ib Rene tabelite j�rgi, siis teeme �ra ja valmis
        return;
    }
    assert(koodiTabel==PFSCP_HTMLEXT); // Kasutame teisendamiseks failist loetud tabelit
    if(sgml2uc.idxLast<=0)
        throw VEAD(ERR_X_TYKK, ERR_ARGVAL, __FILE__,__LINE__, "$Revision: 557 $",
                   "SGML olemite tabel mallu lugemata");
    int l, n=aStr.GetLength();
    for(l=0; l < n; l++)
    {
        if((aStr[l] & (~0x7F))!=0) // peab olema 7bitine ascii
            throw VEAD(ERR_X_TYKK, ERR_ARGVAL, __FILE__,__LINE__, "$Revision: 557 $",
                       "String peab koosnema ASCII (7bitistest) koodidest", (const char*)aStr+l);
        if(aStr[l]!='&') // ei alusta SGML olemit...
        {
tryki:
            wStr += ((FSWCHAR)(aStr[l])) & 0x7F; // ...l�heb niisama
            continue;
        }
        // V�ib alustada mingit SGML olemit - &blah;
        int lSemiPos=(int)aStr.Find(";", l+1);
        if(lSemiPos<0) // see ampersand ilma l�petava semita
        {
            if(ignoramp==true)
                goto tryki;
            throw VEAD(ERR_X_TYKK, ERR_ARGVAL, __FILE__,__LINE__, "$Revision: 557 $",
                       "Ampersandi tagant semi puudu", (const char*)aStr+l);
        }
        if(autosgml==true && aStr[l+1]=='#') // teisenda &#[{x|X}]12345; s�mbolid
        {
            int tmp=0, j=l+2;
            if(aStr[j]=='x' || aStr[j]=='X')    // teisenda &#x12345; ja &#X12345; hexakoodid
            {
                j++;
                //if(sscanf(((const char*)aStr)+j, "%x", &tmp)!=1)
                //        throw VEAD(ERR_X_TYKK, ERR_ARGVAL, __FILE__,__LINE__, "$Revision: 557 $",
                //                    "Vigane SGML olem", (const char*)aStr+l);
                //for(; j<lSemiPos; j++)
                //    {
                //    if(strchr("0123456789aAbBcCdDeEfF", aStr[j])==NULL)
                //       throw VEAD(ERR_X_TYKK, ERR_ARGVAL, __FILE__,__LINE__, "$Revision: 557 $",
                //                    "Vigane SGML olem", (const char*)aStr+l);
                //    }
                j+=STRSOUP::UnsignedStr2Hex<int, char>(&tmp, ((const char*)aStr)+j);
                if(j<=0 || aStr[j]!=';')
                    throw VEAD(ERR_X_TYKK, ERR_ARGVAL, __FILE__,__LINE__, "$Revision: 557 $",
                               "Vigane SGML olem", (const char*)aStr+l);
                if(tmp>0xFFFF)
                    throw VEAD(ERR_X_TYKK, ERR_ARGVAL, __FILE__,__LINE__, "$Revision: 557 $",
                               "Vigane SGML olem (peab mahtuma 2 baidi peale)", (const char*)aStr+l);
            }
            else                                // teisenda &#12345; ja &#12345; k�mnendkoodid
            {
                //for(; j<lSemiPos; j++)
                //    {
                //    if(aStr[j]<'0' || aStr[j]>'9')
                //        throw VEAD(ERR_X_TYKK, ERR_ARGVAL, __FILE__,__LINE__, "$Revision: 557 $",
                //                    "Vigane SGML olem (lubatud 0-9)", (const char*)aStr+l);
                //    if((tmp=10*tmp+aStr[j]-'0')>0xFFFF)
                //        throw VEAD(ERR_X_TYKK, ERR_ARGVAL, __FILE__,__LINE__, "$Revision: 557 $",
                //                    "Vigane SGML olem (peab mahtuma 2 baidi peale)", (const char*)aStr+l);
                //    }
                j+=STRSOUP::UnsignedStr2Num<int, char>(&tmp, ((const char*)aStr)+j);
                if(j<=0 || aStr[j]!=';')
                    throw VEAD(ERR_X_TYKK, ERR_ARGVAL, __FILE__,__LINE__, "$Revision: 557 $",
                               "Vigane SGML olem", (const char*)aStr+l);
                if(tmp>0xFFFF)
                    throw VEAD(ERR_X_TYKK, ERR_ARGVAL, __FILE__,__LINE__, "$Revision: 557 $",
                               "Vigane SGML olem (peab mahtuma 2 baidi peale)", (const char*)aStr+l);
            }
            wStr += (WCHAR)tmp;
            l=lSemiPos;
            continue;
        }
        if(lSemiPos-l+1 > sgml_stringi_max_pikkus) // nii pikk ei saa olla tabelis
        {
            if(ignoramp==true)
                goto tryki;
            throw VEAD(ERR_X_TYKK, ERR_ARGVAL, __FILE__,__LINE__, "$Revision: 557 $",
                       "Puudub SGML olemite tabelist", (const char*)aStr+l);
        }
        CFSAString szSymbol=aStr.Mid(l, lSemiPos-l+1); // l�ikame &bla; sisendstringist v�lja
        SGML_UC* rec;
        if((rec=sgml2uc.Get(&szSymbol))==NULL) // ei leidnud kahendtabelist - jama lahti
        {
            if(ignoramp==true)
                goto tryki;
            throw VEAD(ERR_X_TYKK, ERR_ARGVAL, __FILE__,__LINE__, "$Revision: 557 $",
                       "Puudub SGML olemite tabelist", (const char*)szSymbol);
        }
        wStr += rec->uc;
        l=lSemiPos;
    }
}
Exemple #3
0
void CONV_HTML_UC2::ConvFromUc(
    CFSAString& aStr,
    const PFSCODEPAGE koodiTabel,
    const CFSWString& wStr
)
{
    aStr.Empty();
    if(koodiTabel!=PFSCP_HTMLEXT) // Krutime Renee algoritmi j�rgi
    {
        aStr = FSStrWtoA(wStr, koodiTabel); // Kui teisendus k�ib Rene tabelite j�rgi, siis teeme �ra ja valmis
        return;
    }
    assert(koodiTabel==PFSCP_HTMLEXT); // Kasutame teisendamiseks failist loetud tabelit
    if(sgml2uc.idxLast<=0)
        throw VEAD(ERR_X_TYKK, ERR_ARGVAL, __FILE__,__LINE__, "$Revision: 557 $",
                   "SGML olemite tabel mallu lugemata");
    FSWCHAR wc;
    for(int i=0; (wc=wStr[i])!=0; i++)
    {
        if((wc & (~0x7F))==0) // Oli ASCII (7bitine) kood
        {
            if(ignoramp==false && wc==(FSWCHAR)'&') // Ampersand SGML olemiks
                aStr += "&amp;";
            else
                aStr += (char)(wc & 0x7F); // Muud ASCII koodid niisama �le
            continue;
        }
        // Polnud ASCII kood, peab olema  SGML olemite loendis
        SGML_UC* rec;
        if((rec=uc2sgml.Get((const FSWCHAR*)wStr+i))!=NULL) // leidsime loendist
        {
            aStr += rec->sgml;
            continue;
        }
        int olemiAlgusPos=aStr.GetLength();
        aStr+="&#";
        STRSOUP::UnsignedNum2Str<int, CFSAString, char, 10>((unsigned int)(wStr[i]), aStr);
        aStr+=';';
        if(autosgml==false)
        {
            throw VEAD(ERR_X_TYKK, ERR_ARGVAL, __FILE__,__LINE__, "$Revision: 557 $",
                       "UniCode'i kood programmi SGML olemite tabelist puudu, 10ndkood",
                       (const char*)aStr+olemiAlgusPos);
        }
        /*
        if(autosgml==false)
            {
            char tmpBuf[128];
            sprintf(tmpBuf, "%d", (unsigned int)(wStr[i]));
            throw VEAD(ERR_X_TYKK, ERR_ARGVAL, __FILE__,__LINE__, "$Revision: 557 $",
                        "UniCode s�mbol programmi SGML olemite tabelist puudu, kood", tmpBuf);
            }
        //autosgml==true;
        CFSAString revSgml;
        int j=-1;
        assert(wc > 0);
        do
            {
            revSgml[++j] = (unsigned)(wc%10)+(unsigned)'0';
            wc /= 10;
            } while(wc > 0);
        aStr += "&#";
        while(j>=0)
            aStr+=revSgml[j--];
        aStr += ';';
        */
    }
}
Exemple #4
0
void CJSONWriter::Text(const CFSAString &szStr) {
	for (INTPTR ip=0; ip<szStr.GetLength(); ip++) {
		if (szStr[ip]=='\"') m_Stream.WriteChar('\\');
		m_Stream.WriteChar(szStr[ip]);
	}
}