// Markup.cpp: implementation of the CMarkup class.
//
// Markup Release 9.0
// Copyright (C) 1999-2007 First Objective Software, Inc. All rights reserved
// Go to www.firstobject.com for the latest CMarkup and EDOM documentation
// Use in commercial applications requires written permission
// This software is provided "as is", with no warranty.
//
#include "StdAfx.h"
#include <stdio.h>
#include "Markup.h"
#ifdef MCD_STRERROR
#include <string.h>
#include <errno.h>
#else
#include <windows.h>
#endif
#if defined(_DEBUG) && ! defined(MARKUP_STL) && ! defined(MARKUP_STDC)
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#ifdef _MBCS
#pragma message( "Note: MBCS build (not UTF-8)" )
// For UTF-8, remove _MBCS from project settings C/C++ preprocessor definitions
#endif
// Customization
#define x_EOL _T("\r\n") // can be \r\n or \n or empty
#define x_EOLLEN (sizeof(x_EOL)/sizeof(MCD_CHAR)-1) // string length of x_EOL
#define x_ATTRIBQUOTE _T("\"") // can be double or single quote
void CMarkup::operator=( const CMarkup& markup )
{
m_iPosParent = markup.m_iPosParent;
m_iPos = markup.m_iPos;
m_iPosChild = markup.m_iPosChild;
m_iPosFree = markup.m_iPosFree;
m_iPosDeleted = markup.m_iPosDeleted;
m_nNodeType = markup.m_nNodeType;
m_nNodeOffset = markup.m_nNodeOffset;
m_nNodeLength = markup.m_nNodeLength;
m_strDoc = markup.m_strDoc;
m_strError = markup.m_strError;
m_nFlags = markup.m_nFlags;
// Copy used part of the index array
m_aPos.RemoveAll();
m_aPos.nSize = m_iPosFree;
if ( m_aPos.nSize < 8 )
m_aPos.nSize = 8;
m_aPos.nSegs = m_aPos.SegsUsed();
if ( m_aPos.nSegs )
{
m_aPos.pSegs = (ElemPos**)(new char[m_aPos.nSegs*sizeof(char*)]);
int nSegSize = 1 << m_aPos.PA_SEGBITS;
for ( int nSeg=0; nSeg < m_aPos.nSegs; ++nSeg )
{
if ( nSeg + 1 == m_aPos.nSegs )
nSegSize = m_aPos.GetSize() - (nSeg << m_aPos.PA_SEGBITS);
m_aPos.pSegs[nSeg] = (ElemPos*)(new char[nSegSize*sizeof(ElemPos)]);
memcpy( m_aPos.pSegs[nSeg], markup.m_aPos.pSegs[nSeg], nSegSize*sizeof(ElemPos) );
}
}
// Copy SavedPos map
m_mapSavedPos.RemoveAll();
if ( markup.m_mapSavedPos.pTable )
{
m_mapSavedPos.AllocMapTable();
for ( int nSlot=0; nSlot < SavedPosMap::SPM_SIZE; ++nSlot )
{
SavedPos* pCopySavedPos = markup.m_mapSavedPos.pTable[nSlot];
if ( pCopySavedPos )
{
int nCount = 0;
while ( pCopySavedPos[nCount].nSavedPosFlags & SavedPosMap::SPM_USED )
{
++nCount;
if ( pCopySavedPos[nCount-1].nSavedPosFlags & SavedPosMap::SPM_LAST )
break;
}
if ( nCount )
{
SavedPos* pNewSavedPos = new SavedPos[nCount];
for ( int nCopy=0; nCopy<nCount; ++nCopy )
pNewSavedPos[nCopy] = pCopySavedPos[nCopy];
pNewSavedPos[nCount-1].nSavedPosFlags |= SavedPosMap::SPM_LAST;
m_mapSavedPos.pTable[nSlot] = pNewSavedPos;
}
}
}
}
MARKUP_SETDEBUGSTATE;
}
bool CMarkup::SetDoc( MCD_PCSZ szDoc )
{
// Set document text
if ( szDoc )
m_strDoc = szDoc;
else
MCD_STRCLEAR(m_strDoc);
MCD_STRCLEAR(m_strError);
return x_ParseDoc();
};
bool CMarkup::SetDoc( const MCD_STR& strDoc )
{
m_strDoc = strDoc;
MCD_STRCLEAR(m_strError);
return x_ParseDoc();
}
bool CMarkup::IsWellFormed()
{
if ( m_aPos.GetSize()
&& ! (m_aPos[0].nFlags & MNF_ILLFORMED)
&& m_aPos[0].iElemChild
&& ! m_aPos[m_aPos[0].iElemChild].iElemNext )
return true;
return false;
}
bool CMarkup::Load( MCD_CSTR szFileName )
{
if ( ! ReadTextFile(szFileName, m_strDoc, &m_strError, &m_nFlags) )
return false;
return x_ParseDoc();
}
bool CMarkup::ReadTextFile( MCD_CSTR szFileName, MCD_STR& strDoc, MCD_STR* pstrError, int* pnFlags )
{
// Static utility method to load text file into strDoc
//
// Open file to read binary
FILE* fp = MCD_FOPEN( szFileName, _T("rb") );
if ( ! fp )
{
if ( pstrError )
*pstrError = x_GetLastError();
return false;
}
// Set flags to 0 unless flags argument provided
int nFlags = pnFlags?*pnFlags:0;
MCD_CHAR szDescBOM[20] = {0};
MCD_CHAR szResult[100];
MCD_STRCLEAR(strDoc);
// Get file length
fseek( fp, 0, SEEK_END );
int nFileByteLen = ftell( fp );
fseek( fp, 0, SEEK_SET );
#if defined(UNICODE) // convert file to wide char
int nWideLen = 0;
if ( nFileByteLen )
{
char* pBuffer = new char[nFileByteLen];
fread( pBuffer, nFileByteLen, 1, fp );
/*
// Alternative: use these 3 lines instead of 3 lines below using UTF8To16
// For ANSI files, replace CP_UTF8 with CP_ACP in both places
nWideLen = MultiByteToWideChar(CP_UTF8,0,pBuffer,nFileByteLen,NULL,0);
MCD_CHAR* pUTF16Buffer = MCD_GETBUFFER(strDoc,nWideLen);
MultiByteToWideChar(CP_UTF8,0,pBuffer,nFileByteLen,pUTF16Buffer,nWideLen);
*/
// For ANSI files, replace both UTF8To16 calls with mbstowcs (arguments are the same)
nWideLen = UTF8To16(NULL,pBuffer,nFileByteLen);
MCD_CHAR* pUTF16Buffer = MCD_GETBUFFER(strDoc,nWideLen);
UTF8To16(pUTF16Buffer,pBuffer,nFileByteLen);
MCD_RELEASEBUFFER( strDoc, pUTF16Buffer, nWideLen );
delete [] pBuffer;
}
MCD_SPRINTF( szResult, _T("%s%d bytes to %d wide chars"), szDescBOM, nFileByteLen, nWideLen );
if ( pstrError )
*pstrError = szResult;
#else // read file directly
if ( nFileByteLen )
{
MCD_CHAR* pUTF8Buffer = MCD_GETBUFFER(strDoc,nFileByteLen);
fread( pUTF8Buffer, nFileByteLen, 1, fp );
MCD_RELEASEBUFFER( strDoc, pUTF8Buffer, nFileByteLen );
#if defined(_MBCS) // needs to be in memory as MBCS
MCD_STR strEncoding = GetDeclaredEncoding( strDoc );
if ( MCD_STRISEMPTY(strEncoding) || MCD_PSZNICMP(MCD_2PCSZ(strEncoding),_T("UTF-8"),5)==0 )
strDoc = UTF8ToA( strDoc );
#endif
}
MCD_SPRINTF( szResult, _T("%s%d bytes"), szDescBOM, nFileByteLen );
if ( pstrError )
*pstrError = szResult;
#endif
fclose( fp );
if ( pnFlags )
*pnFlags = nFlags;
return true;
}
bool CMarkup::Save( MCD_CSTR szFileName )
{
return WriteTextFile( szFileName, m_strDoc, &m_strError, &m_nFlags );
}
bool CMarkup::WriteTextFile( MCD_CSTR szFileName, MCD_STR& strDoc, MCD_STR* pstrError, int* pnFlags )
{
// Static utility method to save strDoc to text file
//
// Open file to write binary
bool bSuccess = true;
FILE* fp = MCD_FOPEN( szFileName, _T("wb") );
if ( ! fp )
{
if ( pstrError )
*pstrError = x_GetLastError();
return false;
}
// Set flags to 0 unless flags argument provided
int nFlags = pnFlags?*pnFlags:0;
MCD_CHAR szDescBOM[20] = {0};
MCD_CHAR szResult[100];
// Get document length
int nDocLength = MCD_STRLENGTH(strDoc);
#if defined( UNICODE )
int nMBLen = 0;
if ( nDocLength )
{
/*
// Alternative: use these 3 lines instead of 3 lines below using UTF16To8
// For ANSI files, replace CP_UTF8 with CP_ACP in both places
nMBLen = WideCharToMultiByte(CP_UTF8,0,strDoc,nDocLength,NULL,0,NULL,NULL);
char* pBuffer = new char[nMBLen+1];
WideCharToMultiByte(CP_UTF8,0,strDoc,nDocLength,pBuffer,nMBLen+1,NULL,NULL);
*/
// For ANSI files, replace both UTF16To8 calls with wcstombs (arguments are the same)
nMBLen = UTF16To8(NULL,MCD_2PCSZ(strDoc),0);
char* pBuffer = new char[nMBLen+1];
UTF16To8(pBuffer,MCD_2PCSZ(strDoc),nMBLen);
bSuccess = ( fwrite( pBuffer, nMBLen, 1, fp ) == 1 );
delete [] pBuffer;
}
MCD_SPRINTF( szResult, _T("%d wide chars to %s%d bytes"), nDocLength, szDescBOM, nMBLen );
if ( pstrError )
*pstrError = szResult;
#else // MBCS or UTF-8
if ( nDocLength )
{
MCD_STR strDocWrite = strDoc; // reference unless converted
#if defined(_MBCS) // is in memory as MBCS
MCD_STR strEncoding = GetDeclaredEncoding( strDoc );
if ( MCD_STRISEMPTY(strEncoding) || MCD_PSZNICMP(MCD_2PCSZ(strEncoding),_T("UTF-8"),5)==0 )
strDocWrite = AToUTF8( strDoc );
#endif
nDocLength = MCD_STRLENGTH(strDocWrite);
bSuccess = ( fwrite( MCD_2
没有合适的资源?快使用搜索试试~ 我知道了~
xml文件生成器,双击即可在目的地生成xml文件
共20个文件
h:6个
cpp:5个
ico:2个
4星 · 超过85%的资源 需积分: 35 86 下载量 102 浏览量
2008-07-14
17:57:01
上传
评论 1
收藏 93KB RAR 举报
温馨提示
双击即可在目的地生成xml文件,程序中引用了QT,可跨平台运行
资源推荐
资源详情
资源评论
收起资源包目录
xml.rar (20个子文件)
source
StdAfx.h 1KB
Markup.cpp 88KB
xml.clw 984B
xml.dsw 529B
Markup.h 19KB
res
xml.ico 116KB
xml.rc2 395B
复件 xml.ico 1KB
Thumbs.db 4KB
xmlDlg.h 2KB
xml.dsp 4KB
IniFile.h 3KB
IniFile.cpp 28KB
xmlDlg.cpp 12KB
Resource.h 528B
xml.cpp 2KB
xml.aps 34KB
xml.rc 5KB
StdAfx.cpp 205B
xml.h 1KB
共 20 条
- 1
资源评论
- 7296649652013-12-09虽然是源代码。不过也谢谢了。。可以参考参考····
- IT伤心鸟2012-12-04有点用,谢了
- 雨焰2012-09-11额,不记得当初的使用情况了!但是给个好评还是必须的!
- Jonwin2014-05-13源码与我想要的那种有点不一样,不过还是谢谢
- bailiju2013-02-25是代码,我原以为是XML文件生成工具软件。
bitkx2008
- 粉丝: 17
- 资源: 18
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功