mirror of
https://github.com/znc/znc.git
synced 2026-08-10 19:02:51 +02:00
Pulled in CString changes from my common repository to help facilitate the upcoming webmods changes
Changes include... - CString - Addition of LCString typedef to list<CString> Added four more args to CString::Token()... bool bAllowEmpty = false <-- This default of false is NOT backward compatible but seems way more intuitive const CString& sLeft = "" const CString& sRight = "" bool bTrimQuotes = true Added CString::OptionSplit() Added CString::QuoteSplit() Added two new args to CString::Split()... bool bTrimQuotes = true, bool bTrimWhiteSpace = false - CTemplate - Added new class CTemplateTagHandler to provide capability to add custom tags and vars Added var name pointer dereferencing in the form of <? VAR Name=*other_var ?> (use ** to start with a literal star) Added a list of paths that can be used to look for a given filename in multiple locations Added CTemplate::PrependPath() Added CTemplate::AppendPath() Added CTemplate::RemovePath() Added CTemplate::ClearPath() Added CTemplate::PrintString() for filling a CString& instead of a stream Added <? LT ?> which outputs a literal "<?" Added <? GT ?> which outputs a literal "?>" Added <? SETBLOCK ?> and <? ENDSETBLOCK ?> for setting a variable's value to the contents between the tags Added <? EXPAND ?> for expanding a filename to a path using the settable list of paths Added <? BREAK ?> and <? CONTINUE ?> inner loop tags Added <? EXIT ?> tag to stop processing Added <? DEBUG ?> tag for printing to DEBUG() Added REVERSE keyword to the <? LOOP ?> tag git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1537 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
+85
-15
@@ -15,9 +15,35 @@
|
||||
#include <iostream>
|
||||
|
||||
using std::ostream;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
class CTemplate;
|
||||
|
||||
class CTemplateTagHandler {
|
||||
public:
|
||||
CTemplateTagHandler() {}
|
||||
virtual ~CTemplateTagHandler() {}
|
||||
|
||||
virtual bool HandleVar(CTemplate& Tmpl, const CString& sName, const CString& sArgs, CString& sOutput) {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool HandleTag(CTemplate& Tmpl, const CString& sName, const CString& sArgs, CString& sOutput) {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool HandleIf(CTemplate& Tmpl, const CString& sName, const CString& sArgs, CString& sOutput) {
|
||||
return HandleVar(Tmpl, sName, sArgs, sOutput);
|
||||
}
|
||||
|
||||
virtual bool HandleValue(CTemplate& Tmpl, CString& sValue, const MCString& msOptions) {
|
||||
return false;
|
||||
}
|
||||
private:
|
||||
};
|
||||
class CTemplate;
|
||||
|
||||
class CTemplateOptions {
|
||||
public:
|
||||
CTemplateOptions() {
|
||||
@@ -25,7 +51,7 @@ public:
|
||||
m_eEscapeTo = CString::EASCII;
|
||||
}
|
||||
|
||||
~CTemplateOptions() {}
|
||||
virtual ~CTemplateOptions() {}
|
||||
|
||||
void Parse(const CString& sLine);
|
||||
|
||||
@@ -41,16 +67,19 @@ private:
|
||||
|
||||
class CTemplateLoopContext {
|
||||
public:
|
||||
CTemplateLoopContext(unsigned long uFilePos, const CString& sLoopName, vector<CTemplate*>* pRows) {
|
||||
CTemplateLoopContext(unsigned long uFilePos, const CString& sLoopName, bool bReverse, vector<CTemplate*>* pRows) {
|
||||
m_uFilePosition = uFilePos;
|
||||
m_sName = sLoopName;
|
||||
m_uRowIndex = 0;
|
||||
m_bReverse = bReverse;
|
||||
m_pvRows = pRows;
|
||||
m_bHasData = false;
|
||||
}
|
||||
|
||||
~CTemplateLoopContext() {}
|
||||
virtual ~CTemplateLoopContext() {}
|
||||
|
||||
// Setters
|
||||
void SetHasData(bool b = true) { m_bHasData = b; }
|
||||
void SetName(const CString& s) { m_sName = s; }
|
||||
void SetRowIndex(unsigned int u) { m_uRowIndex = u; }
|
||||
unsigned int IncRowIndex() { return ++m_uRowIndex; }
|
||||
@@ -59,6 +88,7 @@ public:
|
||||
// !Setters
|
||||
|
||||
// Getters
|
||||
bool HasData() const { return m_bHasData; }
|
||||
const CString& GetName() const { return m_sName; }
|
||||
unsigned long GetFilePosition() const { return m_uFilePosition; }
|
||||
unsigned int GetRowIndex() const { return m_uRowIndex; }
|
||||
@@ -68,32 +98,70 @@ public:
|
||||
CTemplate* GetCurRow() { return GetRow(m_uRowIndex); }
|
||||
|
||||
CTemplate* GetRow(unsigned int uIndex);
|
||||
CString GetValue(const CString& sName);
|
||||
CString GetValue(const CString& sName, bool bFromIf = false);
|
||||
// !Getters
|
||||
private:
|
||||
protected:
|
||||
CString m_sName; //! The name portion of the <?LOOP name?> tag
|
||||
unsigned int m_uRowIndex; //! The index of the current row we're on
|
||||
unsigned long m_uFilePosition; //! The file position of the opening <?LOOP?> tag
|
||||
vector<CTemplate*>* m_pvRows; //! This holds pointers to the templates associated with this loop
|
||||
bool m_bReverse; //!< Iterate through this loop in reverse order
|
||||
bool m_bHasData; //!< Tells whether this loop has real data or not
|
||||
CString m_sName; //!< The name portion of the <?LOOP name?> tag
|
||||
unsigned int m_uRowIndex; //!< The index of the current row we're on
|
||||
unsigned long m_uFilePosition; //!< The file position of the opening <?LOOP?> tag
|
||||
vector<CTemplate*>* m_pvRows; //!< This holds pointers to the templates associated with this loop
|
||||
};
|
||||
|
||||
|
||||
class CTemplate : public MCString {
|
||||
public:
|
||||
CTemplate() : MCString(), m_spOptions(new CTemplateOptions) {}
|
||||
CTemplate(const CString& sFileName) : MCString(), m_sFileName(sFileName), m_spOptions(new CTemplateOptions) {}
|
||||
CTemplate(const CSmartPtr<CTemplateOptions>& Options) : MCString(), m_spOptions(Options) {}
|
||||
~CTemplate();
|
||||
CTemplate() : MCString(), m_spOptions(new CTemplateOptions) {
|
||||
Init();
|
||||
}
|
||||
|
||||
CTemplate(const CString& sFileName) : MCString(), m_sFileName(sFileName), m_spOptions(new CTemplateOptions) {
|
||||
Init();
|
||||
}
|
||||
|
||||
CTemplate(const CSmartPtr<CTemplateOptions>& Options, CTemplate* pParent = NULL) : MCString(), m_spOptions(Options) {
|
||||
Init();
|
||||
m_pParent = pParent;
|
||||
}
|
||||
|
||||
virtual ~CTemplate();
|
||||
|
||||
//! Class for implementing custom tags in subclasses
|
||||
void AddTagHandler(CSmartPtr<CTemplateTagHandler> spTagHandler) {
|
||||
m_vspTagHandlers.push_back(spTagHandler);
|
||||
}
|
||||
|
||||
vector<CSmartPtr<CTemplateTagHandler> >& GetTagHandlers() {
|
||||
if (m_pParent) {
|
||||
return m_pParent->GetTagHandlers();
|
||||
}
|
||||
|
||||
return m_vspTagHandlers;
|
||||
}
|
||||
|
||||
CString ResolveLiteral(const CString& sString);
|
||||
|
||||
void Init();
|
||||
|
||||
CTemplate* GetParent(bool bRoot);
|
||||
CString ExpandFile(const CString& sFilename);
|
||||
bool SetFile(const CString& sFileName);
|
||||
|
||||
void SetPath(const CString& sPath); // Sets the dir:dir:dir type path to look at for templates, as of right now no ../../.. protection
|
||||
void PrependPath(const CString& sPath);
|
||||
void AppendPath(const CString& sPath);
|
||||
void RemovePath(const CString& sPath);
|
||||
void ClearPath();
|
||||
CString ResolvePath(const CString& sPath, const CString& sFilename);
|
||||
bool PrintString(CString& sRet);
|
||||
bool Print(ostream& oOut = cout);
|
||||
bool Print(const CString& sFileName, ostream& oOut = cout);
|
||||
bool ValidIf(const CString& sArgs);
|
||||
bool ValidExpr(const CString& sExpr);
|
||||
bool IsTrue(const CString& sName);
|
||||
bool HasLoop(const CString& sName);
|
||||
CString GetValue(const CString& sName);
|
||||
CString GetValue(const CString& sName, bool bFromIf = false);
|
||||
CTemplate& AddRow(const CString& sName);
|
||||
CTemplate* GetRow(const CString& sName, unsigned int uIndex);
|
||||
vector<CTemplate*>* GetLoop(const CString& sName);
|
||||
@@ -105,11 +173,13 @@ public:
|
||||
const CString& GetFileName() const { return m_sFileName; }
|
||||
// !Getters
|
||||
private:
|
||||
protected:
|
||||
CTemplate* m_pParent;
|
||||
CString m_sFileName;
|
||||
LCString m_lsPaths;
|
||||
map<CString, vector<CTemplate*> > m_mvLoops;
|
||||
vector<CTemplateLoopContext*> m_vLoopContexts;
|
||||
CSmartPtr<CTemplateOptions> m_spOptions;
|
||||
vector<CSmartPtr<CTemplateTagHandler> > m_vspTagHandlers;
|
||||
};
|
||||
|
||||
#endif // !_TEMPLATE_H
|
||||
|
||||
Reference in New Issue
Block a user