📄 pymlengineimpl.cpp
字号:
//// This file is part of the "More for C++" library//// Copyright (c) 1999-2003 by Thorsten Goertz (thorsten@morefor.org)//// The "More for C++" library is free software; you can redistribute it and/or// modify it under the terms of the license that comes with this package.//// Read "license.txt" for more details.//// THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED// WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES// OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.////////////////////////////////////////////////////////////////////////////////#include "pymlengineimpl.hpp"using namespace more;using namespace more::io;using namespace more::os;using namespace more::pyml;using namespace more::script;////////////////////////////////////////////////////////////////////////////////PymlEngineImpl::PymlEngineImpl( const p<PythonInterpreter>& pPythonInterpreter): m_pPythonInterpreter( pPythonInterpreter ), m_bHasBeenInterrupted( false ){}////////////////////////////////////////////////////////////////////////////////p<PythonInterpreter> PymlEngineImpl::getInterpreter( ){ return m_pPythonInterpreter;}////////////////////////////////////////////////////////////////////////////////void PymlEngineImpl::transform( const String& sPyml, const p<OutputStream>& pOutputStream, const p<Directory>& pWorkingDirectory) throw( IOException ){ if( pOutputStream == 0 ) { throw NullPointerException( ); } try { size_t nPosOfHtml = 0; size_t nPosOfStartTag = 0; m_bHasBeenInterrupted = false; while( sPyml.find( "<py>", nPosOfHtml, nPosOfStartTag ) && !m_bHasBeenInterrupted ) { String sHTML = sPyml.getSubstring( nPosOfHtml, nPosOfStartTag - nPosOfHtml ); size_t nPosOfEndTag; *pOutputStream << sHTML; if( sPyml.find( "</py>", nPosOfStartTag, nPosOfEndTag ) ) { String sPython = extractPython( sPyml, nPosOfStartTag, nPosOfEndTag ); m_pPythonInterpreter -> invoke( sPython, pOutputStream, pWorkingDirectory ); nPosOfHtml = nPosOfEndTag + 5; } else { nPosOfHtml = nPosOfStartTag + 4; } } if( !m_bHasBeenInterrupted && sPyml.getLength( ) - nPosOfHtml > 0 ) { *pOutputStream << sPyml.getSuffix( sPyml.getLength( ) - nPosOfHtml ); } } catch( const Interpreter::NotAvailable& ) { *pOutputStream << "The Python interpreter is not available.\n"; }}////////////////////////////////////////////////////////////////////////////////void PymlEngineImpl::interrupt( ){ m_bHasBeenInterrupted = true;}////////////////////////////////////////////////////////////////////////////////bool PymlEngineImpl::hasBeenInterrupted( ){ return m_bHasBeenInterrupted;}////////////////////////////////////////////////////////////////////////////////String PymlEngineImpl::extractPython( const String& sPyml, size_t nPosOfStartTag, size_t nPosOfEndTag) const{ Array<char> result( nPosOfEndTag - nPosOfStartTag - 4 + 2 ); size_t nIndex = nPosOfStartTag + 4; size_t nPosOfFirstNonWhiteSpace; size_t nNoOfLeadingWhiteSpaces; size_t nCopyIndex = 0; while( nIndex < nPosOfEndTag && ( sPyml[nIndex] == '\r' || sPyml[nIndex] == '\n' ) ) { nIndex++; } nPosOfFirstNonWhiteSpace = nIndex; while( nPosOfFirstNonWhiteSpace < nPosOfEndTag && sPyml[nPosOfFirstNonWhiteSpace] <= ' ' ) { nPosOfFirstNonWhiteSpace++; } nNoOfLeadingWhiteSpaces = nPosOfFirstNonWhiteSpace - nIndex; while( nIndex < nPosOfEndTag ) { nIndex += nNoOfLeadingWhiteSpaces; while( nIndex < nPosOfEndTag && ( sPyml[nIndex] >= ' ' || sPyml[nIndex] == '\t' ) ) { result[nCopyIndex++] = sPyml[nIndex++]; } while( nIndex < nPosOfEndTag && ( sPyml[nIndex] == '\r' || sPyml[nIndex] == '\n' ) ) { nIndex++; } result[nCopyIndex++] = '\n'; } result[nCopyIndex] = 0x00; return String( result );}////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -