예제 #1
0
파일: Markup.cpp 프로젝트: kamilWLca/brix
INXString CMarkup::x_TextToDoc( char* szText, bool bAttrib ) const
{
    // Convert text as seen outside XML document to XML friendly
    // replacing special characters with ampersand escape codes
    // E.g. convert "6>7" to "6>7"
    //
    // <   less than
    // &  ampersand
    // >   greater than
    //
    // and for attributes:
    //
    // ' apostrophe or single quote
    // " double quote
    //
    static char* szaReplace[] = { "<", "&", ">", "'", """};
    const char* pFind = bAttrib? "<&>\'\"":"<&>";
    INXString csText;
    const char* pSource = szText;
    int nDestSize = strlen(pSource);
    nDestSize += nDestSize / 10 + 7;
    char* pDest = csText.GetBuffer(nDestSize);
    int nLen = 0;
    char cSource = *pSource;
    char* pFound;
    while ( cSource )
    {
        if ( nLen > nDestSize - 6 )
        {
            csText.ReleaseBuffer(nLen);
            nDestSize *= 2;
            pDest = csText.GetBuffer(nDestSize);
        }
        if ( (pFound=(char*)strchr(pFind,cSource)) != NULL )
        {
            pFound = szaReplace[pFound-pFind];
            strcpy(&pDest[nLen],pFound);
            nLen += strlen(pFound);
        }
        else
        {
            _tccpy( &pDest[nLen], pSource );
            nLen += _tclen( pSource );
        }
        pSource += _tclen( pSource );
        cSource = *pSource;
    }
    csText.ReleaseBuffer(nLen);
    return csText;
}
예제 #2
0
파일: Markup.cpp 프로젝트: kamilWLca/brix
INXString CMarkup::x_TextFromDoc( int nLeft, int nRight ) const
{
    // Convert XML friendly text to text as seen outside XML document
    // ampersand escape codes replaced with special characters e.g. convert "6&gt;7" to "6>7"
    // Conveniently the result is always the same or shorter in byte length
    //
    static char* szaCode[] = { "lt;","amp;", "gt;", "apos;", "quot;" };
    static int anCodeLen[] = { 3,4,3,5,5 };
    static char* szSymbol = "<&>\'\"";
    INXString csText;
    const char* pSource = (const char*)m_csDoc;
    int nDestSize = nRight - nLeft + 1;
    char* pDest = csText.GetBuffer(nDestSize);
    //LPTSTR pDest = csText.GetBuffer(nDestSize);
    int nLen = 0;
    int nCharLen = 0;
    int nChar = nLeft;
    while ( nChar <= nRight )
    {
        if ( pSource[nChar] == '&')
        {
            // Look for matching &code;
            bool bCodeConverted = false;
            for ( int nMatch = 0; nMatch < 5; ++nMatch )
            {
                if ( nChar <= nRight - anCodeLen[nMatch]
                        && strncmp(szaCode[nMatch],&pSource[nChar+1],anCodeLen[nMatch]) == 0 )
                {
                    // Insert symbol and increment index past ampersand semi-colon
                    pDest[nLen++] = szSymbol[nMatch];
                    nChar += anCodeLen[nMatch] + 1;
                    bCodeConverted = true;
                    break;
                }
            }

            // If the code is not converted, leave it as is
            if ( ! bCodeConverted )
            {
                pDest[nLen++] = _T('&');
                ++nChar;
            }
        }
        else // not &
        {
            nCharLen = _tclen(&pSource[nChar]);
            _tccpy( &pDest[nLen], &pSource[nChar] );
            nLen += nCharLen;
            nChar += nCharLen;
        }
    }
    csText.ReleaseBuffer(nLen);
    return csText;
}
예제 #3
0
void Encapsulate::OnOK() 
{
	bool errorFlag = FALSE;
	INXString strText = "";
	UINT i;
	
	// update attributes such as m_BlockName
	UpdateData(TRUE);
	//get the text from the textboxes
	for (i=1; i<=inNum; i++) {
		strText = "";
		int len = inEdit[i]->LineLength(inEdit[i]->LineIndex(0));
		if (len) {
			inEdit[i]->GetLine(0, strText.GetBuffer(len), len);
			strText.ReleaseBuffer(len);
		}
		INXString x(strText.MakeLower());
		inNames[i] = strText.MakeLower();
	}
	for (i=1; i<=outNum; i++) {
		strText = "";
		int len = outEdit[i]->LineLength(outEdit[i]->LineIndex(0));
		if (len) {
			outEdit[i]->GetLine(0, strText.GetBuffer(len), len);
			strText.ReleaseBuffer(len);
		}
		outNames[i] = (INXString)strText.MakeLower();
	}
	for (i=1; i<=startNum; i++) {
		strText = "";
		int len = startEdit[i]->LineLength(startEdit[i]->LineIndex(0));
		if (len) {
			startEdit[i]->GetLine(0, strText.GetBuffer(len), len);
			strText.ReleaseBuffer(len);
		}
		startNames[i] = strText.MakeLower();
	}
	for (i=1; i<=finishNum; i++) {
		strText = "";
		int len = finishEdit[i]->LineLength(finishEdit[i]->LineIndex(0));
		if (len) {
			finishEdit[i]->GetLine(0, strText.GetBuffer(len), len);
			strText.ReleaseBuffer(len);
		}
		finishNames[i] = strText.MakeLower();
	}

	// Check port names are not empty strings and are unique
	for (i=1; i<=inNum; i++) {
		// check port names
		if (inNames[i] == "") {
			AfxMessageBox("WARNING: Enter a port name for " + inLabels[i]);
			errorFlag = TRUE;
		}
		for (UINT j=1; j<=inNum; j++) {
			if (i!=j && inNames[i] == inNames[j]) {
				AfxMessageBox("WARNING: " + inLabels[i] + " is not unique.");
				errorFlag = TRUE;
			}
		}
	}
			
	if (!errorFlag) {
		for (i=1; i<=outNum; i++) {
			// check port names
			if (outNames[i] == "") {
				AfxMessageBox("WARNING: Enter a port name for " + outLabels[i]);
				errorFlag = TRUE;
			}
			for (UINT j=1; j<=outNum; j++) {
				if (i!=j && outNames[i] == outNames[j]) {
					AfxMessageBox("WARNING: " + outLabels[i] + " is not unique.");
					errorFlag = TRUE;					
				}
			}
		}
	}
			
	if (!errorFlag) {
		for (i=1; i<=startNum; i++) {
			// check port names
			if (startNames[i] == "") {
				AfxMessageBox("WARNING: Enter a port name for " + startLabels[i]);					
				errorFlag = TRUE;
			}
			for (UINT j=1; j<=startNum; j++) {
				if (i!=j && startNames[i] == startNames[j]) {
					AfxMessageBox("WARNING: " + startLabels[i] + " is not unique.");
					errorFlag = TRUE;
				}
			}
		}
	}
			
	if (!errorFlag) {
		for (i=1; i<=finishNum; i++) {
			// check port names
			if (finishNames[i] == "") {
				AfxMessageBox("WARNING: Enter a port name for " + finishLabels[i]);
				errorFlag = TRUE;
			}
			for (UINT j=1; j<=finishNum; j++) {
				if (i!=j && finishNames[i] == finishNames[j]) {
					AfxMessageBox("WARNING: " + finishLabels[i] + " is not unique.");
					errorFlag = TRUE;
				}
			}
		}
	}

	
	if (!errorFlag) {
		CDialog::OnOK();
	}
}