|
|
|
@ -21,12 +21,12 @@ Imports System.Diagnostics.CodeAnalysis |
|
|
|
|
''' <summary> |
|
|
|
|
''' The parser of |
|
|
|
|
''' </summary> |
|
|
|
|
Public NotInheritable Class BBCodeParser |
|
|
|
|
Public NotInheritable Class BBCodeParser(Of TContext As Class) |
|
|
|
|
|
|
|
|
|
Private __Factory As BBCodeElementFactory |
|
|
|
|
Private __Configuration As BBCodeConfiguration |
|
|
|
|
Private __Factory As BBCodeElementFactory(Of TContext) |
|
|
|
|
Private __Configuration As BBCodeConfiguration(Of TContext) |
|
|
|
|
|
|
|
|
|
Private Shared ReadOnly __ConfigSerializer As New System.Xml.Serialization.XmlSerializer(GetType(BBCodeConfiguration)) |
|
|
|
|
Private Shared ReadOnly __ConfigSerializer As New System.Xml.Serialization.XmlSerializer(GetType(BBCodeConfiguration(Of TContext))) |
|
|
|
|
Private Shared ReadOnly __Tokenizer As Tokenization.Tokenizer = PrepareTokenizer() |
|
|
|
|
|
|
|
|
|
''' <summary>Initializes an instance of the <see cref="BBCodeParser" /> class. |
|
|
|
@ -40,7 +40,7 @@ Public NotInheritable Class BBCodeParser |
|
|
|
|
Public ReadOnly Property Dictionary() As BBCodeElementDictionary |
|
|
|
|
Get |
|
|
|
|
If (__Configuration Is Nothing) Then |
|
|
|
|
__Configuration = New BBCodeConfiguration() |
|
|
|
|
__Configuration = New BBCodeConfiguration(Of TContext)() |
|
|
|
|
End If |
|
|
|
|
Return __Configuration.Dictionary |
|
|
|
|
End Get |
|
|
|
@ -49,10 +49,10 @@ Public NotInheritable Class BBCodeParser |
|
|
|
|
''' <summary> |
|
|
|
|
''' Gets the dictionary of types created by the parser. |
|
|
|
|
''' </summary> |
|
|
|
|
Public ReadOnly Property ElementTypes() As BBCodeElementTypeDictionary |
|
|
|
|
Public ReadOnly Property ElementTypes() As BBCodeElementTypeDictionary(Of TContext) |
|
|
|
|
Get |
|
|
|
|
If (__Configuration Is Nothing) Then |
|
|
|
|
__Configuration = New BBCodeConfiguration() |
|
|
|
|
__Configuration = New BBCodeConfiguration(Of TContext)() |
|
|
|
|
End If |
|
|
|
|
Return __Configuration.ElementTypes |
|
|
|
|
End Get |
|
|
|
@ -134,7 +134,7 @@ Public NotInheritable Class BBCodeParser |
|
|
|
|
''' </summary> |
|
|
|
|
''' <param name="text">The text to be parsed.</param> |
|
|
|
|
''' <returns>A <see cref="BBCodeNodeCollection"/> containing the parsed text.</returns> |
|
|
|
|
Public Function Parse(ByVal text As String) As BBCodeDocument |
|
|
|
|
Public Function Parse(ByVal text As String) As BBCodeDocument(Of TContext) |
|
|
|
|
Using reader As New IO.StringReader(text) |
|
|
|
|
Return Parse(reader) |
|
|
|
|
End Using |
|
|
|
@ -145,7 +145,7 @@ Public NotInheritable Class BBCodeParser |
|
|
|
|
''' </summary> |
|
|
|
|
''' <param name="stream">The <see cref="IO.Stream"/> to be parsed.</param> |
|
|
|
|
''' <returns>A <see cref="BBCodeNodeCollection"/> containing the parsed <see cref="IO.Stream"/>.</returns> |
|
|
|
|
Public Function Parse(ByVal stream As IO.Stream) As BBCodeDocument |
|
|
|
|
Public Function Parse(ByVal stream As IO.Stream) As BBCodeDocument(Of TContext) |
|
|
|
|
Return Parse(stream, Text.Encoding.UTF8) |
|
|
|
|
End Function |
|
|
|
|
|
|
|
|
@ -155,7 +155,7 @@ Public NotInheritable Class BBCodeParser |
|
|
|
|
''' <param name="stream">The <see cref="IO.Stream"/> to be parsed.</param> |
|
|
|
|
''' <param name="encoding">The encoding of the stream.</param> |
|
|
|
|
''' <returns>A <see cref="BBCodeNodeCollection"/> containing the parsed <see cref="IO.Stream"/>.</returns> |
|
|
|
|
Public Function Parse(ByVal stream As IO.Stream, ByVal encoding As Text.Encoding) As BBCodeDocument |
|
|
|
|
Public Function Parse(ByVal stream As IO.Stream, ByVal encoding As Text.Encoding) As BBCodeDocument(Of TContext) |
|
|
|
|
Return Parse(New IO.StreamReader(stream, encoding)) |
|
|
|
|
End Function |
|
|
|
|
|
|
|
|
@ -164,11 +164,11 @@ Public NotInheritable Class BBCodeParser |
|
|
|
|
''' </summary> |
|
|
|
|
''' <param name="reader">The <see cref="IO.TextReader"/> to be parsed.</param> |
|
|
|
|
''' <returns>A <see cref="BBCodeNodeCollection"/> containing the parsed <see cref="IO.TextReader"/>.</returns> |
|
|
|
|
Public Function Parse(ByVal reader As IO.TextReader) As BBCodeDocument |
|
|
|
|
Public Function Parse(ByVal reader As IO.TextReader) As BBCodeDocument(Of TContext) |
|
|
|
|
|
|
|
|
|
Dim doc = New BBCodeDocument(Me) |
|
|
|
|
Dim rootElement As New BBCodeElement(Me) |
|
|
|
|
Dim currentElement As BBCodeElement = rootElement |
|
|
|
|
Dim doc = New BBCodeDocument(Of TContext)(Me) |
|
|
|
|
Dim rootElement As New BBCodeElement(Of TContext)(Me) |
|
|
|
|
Dim currentElement As BBCodeElement(Of TContext) = rootElement |
|
|
|
|
|
|
|
|
|
Dim tk As Tokenization.Token |
|
|
|
|
Dim sb As New Text.StringBuilder() |
|
|
|
@ -195,7 +195,7 @@ Public NotInheritable Class BBCodeParser |
|
|
|
|
'* Add the text node |
|
|
|
|
'* |
|
|
|
|
If (sb.Length > 0) Then |
|
|
|
|
currentElement.Nodes.Add(New BBCodeText(sb.ToString())) |
|
|
|
|
currentElement.Nodes.Add(New BBCodeText(Of TContext)(sb.ToString())) |
|
|
|
|
End If |
|
|
|
|
|
|
|
|
|
'* |
|
|
|
@ -226,16 +226,16 @@ Public NotInheritable Class BBCodeParser |
|
|
|
|
''' <summary> |
|
|
|
|
''' Gets the <see cref="BBCodeElementFactory"/>. |
|
|
|
|
''' </summary> |
|
|
|
|
Private ReadOnly Property Factory() As BBCodeElementFactory |
|
|
|
|
Private ReadOnly Property Factory() As BBCodeElementFactory(Of TContext) |
|
|
|
|
Get |
|
|
|
|
If (__Factory Is Nothing) Then |
|
|
|
|
__Factory = New BBCodeElementFactory(Me) |
|
|
|
|
__Factory = New BBCodeElementFactory(Of TContext)(Me) |
|
|
|
|
End If |
|
|
|
|
Return __Factory |
|
|
|
|
End Get |
|
|
|
|
End Property |
|
|
|
|
|
|
|
|
|
Private Sub ParseElement(ByVal rootElement As BBCodeElement, ByRef currentElement As BBCodeElement, ByVal token As Tokenization.Token, ByVal sb As Text.StringBuilder, ByVal tag As BBCodeTag) |
|
|
|
|
Private Sub ParseElement(ByVal rootElement As BBCodeElement(Of TContext), ByRef currentElement As BBCodeElement(Of TContext), ByVal token As Tokenization.Token, ByVal sb As Text.StringBuilder, ByVal tag As BBCodeTag) |
|
|
|
|
|
|
|
|
|
'* |
|
|
|
|
'* Check the token Type |
|
|
|
@ -261,13 +261,13 @@ Public NotInheritable Class BBCodeParser |
|
|
|
|
|
|
|
|
|
End Sub |
|
|
|
|
|
|
|
|
|
Private Sub ParseTag(ByRef currentElement As BBCodeElement, ByVal sb As Text.StringBuilder, ByVal tag As BBCodeTag) |
|
|
|
|
Private Sub ParseTag(ByRef currentElement As BBCodeElement(Of TContext), ByVal sb As Text.StringBuilder, ByVal tag As BBCodeTag) |
|
|
|
|
|
|
|
|
|
'* |
|
|
|
|
'* Add the text previous to the current element |
|
|
|
|
'* |
|
|
|
|
If (sb.Length > 0) Then |
|
|
|
|
currentElement.Nodes.Add(New BBCodeText(sb.ToString())) |
|
|
|
|
currentElement.Nodes.Add(New BBCodeText(Of TContext)(sb.ToString())) |
|
|
|
|
sb.Remove(0, sb.Length) |
|
|
|
|
End If |
|
|
|
|
|
|
|
|
@ -286,7 +286,7 @@ Public NotInheritable Class BBCodeParser |
|
|
|
|
|
|
|
|
|
End Sub |
|
|
|
|
|
|
|
|
|
Private Shared Sub ParseClosingTag(ByVal rootElement As BBCodeElement, ByRef currentElement As BBCodeElement, ByVal token As Tokenization.Token, ByVal sb As Text.StringBuilder, ByVal tag As BBCodeTag) |
|
|
|
|
Private Shared Sub ParseClosingTag(ByVal rootElement As BBCodeElement(Of TContext), ByRef currentElement As BBCodeElement(Of TContext), ByVal token As Tokenization.Token, ByVal sb As Text.StringBuilder, ByVal tag As BBCodeTag) |
|
|
|
|
|
|
|
|
|
'* |
|
|
|
|
'* Check if the closing tag is closing a previously open tag |
|
|
|
@ -296,7 +296,7 @@ Public NotInheritable Class BBCodeParser |
|
|
|
|
'* Add the inner text |
|
|
|
|
'* |
|
|
|
|
If (sb.Length > 0) Then |
|
|
|
|
currentElement.Nodes.Add(New BBCodeText(sb.ToString())) |
|
|
|
|
currentElement.Nodes.Add(New BBCodeText(Of TContext)(sb.ToString())) |
|
|
|
|
sb.Remove(0, sb.Length) |
|
|
|
|
End If |
|
|
|
|
|
|
|
|
|