Esempio n. 1
0
void CMarkup::x_DocChange( int nLeft, int nReplace, const INXString& csInsert )
{
    // Insert csInsert int m_csDoc at nLeft replacing nReplace chars
    // Do this with only one buffer reallocation if it grows
    //
    int nDocLength = m_csDoc.GetLength();
    int nInsLength = csInsert.GetLength();

    // Make sure nLeft and nReplace are within bounds
    nLeft = max( 0, min( nLeft, nDocLength ) );
    nReplace = max( 0, min( nReplace, nDocLength-nLeft ) );

    // Get pointer to buffer with enough room
    int nNewLength = nInsLength + nDocLength - nReplace;
    int nBufferLen = nNewLength;
    char* pDoc = m_csDoc.GetBuffer( nBufferLen );

    // Move part of old doc that goes after insert
    if ( nLeft+nReplace < nDocLength )
        memmove( &pDoc[nLeft+nInsLength], &pDoc[nLeft+nReplace], (nDocLength-nLeft-nReplace)*sizeof(char) );

    // Copy insert
    //const char* tempChar = csInsert;
    memcpy( &pDoc[nLeft], (const char*)csInsert, nInsLength*sizeof(char));

    // Release
    m_csDoc.ReleaseBuffer( nNewLength );
}
Esempio n. 2
0
int parseLines( INXString &csTextBlock, std::list<INXString> &rLines )
{

	// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	// Split-up the received text into new-line terminated pieces.
	// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

	// 1st of all, chop-off any \n's at the beginning of the string, as these are effectively 0-length
	// lines, which are not worth processing further.

	rLines.clear();

	int charPos = csTextBlock.Find('\n');
	int len = csTextBlock.GetLength();
	while(charPos == 0){
		csTextBlock = csTextBlock.Right(len-1);
		charPos = csTextBlock.Find('\n');
		len = csTextBlock.GetLength();
	}


	charPos = csTextBlock.Find('\n');
	len = csTextBlock.GetLength();

	if ( charPos == -1 ) {
		// There is no '\n' at all.  Treat the string as just one line.
		rLines.push_back(csTextBlock);
		csTextBlock = "";

	} else {

		while( charPos != -1 ){

			// The \n is in the middle somewhere - get the left-most substring
			rLines.push_back(csTextBlock.Left(charPos+1) );
			csTextBlock = csTextBlock.Right(csTextBlock.GetLength() - 1 - charPos);

			charPos = csTextBlock.Find('\n');
			len = csTextBlock.GetLength();

		} // while( charPos != -1 )

	} // if(charPos != -1)

	len = csTextBlock.GetLength();

	if ( csTextBlock.GetLength() > 0 ) {
		// Pushthe last non- \n terminated string
		rLines.push_back(csTextBlock);
		csTextBlock = "";

	}
	return rLines.size();

}
Esempio n. 3
0
INXString cloneBackSlashes( const INXString &csText )
{
	INXString csRetval = "";

	for(int i=0;i<csText.GetLength();i++)
	{
		csRetval.AppendChar(((INXString)csText)[i] );
		if( ((INXString)csText)[i] == '\\'){
			csRetval.AppendChar( '\\' );
		}
	}
	return csRetval;
}
Esempio n. 4
0
bool CMarkup::x_SetAttrib( int iPos, char* szAttrib, char* szValue )
{
    // Set attribute in iPos element
    TokenPos token( m_csDoc );
    int nInsertAt;
    if ( iPos && m_nNodeType == MNT_ELEMENT )
    {
        token.nNext = m_aPos[iPos].nStartL + 1;
        nInsertAt = m_aPos[iPos].nStartR - (m_aPos[iPos].IsEmptyElement()?1:0);
    }
    else
        return false;

    // Create insertion text depending on whether attribute already exists
    int nReplace = 0;
    INXString csInsert;
    if ( x_FindAttrib( token, szAttrib ) )
    {
        // Replace value only
        // Decision: for empty value leaving attrib="" instead of removing attrib
        csInsert = x_TextToDoc( szValue, true );
        nInsertAt = token.nL;
        nReplace = token.nR-token.nL+1;
    }
    else
    {
        // Insert string name value pair
        INXString csFormat(" ");
        csFormat += (wxChar*)szAttrib;
        csFormat += _T("=\"");
        csFormat += x_TextToDoc( szValue, true );
        csFormat += _T("\"");
        csInsert = csFormat;
    }

    x_DocChange( nInsertAt, nReplace, csInsert );
    int nAdjust = csInsert.GetLength() - nReplace;
    m_aPos[iPos].nStartR += nAdjust;
    m_aPos[iPos].AdjustEnd( nAdjust );
    x_Adjust( iPos, nAdjust );
    MARKUP_SETDEBUGSTATE;
    return true;
}
Esempio n. 5
0
DBTIMESTAMP parseTimeStamp( INXString &cs )
{
	DBTIMESTAMP ts ;
	memset( &ts, 0, sizeof(DBTIMESTAMP) ); 

	INXString cs2;
    const size_t newsize = 100;
    char buff[newsize];
int i;
	for(i=0;i<cs.GetLength();i++)
		buff[i] = (char) cs.GetAt(i);

	buff[i+1] = '\0';

	sscanf_s( buff,
		//(char *)lptStr, 
		//dum,
		"%4d-%2d-%2d %2d:%2d:%2d:%9d", 
		&ts.year, &ts.month, &ts.day, &ts.hour, &ts.minute, &ts.second, &ts.fraction );

	return ts;
}
Esempio n. 6
0
void parseSodlWidgetData( const INXString &fileLine, INXString &widgetTag, INXString &targetFileName )
{

	// A GUI tag is preceded by %%%_ which needs to be removed from the GUI file
	widgetTag = fileLine;
	widgetTag.Delete(0, 4);
	// Now that the %%%_ has gone, store value for target file name also.
	targetFileName = widgetTag;

	// where is space between widget tag and target file name
	int posnOfSeparatorSpace = widgetTag.Find(INXString(" "));

	// get the characters of the widget tag (ie up to, not including, the space).
	widgetTag = widgetTag.Left(posnOfSeparatorSpace);

	// Now get the target file name.

	int length = targetFileName.GetLength();
	targetFileName = targetFileName.Right(length-posnOfSeparatorSpace-1);

	return;

}
Esempio n. 7
0
bool CMarkup::x_AddElem( char* szName, char* szValue, bool bInsert, bool bAddChild )
{
    if ( bAddChild )
    {
        // Adding a child element under main position
        if ( ! m_iPos )
            return false;
    }
    else if ( m_iPosParent == 0 )
    {
        // Adding root element
        if ( IsWellFormed() )
            return false;


        // Locate after any version and DTD
        m_aPos[0].nEndL = m_csDoc.GetLength();
    }

    // Locate where to add element relative to current node
    int iPosParent, iPosBefore, nOffset = 0, nLength = 0;
    if ( bAddChild )
    {
        iPosParent = m_iPos;
        iPosBefore = m_iPosChild;
    }
    else
    {
        iPosParent = m_iPosParent;
        iPosBefore = m_iPos;
    }
    int nFlags = bInsert?1:0;
    x_LocateNew( iPosParent, iPosBefore, nOffset, nLength, nFlags );
    bool bEmptyParent = m_aPos[iPosParent].IsEmptyElement();
    if ( bEmptyParent || m_aPos[iPosParent].nStartR + 1 == m_aPos[iPosParent].nEndL )
        nOffset += 2;

    // Create element and modify positions of affected elements
    // If no szValue is specified, an empty element is created
    // i.e. either <NAME>value</NAME> or <NAME/>
    //
    int iPos = x_GetFreePos();
    m_aPos[iPos].nStartL = nOffset;

    // Set links
    m_aPos[iPos].iElemParent = iPosParent;
    m_aPos[iPos].iElemChild = 0;
    m_aPos[iPos].iElemNext = 0;
    if ( iPosBefore )
    {
        // Link in after iPosBefore
        m_aPos[iPos].iElemNext = m_aPos[iPosBefore].iElemNext;
        m_aPos[iPosBefore].iElemNext = iPos;
    }
    else
    {
        // First child
        m_aPos[iPos].iElemNext = m_aPos[iPosParent].iElemChild;
        m_aPos[iPosParent].iElemChild = iPos;
    }

    // Create string for insert
    INXString csInsert;
    int nLenName = strlen(szName);
    int nLenValue = szValue? strlen(szValue) : 0;
    if ( ! nLenValue )
    {
        // <NAME/> empty element
        csInsert = "<";
        csInsert += (wxChar*)szName;
        csInsert += _T("/>\r\n");
        m_aPos[iPos].nStartR = m_aPos[iPos].nStartL + nLenName + 2;
        m_aPos[iPos].nEndL = m_aPos[iPos].nStartR - 1;
        m_aPos[iPos].nEndR = m_aPos[iPos].nEndL + 1;
    }
    else
    {
        // <NAME>value</NAME>
        INXString csValue = x_TextToDoc( szValue );
        nLenValue = csValue.GetLength();
        csInsert.Append(wxT("<"));
        csInsert += (wxChar*)szName;
        csInsert += wxT(">");
        csInsert += csValue;
        csInsert += wxT("</");
        csInsert += (wxChar*)szName;
        csInsert += wxT(">\r\n");
        m_aPos[iPos].nStartR = m_aPos[iPos].nStartL + nLenName + 1;
        m_aPos[iPos].nEndL = m_aPos[iPos].nStartR + nLenValue + 1;
        m_aPos[iPos].nEndR = m_aPos[iPos].nEndL + nLenName + 2;
    }

    // Insert
    int nReplace = 0, nLeft = m_aPos[iPos].nStartL;
    if ( bEmptyParent )
    {
        INXString csParentTagName = x_GetTagName(iPosParent);
        INXString csFormat;
        csFormat.Append(wxT(">\r\n"));
        csFormat += csInsert;
        csFormat += wxT("</");
        csFormat += csParentTagName;
        csInsert = csFormat;
        nLeft = m_aPos[iPosParent].nStartR - 1;
        nReplace = 1;
        // x_Adjust is going to update all affected indexes by one amount
        // This will satisfy all except the empty parent
        // Here we pre-adjust for the empty parent
        // The empty tag slash is removed
        m_aPos[iPosParent].nStartR -= 1;
        // For the newly created end tag, see the following example:
        // <A/> (len 4) becomes <A><B/></A> (len 11)
        // In x_Adjust everything will be adjusted 11 - 4 = 7
        // But the nEndL of element A should only be adjusted 5
        m_aPos[iPosParent].nEndL -= (csParentTagName.GetLength() + 1);
    }
    else if ( m_aPos[iPosParent].nStartR + 1 == m_aPos[iPosParent].nEndL )
    {
        csInsert = _T("\r\n") + csInsert;
        nLeft = m_aPos[iPosParent].nStartR + 1;
    }
    x_DocChange( nLeft, nReplace, csInsert );
    x_Adjust( iPos, csInsert.GetLength() - nReplace );

    if ( bAddChild )
        x_SetPos( m_iPosParent, iPosParent, iPos );
    else
        x_SetPos( iPosParent, iPos, 0 );
    return true;
}