From e7feeafa568d3c01ddf4d6466c4724dbe06c18eb Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Mon, 3 Apr 2006 19:34:21 +0000 Subject: [PATCH] added ParseInnerSource() to make
-like parsing easier

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38535 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 include/wx/html/htmlpars.h | 10 ++++++++++
 src/html/htmlpars.cpp      | 15 +++++++++++++++
 src/html/m_pre.cpp         | 10 ++--------
 3 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/include/wx/html/htmlpars.h b/include/wx/html/htmlpars.h
index d102b6c8dd..7a7951b3e8 100644
--- a/include/wx/html/htmlpars.h
+++ b/include/wx/html/htmlpars.h
@@ -116,6 +116,10 @@ public:
     // empty
     virtual bool RestoreState();
 
+    // Returns HTML source inside the element (i.e. between the starting
+    // and ending tag)
+    wxString GetInnerSource(const wxHtmlTag& tag);
+
     // Parses HTML string 'markup' and extracts charset info from  tag
     // if present. Returns empty string if the tag is missing.
     // For wxHTML's internal use.
@@ -224,6 +228,12 @@ protected:
     void ParseInner(const wxHtmlTag& tag)
         { m_Parser->DoParsing(tag.GetBeginPos(), tag.GetEndPos1()); }
 
+    // Parses given source as if it was tag's inner code (see
+    // wxHtmlParser::GetInnerSource).  Unlike ParseInner(), this method lets
+    // you specify the source code to parse. This is useful when you need to
+    // modify the inner text before parsing.
+    void ParseInnerSource(const wxString& source);
+
     wxHtmlParser *m_Parser;
 
     DECLARE_NO_COPY_CLASS(wxHtmlTagHandler)
diff --git a/src/html/htmlpars.cpp b/src/html/htmlpars.cpp
index b1da8c92df..ea7f38d865 100644
--- a/src/html/htmlpars.cpp
+++ b/src/html/htmlpars.cpp
@@ -432,12 +432,27 @@ bool wxHtmlParser::RestoreState()
     return true;
 }
 
+wxString wxHtmlParser::GetInnerSource(const wxHtmlTag& tag)
+{
+    return GetSource()->Mid(tag.GetBeginPos(),
+                            tag.GetEndPos1() - tag.GetBeginPos());
+}
+
 //-----------------------------------------------------------------------------
 // wxHtmlTagHandler
 //-----------------------------------------------------------------------------
 
 IMPLEMENT_ABSTRACT_CLASS(wxHtmlTagHandler,wxObject)
 
+void wxHtmlTagHandler::ParseInnerSource(const wxString& source)
+{
+    // It is safe to temporarily change the source being parsed,
+    // provided we restore the state back after parsing
+    m_Parser->SetSourceAndSaveState(source);
+    m_Parser->DoParsing();
+    m_Parser->RestoreState();
+}
+
 
 //-----------------------------------------------------------------------------
 // wxHtmlEntitiesParser
diff --git a/src/html/m_pre.cpp b/src/html/m_pre.cpp
index f522512994..4b5a71c7aa 100644
--- a/src/html/m_pre.cpp
+++ b/src/html/m_pre.cpp
@@ -104,14 +104,8 @@ TAG_HANDLER_BEGIN(PRE, "PRE")
         c->SetAlignHor(wxHTML_ALIGN_LEFT);
         c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
 
-        wxString srcMid =
-            m_WParser->GetSource()->Mid(tag.GetBeginPos(),
-                                        tag.GetEndPos1() - tag.GetBeginPos());
-        // It is safe to temporarily change the source being parsed,
-        // provided we restore the state back after parsing
-        m_Parser->SetSourceAndSaveState(HtmlizeWhitespaces(srcMid));
-        m_Parser->DoParsing();
-        m_Parser->RestoreState();
+        wxString srcMid = m_WParser->GetInnerSource(tag);
+        ParseInnerSource(HtmlizeWhitespaces(srcMid));
 
         m_WParser->CloseContainer();
         m_WParser->CloseContainer();
-- 
2.45.2