// Markup.cpp: implementation of the CMarkup class.
//
// Markup Release 8.1
// Copyright (C) 1999-2005 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 "Markup.h"
#ifdef _DEBUG
#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
// Defines for Windows CE
#ifdef _WIN32_WCE
#define _tclen(p) 1
#define _tccpy(p1,p2) *(p1)=*(p2)
#endif
// Customization
#define x_EOL _T("\r\n") // can be \r\n or \n or empty
#define x_EOLLEN (sizeof(x_EOL)/sizeof(_TCHAR)-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;
}
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( LPCTSTR szDoc )
{
// Set document text
if ( szDoc )
m_strDoc = szDoc;
else
m_strDoc.Empty();
m_strError.Empty();
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( LPCTSTR szFileName )
{
if ( ! ReadTextFile(szFileName, m_strDoc, &m_strError, &m_nFlags) )
return false;
return x_ParseDoc();
}
bool CMarkup::ReadTextFile( LPCTSTR szFileName, CString& strDoc, CString* pstrError, int* pnFlags )
{
// Static utility method to load text file into strDoc
//
// Open file to read binary
FILE* fp = _tfopen( szFileName, _T("rb") );
if ( ! fp )
{
if ( pstrError )
*pstrError = strerror(errno);
return false;
}
// Set flags to 0 unless flags argument provided
int nFlags = pnFlags?*pnFlags:0;
_TCHAR szDescBOM[20] = {0};
strDoc.Empty();
// 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 );
// For ANSI files, replace CP_UTF8 with CP_ACP in both places
nWideLen = MultiByteToWideChar(CP_UTF8,0,pBuffer,nFileByteLen,NULL,0);
MultiByteToWideChar(CP_UTF8,0,pBuffer,nFileByteLen,strDoc.GetBuffer(nWideLen),nWideLen);
strDoc.ReleaseBuffer( nWideLen );
delete [] pBuffer;
}
if ( pstrError )
(*pstrError).Format(_T("%s%d bytes to %d wide chars"),szDescBOM,nFileByteLen,nWideLen);
#else // read file directly
if ( nFileByteLen )
{
fread( strDoc.GetBuffer(nFileByteLen), nFileByteLen, 1, fp );
strDoc.ReleaseBuffer( nFileByteLen );
}
if ( pstrError )
(*pstrError).Format( _T("%s%d bytes"), szDescBOM, nFileByteLen );
#endif
fclose( fp );
if ( pnFlags )
*pnFlags = nFlags;
return true;
}
bool CMarkup::Save( LPCTSTR szFileName )
{
return WriteTextFile( szFileName, m_strDoc, &m_strError, &m_nFlags );
}
bool CMarkup::WriteTextFile( LPCTSTR szFileName, CString& strDoc, CString* pstrError, int* pnFlags )
{
// Static utility method to save strDoc to text file
//
// Open file to write binary
bool bSuccess = true;
FILE* fp = _tfopen( szFileName, _T("wb") );
if ( ! fp )
{
if ( pstrError )
*pstrError = strerror(errno);
return false;
}
// Set flags to 0 unless flags argument provided
int nFlags = pnFlags?*pnFlags:0;
_TCHAR szDescBOM[20] = {0};
// Get document length
int nDocLength = strDoc.GetLength();
#if defined( _UNICODE )
int nMBLen = 0;
if ( nDocLength )
{
// 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);
bSuccess = ( fwrite( pBuffer, nMBLen, 1, fp ) == 1 );
delete [] pBuffer;
}
if ( pstrError )
(*pstrError).Format( _T("%d wide chars to %s%d bytes"), nDocLength, szDescBOM, nMBLen );
#else // MBCS or UTF-8
if ( nDocLength )
{
CString strDocWrite = strDoc; // reference unless converted
nDocLength = strDocWrite.GetLength();
bSuccess = ( fwrite( (LPCTSTR)strDocWrite, nDocLength, 1, fp ) == 1 );
}
if ( pstrError )
(*pstrError).Format( _T("%s%d bytes"), szDescBOM, nDocLength );
#endif
if ( ! bSuccess && pstrError )
*pstrError = strerror(errno);
fclose(fp);
if ( pnFlags )
*pnFlags = nFlags;
return bSuccess;
}
bool CMarkup::FindElem( LPCTSTR szName )
{
// Change current position only if found
//
if ( m_aPos.GetSize() )
{
int iPos = x_FindElem( m_iPosParent, m_iPos, szName );
if ( iPos )
{
// Assign new position
x_SetPos( m_aPos[iPos].iElemParent, iPos, 0 );
return true;
}
}
return false;
}
bool CMarkup::FindChildElem( LPCTSTR szName )
{
// Change current child position only if found
//
// Shorthand: call this with no current main position
// means find child under root element
if ( ! m_iPos )
FindElem();
int iPosChild = x_FindElem( m_iPos, m_iPosChild, szName );
if ( iPosChild )
{
// Assign new position
int iPos = m_aPos[iPosChild].iElemParent;
x_SetPos( m_aPos[iPos].iElemParent, iPos, iPosChild );
return true;
}
return false;
}
CString CMarkup::EscapeText( LPCTSTR szText, int nFlags )
{
// 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 LPCTSTR szaReplace[] = { _T("<"),_T("&"),_T(">"),_T("'"),_T(""") };
LPCTSTR pFind = (nFlags&MNF_ESCAPEQUOTES)?_T("<&>\'\""):_T("<&>
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
国外知名自动更新软件Updater源代码 (250个子文件)
logol_old.bmp 149KB
about.bmp 147KB
logos.bmp 74KB
logos_old.bmp 74KB
about_old.bmp 73KB
authentication.bmp 68KB
logol.bmp 51KB
close_application.bmp 51KB
warning.bmp 51KB
information.bmp 51KB
error.bmp 51KB
confirmation.bmp 51KB
language_select.bmp 7KB
updater_neg.bmp 670B
updater.bmp 670B
Updater.clw 12KB
Markup.cpp 71KB
CustomBitmapButton.cpp 59KB
Rijndael.cpp 58KB
UpdateInfo.cpp 49KB
UpdateProcess.cpp 43KB
SystemTray.cpp 39KB
Settings.cpp 34KB
XHTMLStatic.cpp 33KB
ModeSilent.cpp 31KB
ModeFullSheet.cpp 30KB
Language.cpp 28KB
InstallFiles.cpp 26KB
HttpFileObject.cpp 24KB
FtpFileObject.cpp 21KB
Registry.cpp 18KB
Functions.cpp 18KB
XHyperLink.cpp 17KB
NetworkFileObject.cpp 17KB
NotifyDlg.cpp 16KB
RestoreInfo.cpp 15KB
Updater.cpp 14KB
Path.cpp 14KB
CheckVersion.cpp 14KB
Restore.cpp 14KB
Rollback.cpp 14KB
Install.cpp 13KB
GetOpt.cpp 13KB
md5.cpp 12KB
CopyFile.cpp 12KB
Download.cpp 11KB
WebBrowser.cpp 11KB
RiskFunctions.cpp 11KB
Internet.cpp 11KB
TreeUpdater.cpp 11KB
ModeFullPropSelectUpdate.cpp 10KB
Unzipper.cpp 10KB
XNamedColors.cpp 10KB
ThemeUtil.cpp 10KB
EventInfo.cpp 10KB
AuthenticationDlg.cpp 9KB
ProxySettingsDlg.cpp 9KB
CloseApplicationDlg.cpp 9KB
ResultLabel.cpp 9KB
BackUp.cpp 9KB
InstallRegistry.cpp 9KB
CheckForUpdatesProcess.cpp 9KB
RestoreDlg.cpp 8KB
CopyFolder.cpp 8KB
Protection.cpp 8KB
InstallIni.cpp 7KB
AboutDlg.cpp 7KB
TransparentIcon.cpp 7KB
ErrorDlg.cpp 7KB
ModeFullPropFinish.cpp 7KB
HyperlinkLabel.cpp 7KB
ModeHidden.cpp 7KB
ConnectionTest.cpp 6KB
ModeFullPropWelcome.cpp 6KB
ActionPoints.cpp 6KB
TransparentBitmap.cpp 6KB
Sections.cpp 6KB
ModeFullPropCheck.cpp 6KB
RollbackInfo.cpp 5KB
ModeFullPropProtection.cpp 5KB
ModeFullPropInstall.cpp 5KB
ModeFullPropDownload.cpp 5KB
SelectUpdate.cpp 5KB
ConfirmationDlg.cpp 5KB
LogViewerDlg.cpp 5KB
SelectLanguageDlg.cpp 5KB
ModeFullPropHtmlMessage.cpp 4KB
Proxy.cpp 4KB
InformationDlg.cpp 4KB
WarningDlg.cpp 4KB
ModeFullPropRollback.cpp 4KB
ModeFullPropLicense.cpp 4KB
SelfUpdateInfo.cpp 4KB
FileVersion.cpp 4KB
FileData.cpp 4KB
StringFunctions.cpp 3KB
Log.cpp 3KB
SectionData.cpp 3KB
ProxyInfo.cpp 3KB
ShortcutData.cpp 3KB
共 250 条
- 1
- 2
- 3
资源评论
- sky_kingdom2014-05-30不错的代码
- qingfeng19852019-08-31不错的代码
- PhilosophicalMan2013-10-29不能编译,提示缺TmSchema.h文件。
- 梦依20142014-05-13不错的代码
- jonsen992014-08-01很详细的代码,不过挺复杂的。慢慢看吧。
kishinev
- 粉丝: 3
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 设计一个简单的电子邮件管理系统,包括用户、邮件、收件箱、发件箱等信息 可以涉及邮件发送、接收、草稿箱、垃圾邮件处理等
- 设计一个在线教育平台数据库,包括课程、学生、教师、考试等信息管理 可以涉及课程安排、学生成绩、教师评价等功能
- 一个音乐播放列表管理系统,包括歌曲信息、用户播放记录、收藏歌单等 可以涉及歌曲分类、播放统计、推荐功能等
- 设计一个简化版的社交网络数据库,包括用户、帖子、评论、关注等信息 可以涉及用户注册、发布帖子、点赞评论等操作
- 电脑编程有哪些电脑编程有哪些电脑编程有哪些
- 一个医院信息管理系统,包括患者、医生、药品、诊断等信息的管理 可以涉及医生排班、患者就诊记录、药品库存等
- 电脑编程有哪些电脑编程有哪些电脑编程有哪些
- 各种规格的攻牙参数对照表
- pycharm官网pycharm官网pycharm官网
- CNC三凌系统,法兰克系统master cam 2017到2023,专用后处理,带备刀,可调整参数
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功