parent
0591fb8474
commit
971fcf4e38
@ -1 +1 @@ |
|||||||
481 |
495 |
@ -1 +1 @@ |
|||||||
217 |
231 |
@ -0,0 +1,183 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : BBCodeAttributeDictionary.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 4/29/2009 11:39:24 AM |
||||||
|
' COPYRIGHT : Copyright © 2009 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' TODO: Add file description |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 4/29/2009 11:39:24 AM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Represents a collection of Attributes. |
||||||
|
''' </summary> |
||||||
|
Public Class BBCodeAttributeDictionary |
||||||
|
Implements IDictionary(Of String, String) |
||||||
|
|
||||||
|
Dim __dic As IDictionary(Of String, String) |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="BBCodeAttributeDictionary" /> class. |
||||||
|
''' This is the default constructor for this class.</summary> |
||||||
|
Public Sub New() |
||||||
|
__dic = New Dictionary(Of String, String) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Removes all items from the <see cref="BBCodeAttributeDictionary" />. |
||||||
|
''' </summary> |
||||||
|
Public Sub Clear() Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of String, String)).Clear |
||||||
|
__dic.Clear() |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Copies the elements of the <see cref="BBCodeAttributeDictionary" /> to an System.Array, starting at a particular System.Array index. |
||||||
|
''' </summary> |
||||||
|
''' <param name="array">The one-dimensional System.Array that is the destination of the elements copied from <see cref="BBCodeAttributeDictionary" />. The System.Array must have zero-based indexing.</param> |
||||||
|
''' <param name="arrayIndex">The zero-based index in array at which copying begins.</param> |
||||||
|
''' <remarks></remarks> |
||||||
|
Private Sub CopyTo(ByVal array() As System.Collections.Generic.KeyValuePair(Of String, String), ByVal arrayIndex As Integer) Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of String, String)).CopyTo |
||||||
|
__dic.CopyTo(array, arrayIndex) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the number of elements contained in the <see cref="BBCodeAttributeDictionary" />. |
||||||
|
''' </summary> |
||||||
|
''' <value>The number of elements contained in the <see cref="BBCodeAttributeDictionary" />.</value> |
||||||
|
Public ReadOnly Property Count() As Integer Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of String, String)).Count |
||||||
|
Get |
||||||
|
Return __dic.Count |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets a value indicating whether the <see cref="BBCodeAttributeDictionary" /> is read-only. |
||||||
|
''' </summary> |
||||||
|
''' <value>true if the <see cref="BBCodeAttributeDictionary" /> is read-only; otherwise, false.</value> |
||||||
|
Public ReadOnly Property IsReadOnly() As Boolean Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of String, String)).IsReadOnly |
||||||
|
Get |
||||||
|
Return __dic.IsReadOnly |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Adds an element with the provided key and value to the <see cref="BBCodeAttributeDictionary" />. |
||||||
|
''' </summary> |
||||||
|
''' <param name="key">The object to use as the key of the element to add.</param> |
||||||
|
''' <param name="value">The object to use as the value of the element to add.</param> |
||||||
|
Public Sub Add(ByVal key As String, ByVal value As String) Implements System.Collections.Generic.IDictionary(Of String, String).Add |
||||||
|
__dic.Add(key.ToUpperInvariant(), value) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Determines whether the <see cref="BBCodeAttributeDictionary" /> contains an element with the specified key. |
||||||
|
''' </summary> |
||||||
|
''' <param name="key">The key to locate in the <see cref="BBCodeAttributeDictionary" />.</param> |
||||||
|
''' <returns><c>True</c> if the <see cref="BBCodeAttributeDictionary" /> contains an element with the key; otherwise, <c>False</c>.</returns> |
||||||
|
''' <remarks></remarks> |
||||||
|
Public Function ContainsKey(ByVal key As String) As Boolean Implements System.Collections.Generic.IDictionary(Of String, String).ContainsKey |
||||||
|
Return __dic.ContainsKey(key.ToUpperInvariant()) |
||||||
|
End Function |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets or sets the element with the specified key. |
||||||
|
''' </summary> |
||||||
|
''' <param name="key">The key of the element to get or set.</param> |
||||||
|
''' <value>The element with the specified key.</value> |
||||||
|
Default Public Property Item(ByVal key As String) As String Implements System.Collections.Generic.IDictionary(Of String, String).Item |
||||||
|
Get |
||||||
|
Return __dic.Item(key.ToUpperInvariant()) |
||||||
|
End Get |
||||||
|
Set(ByVal value As String) |
||||||
|
__dic.Item(key.ToUpperInvariant()) = value |
||||||
|
End Set |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets an <see cref="System.Collections.Generic.ICollection(Of T)" /> containing the keys of the <see cref="BBCodeAttributeDictionary" />. |
||||||
|
''' </summary> |
||||||
|
''' <value>An <see cref="System.Collections.Generic.ICollection(Of T)" /> containing the keys of the object that implements <see cref="BBCodeAttributeDictionary" />.</value> |
||||||
|
Public ReadOnly Property Keys() As System.Collections.Generic.ICollection(Of String) Implements System.Collections.Generic.IDictionary(Of String, String).Keys |
||||||
|
Get |
||||||
|
Return __dic.Keys |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Removes the element with the specified key from the <see cref="BBCodeAttributeDictionary" />. |
||||||
|
''' </summary> |
||||||
|
''' <param name="key">The key of the element to remove.</param> |
||||||
|
''' <returns><c>True</c> if the element is successfully removed; otherwise, <c>False</c>. This method also returns <c>False</c> if key was not found in the original <see cref="BBCodeAttributeDictionary" />.</returns> |
||||||
|
''' <remarks></remarks> |
||||||
|
Public Function Remove(ByVal key As String) As Boolean Implements System.Collections.Generic.IDictionary(Of String, String).Remove |
||||||
|
Return __dic.Remove(key) |
||||||
|
End Function |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the value associated with the specified key. |
||||||
|
''' </summary> |
||||||
|
''' <param name="key">The key whose value to get.</param> |
||||||
|
''' <param name="value">When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.</param> |
||||||
|
''' <returns><c>True</c> if the object that implements <see cref="BBCodeAttributeDictionary" /> contains an element with the specified key; otherwise, <c>False</c>.</returns> |
||||||
|
''' <remarks></remarks> |
||||||
|
Public Function TryGetValue(ByVal key As String, ByRef value As String) As Boolean Implements System.Collections.Generic.IDictionary(Of String, String).TryGetValue |
||||||
|
Return __dic.TryGetValue(key, value) |
||||||
|
End Function |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets an <see cref="System.Collections.Generic.ICollection(Of T)" /> containing the values in the <see cref="BBCodeAttributeDictionary" />. |
||||||
|
''' </summary> |
||||||
|
''' <value>An <see cref="System.Collections.Generic.ICollection(Of T)" /> containing the values in the object that implements <see cref="BBCodeAttributeDictionary" />.</value> |
||||||
|
Public ReadOnly Property Values() As System.Collections.Generic.ICollection(Of String) Implements System.Collections.Generic.IDictionary(Of String, String).Values |
||||||
|
Get |
||||||
|
Return __dic.Values |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Returns an enumerator that iterates through the collection. |
||||||
|
''' </summary> |
||||||
|
''' <returns>A System.Collections.Generic.IEnumerator(Of T) that can be used to iterate through the collection.</returns> |
||||||
|
Public Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of System.Collections.Generic.KeyValuePair(Of String, String)) Implements System.Collections.Generic.IEnumerable(Of System.Collections.Generic.KeyValuePair(Of String, String)).GetEnumerator |
||||||
|
Return __dic.GetEnumerator() |
||||||
|
End Function |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Adds an item to the <see cref="BBCodeAttributeDictionary"/>. |
||||||
|
''' </summary> |
||||||
|
''' <param name="item">The attribute to be added.</param> |
||||||
|
Private Sub Add(ByVal item As System.Collections.Generic.KeyValuePair(Of String, String)) Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of String, String)).Add |
||||||
|
__dic.Add(item.Key.ToUpperInvariant(), item.Value) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Removes the first occurrence of a specific object from the <see cref="BBCodeAttributeDictionary" />. |
||||||
|
''' </summary> |
||||||
|
''' <param name="item">The object to remove from the <see cref="BBCodeAttributeDictionary" />.</param> |
||||||
|
''' <returns><c>True</c> if item was successfully removed from the <see cref="BBCodeAttributeDictionary" />; otherwise, <c>False</c>. This method also returns <c>False</c> if item is not found in the original <see cref="BBCodeAttributeDictionary" />.</returns> |
||||||
|
''' <remarks></remarks> |
||||||
|
Private Function Remove(ByVal item As System.Collections.Generic.KeyValuePair(Of String, String)) As Boolean Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of String, String)).Remove |
||||||
|
Return __dic.Remove(item) |
||||||
|
End Function |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Determines whether the <see cref="BBCodeAttributeDictionary" /> contains a specific value. |
||||||
|
''' </summary> |
||||||
|
''' <param name="item">The object to locate in the <see cref="BBCodeAttributeDictionary" />.</param> |
||||||
|
''' <returns><c>True</c> if item is found in the <see cref="BBCodeAttributeDictionary" />; otherwise, <c>False</c>.</returns> |
||||||
|
''' <remarks></remarks> |
||||||
|
Private Function Contains(ByVal item As System.Collections.Generic.KeyValuePair(Of String, String)) As Boolean Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of String, String)).Contains |
||||||
|
Return __dic.Contains(item) |
||||||
|
End Function |
||||||
|
|
||||||
|
Private Function IEnumerableGetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator |
||||||
|
Return __dic.GetEnumerator() |
||||||
|
End Function |
||||||
|
|
||||||
|
End Class |
@ -0,0 +1,148 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : BBCodeConfiguration.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 4/30/2009 10:57:20 PM |
||||||
|
' COPYRIGHT : Copyright © 2009 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' TODO: Add file description |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 4/30/2009 10:57:20 PM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
Imports System.Xml.Serialization |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Represents the configuration of the <see cref="BBCodeParser"/>. |
||||||
|
''' </summary> |
||||||
|
<Serializable()> _ |
||||||
|
<XmlRoot(ElementName:=STR_BBCodeConfigurationXmlElement, [Namespace]:=STR_BBCodeSchemaNamespace)> _ |
||||||
|
Public NotInheritable Class BBCodeConfiguration |
||||||
|
Implements IXmlSerializable |
||||||
|
|
||||||
|
Private Shared ReadOnly __CurrentVersion As New System.Version(1, 0) |
||||||
|
|
||||||
|
Private __Version As System.Version |
||||||
|
Private __Dictionary As BBCodeElementDictionary |
||||||
|
Private __ElementTypes As BBCodeElementTypeDictionary |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="BBCodeConfiguration" /> class. |
||||||
|
''' This is the default constructor for this class.</summary> |
||||||
|
Friend Sub New() |
||||||
|
__Version = New Version(1, 0) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the version of the configuration file. |
||||||
|
''' </summary> |
||||||
|
Public Property Version() As System.Version |
||||||
|
Get |
||||||
|
Return __Version |
||||||
|
End Get |
||||||
|
Private Set(ByVal value As System.Version) |
||||||
|
If (value > __CurrentVersion) Then |
||||||
|
Throw New ArgumentException("Unrecognized version.") |
||||||
|
End If |
||||||
|
__Version = value |
||||||
|
End Set |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the dictionary configuration. |
||||||
|
''' </summary> |
||||||
|
<XmlArrayItem()> _ |
||||||
|
Public ReadOnly Property Dictionary() As BBCodeElementDictionary |
||||||
|
Get |
||||||
|
If (__Dictionary Is Nothing) Then |
||||||
|
__Dictionary = New BBCodeElementDictionary() |
||||||
|
End If |
||||||
|
Return __Dictionary |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the factory configuration. |
||||||
|
''' </summary> |
||||||
|
<XmlArrayItem()> _ |
||||||
|
Public ReadOnly Property ElementTypes() As BBCodeElementTypeDictionary |
||||||
|
Get |
||||||
|
If (__ElementTypes Is Nothing) Then |
||||||
|
__ElementTypes = New BBCodeElementTypeDictionary() |
||||||
|
End If |
||||||
|
Return __ElementTypes |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary>This method is reserved and should not be used. When implementing the IXmlSerializable interface, you should return null (Nothing in Visual Basic) from this method, and instead, if specifying a custom schema is required, apply the <see cref="T:System.Xml.Serialization.XmlSchemaProviderAttribute" /> to the class.</summary> |
||||||
|
''' <returns>An <see cref="T:System.Xml.Schema.XmlSchema" /> that describes the XML representation of the object that is produced by the <see cref="M:System.Xml.Serialization.IXmlSerializable.WriteXml(System.Xml.XmlWriter)" /> method and consumed by the <see cref="M:System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader)" /> method.</returns> |
||||||
|
Public Function GetSchema() As System.Xml.Schema.XmlSchema Implements System.Xml.Serialization.IXmlSerializable.GetSchema |
||||||
|
Return Nothing |
||||||
|
End Function |
||||||
|
|
||||||
|
''' <summary>Generates an object from its XML representation.</summary> |
||||||
|
''' <param name="reader">The <see cref="T:System.Xml.XmlReader" /> stream from which the object is deserialized.</param> |
||||||
|
Public Sub ReadXml(ByVal reader As System.Xml.XmlReader) Implements System.Xml.Serialization.IXmlSerializable.ReadXml |
||||||
|
|
||||||
|
'* |
||||||
|
'* Check the name of the element |
||||||
|
'* |
||||||
|
If (reader.NamespaceURI <> STR_BBCodeSchemaNamespace) OrElse (reader.LocalName <> STR_BBCodeConfigurationXmlElement) Then |
||||||
|
Exit Sub |
||||||
|
End If |
||||||
|
|
||||||
|
'* |
||||||
|
'* Gets the version of the configuration |
||||||
|
'* |
||||||
|
Dim versionString = reader.GetAttribute("version") |
||||||
|
If (Not String.IsNullOrEmpty(versionString)) Then |
||||||
|
Me.Version = New System.Version(versionString) |
||||||
|
End If |
||||||
|
|
||||||
|
'* |
||||||
|
'* Move to the first item |
||||||
|
'* |
||||||
|
reader.Read() |
||||||
|
|
||||||
|
Dim dictionarySerializer = New XmlSerializer(GetType(BBCodeElementDictionary)) |
||||||
|
Dim typesSerializer = New XmlSerializer(GetType(BBCodeElementTypeDictionary)) |
||||||
|
|
||||||
|
__ElementTypes = Nothing |
||||||
|
__Dictionary = Nothing |
||||||
|
|
||||||
|
If (reader.LocalName = STR_BBCodeElementTypesXmlElement AndAlso reader.NamespaceURI = STR_BBCodeSchemaNamespace) Then |
||||||
|
__ElementTypes = typesSerializer.Deserialize(reader) |
||||||
|
End If |
||||||
|
|
||||||
|
If (reader.LocalName = STR_BBCodeDictionaryXmlElement AndAlso reader.NamespaceURI = STR_BBCodeSchemaNamespace) Then |
||||||
|
__Dictionary = dictionarySerializer.Deserialize(reader) |
||||||
|
End If |
||||||
|
|
||||||
|
If (__ElementTypes Is Nothing AndAlso reader.LocalName = STR_BBCodeElementTypesXmlElement AndAlso reader.NamespaceURI = STR_BBCodeSchemaNamespace) Then |
||||||
|
__ElementTypes = typesSerializer.Deserialize(reader) |
||||||
|
End If |
||||||
|
|
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary>Converts an object into its XML representation.</summary> |
||||||
|
''' <param name="writer">The <see cref="T:System.Xml.XmlWriter" /> stream to which the object is serialized.</param> |
||||||
|
Public Sub WriteXml(ByVal writer As System.Xml.XmlWriter) Implements System.Xml.Serialization.IXmlSerializable.WriteXml |
||||||
|
|
||||||
|
Dim dictionarySerializer = New XmlSerializer(GetType(BBCodeElementDictionary)) |
||||||
|
Dim typesSerializer = New XmlSerializer(GetType(BBCodeElementTypeDictionary)) |
||||||
|
|
||||||
|
If (ElementTypes.Count > 0) Then |
||||||
|
typesSerializer.Serialize(writer, ElementTypes) |
||||||
|
End If |
||||||
|
|
||||||
|
If (Dictionary.Count > 0) Then |
||||||
|
dictionarySerializer.Serialize(writer, Dictionary) |
||||||
|
End If |
||||||
|
|
||||||
|
End Sub |
||||||
|
|
||||||
|
End Class |
@ -0,0 +1,94 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : BBCodeDocument.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 4/29/2009 10:21:41 PM |
||||||
|
' COPYRIGHT : Copyright © 2009 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' TODO: Add file description |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 4/29/2009 10:21:41 PM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Represents a document writen in BBCode. |
||||||
|
''' </summary> |
||||||
|
Public NotInheritable Class BBCodeDocument |
||||||
|
|
||||||
|
Private __Text As String |
||||||
|
Private __Parser As BBCodeParser |
||||||
|
Private __Nodes As BBCodeNodeCollection |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="BBCodeDocument" /> class.</summary> |
||||||
|
''' <param name="parser">The <see cref="BBCodeParser"/> that created this instance.</param> |
||||||
|
Friend Sub New(ByVal parser As BBCodeParser) |
||||||
|
__Parser = parser |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the <see cref="BBCodeParser"/> that is responsible for this <see cref="BBCodeDocument"/>. |
||||||
|
''' </summary> |
||||||
|
Friend ReadOnly Property Parser() As BBCodeParser |
||||||
|
Get |
||||||
|
Return __Parser |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets or sets the BBCode of the document. |
||||||
|
''' </summary> |
||||||
|
Public Property Text() As String |
||||||
|
Get |
||||||
|
Return __Text |
||||||
|
End Get |
||||||
|
Set(ByVal value As String) |
||||||
|
__Text = value |
||||||
|
Nodes.Clear() |
||||||
|
Nodes.AddRange(Me.Parser.Parse(value).Nodes) |
||||||
|
End Set |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the <see cref="BBCodeNodeCollection"/> generated ba the BBCode text. |
||||||
|
''' </summary> |
||||||
|
''' <value>A <see cref="BBCodeNodeCollection"/> that represents the parsed text of the document.</value> |
||||||
|
Public ReadOnly Property Nodes() As BBCodeNodeCollection |
||||||
|
Get |
||||||
|
If (__Nodes Is Nothing) Then |
||||||
|
__Nodes = New BBCodeNodeCollection() |
||||||
|
End If |
||||||
|
Return __Nodes |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Returns the formatted text. |
||||||
|
''' </summary> |
||||||
|
''' <returns>The formatted text.</returns> |
||||||
|
Public Function Format() As String |
||||||
|
Return Format(New BBCodeHtmlFormatter()) |
||||||
|
End Function |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Returns the formatted text, using the specified <see cref="ITextFormatter"/>. |
||||||
|
''' </summary> |
||||||
|
''' <param name="formatter">An object that implements the <see cref="ITextFormatter"/> interface.</param> |
||||||
|
''' <returns>The formatted text.</returns> |
||||||
|
Public Function Format(ByVal formatter As ITextFormatter) As String |
||||||
|
Dim sb As New Text.StringBuilder() |
||||||
|
For Each n In Nodes |
||||||
|
sb.Append(n.Format(formatter)) |
||||||
|
Next |
||||||
|
Return sb.ToString() |
||||||
|
End Function |
||||||
|
|
||||||
|
Friend Sub SetText(ByVal text As String) |
||||||
|
__Text = text |
||||||
|
End Sub |
||||||
|
|
||||||
|
End Class |
@ -0,0 +1,259 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : BBCodeElement.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 4/29/2009 11:33:36 AM |
||||||
|
' COPYRIGHT : Copyright © 2009 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' TODO: Add file description |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 4/29/2009 11:33:36 AM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
Imports System.Globalization |
||||||
|
Imports System.Text.RegularExpressions |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Represents an BBCode element. |
||||||
|
''' </summary> |
||||||
|
Public Class BBCodeElement |
||||||
|
Inherits BBCodeNode |
||||||
|
|
||||||
|
Private __Name As String |
||||||
|
Private __Nodes As BBCodeNodeCollection |
||||||
|
Private __Attributes As BBCodeAttributeDictionary |
||||||
|
Private __ReplacementFormat As String = String.Empty |
||||||
|
Private __RequireClosingTag As TriState = TriState.UseDefault |
||||||
|
Private __IsValueFormatted As Boolean |
||||||
|
|
||||||
|
Private Shared ReadOnly __RxAttribute As New Regex("\{(?<name>[_a-zA-Z0-9].*?)\}") |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="BBCodeElement" /> class. |
||||||
|
''' This is the default constructor for this class.</summary> |
||||||
|
Friend Sub New() |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="BBCodeElement" /> class.</summary> |
||||||
|
''' <param name="name">The name of the element.</param> |
||||||
|
Protected Sub New(ByVal name As String) |
||||||
|
__Name = name.ToUpperInvariant() |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="BBCodeElement" /> class.</summary> |
||||||
|
''' <param name="parser">The parser used to create this element.</param> |
||||||
|
Friend Sub New(ByVal parser As BBCodeParser) |
||||||
|
MyBase.New(parser) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the name of the element. |
||||||
|
''' </summary> |
||||||
|
Public ReadOnly Property Name() As String |
||||||
|
Get |
||||||
|
Return __Name |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the replacement format for this element. |
||||||
|
''' </summary> |
||||||
|
''' <value>The replacement format.</value> |
||||||
|
''' <remarks> |
||||||
|
''' <para>In order to use the any parameter in the replacement format use the following syntax: {paramName}.</para> |
||||||
|
''' <para/> |
||||||
|
''' <para>The parameter names are case insensitive.</para> |
||||||
|
''' <para/> |
||||||
|
''' <para>There are two reserved parameter keywords for formatting: DEFAULT and VALUE.</para> |
||||||
|
''' <para><c>DEFAULT</c> : The text following the first equal sign after the name of the BBCode element.</para> |
||||||
|
''' <para><c>VALUE</c>: The HTML generated by the BBCode between the start and end element tag.</para> |
||||||
|
''' <para><example>[url=http://tempuri.org]text[/url]</example></para> |
||||||
|
''' <para>In the example above the parameter DEFAULT would have the value "http://tempuri.org", while VALUE would be "text".</para> |
||||||
|
''' <para/> |
||||||
|
''' <para>To replace [url=http://tempuri.org]text[/url] the with <a href="http://tempuri.org">text</a> the following ReplacementFormat should be used:</para> |
||||||
|
''' <example> |
||||||
|
''' <a href="{default|value}">{value|default}</a> |
||||||
|
''' </example> |
||||||
|
''' <para>The example above, will set the href attribute with either the default value or the text inside the [url] element. The pipe (|) implies in finding the first non-empty attribute.</para> |
||||||
|
''' </remarks> |
||||||
|
Public ReadOnly Property ReplacementFormat() As String |
||||||
|
Get |
||||||
|
If (String.IsNullOrEmpty(__ReplacementFormat)) Then |
||||||
|
If (Me.Parser.Dictionary.ContainsKey(Me.Name)) Then |
||||||
|
__ReplacementFormat = Me.Parser.Dictionary(Me.Name).ReplacementFormat |
||||||
|
End If |
||||||
|
End If |
||||||
|
Return __ReplacementFormat |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets a value indicating if the element requires a closing tag. |
||||||
|
''' </summary> |
||||||
|
''' <value><c>True</c> if the element requires a closing tag; otherwise <c>False</c>.</value> |
||||||
|
Public ReadOnly Property RequireClosingTag() As Boolean |
||||||
|
Get |
||||||
|
If (__RequireClosingTag = TriState.UseDefault) Then |
||||||
|
If (Not String.IsNullOrEmpty(Me.Name) AndAlso Me.Parser.Dictionary.ContainsKey(Me.Name)) Then |
||||||
|
__RequireClosingTag = If(Me.Parser.Dictionary(Me.Name).RequireClosingTag, TriState.True, TriState.False) |
||||||
|
End If |
||||||
|
End If |
||||||
|
Return (__RequireClosingTag = TriState.True) |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the list of attributes. |
||||||
|
''' </summary> |
||||||
|
Public ReadOnly Property Attributes() As BBCodeAttributeDictionary |
||||||
|
Get |
||||||
|
If (__Attributes Is Nothing) Then |
||||||
|
__Attributes = New BBCodeAttributeDictionary |
||||||
|
End If |
||||||
|
Return __Attributes |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the list of sub nodes. |
||||||
|
''' </summary> |
||||||
|
Public ReadOnly Property Nodes() As BBCodeNodeCollection |
||||||
|
Get |
||||||
|
If (__Nodes Is Nothing) Then |
||||||
|
__Nodes = New BBCodeNodeCollection(Me) |
||||||
|
End If |
||||||
|
Return __Nodes |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary>Transforms this instance of <see cref="BBCodeElement" /> into its desired text representation.</summary> |
||||||
|
''' <param name="formatter">An object that implements the <see cref="ITextFormatter" /> interface.</param> |
||||||
|
''' <returns>The text formatted by the <see cref="ITextFormatter" />.</returns> |
||||||
|
Public Overrides Function Format(ByVal formatter As ITextFormatter) As String |
||||||
|
IsValueFormatted = False |
||||||
|
Dim sb As New Text.StringBuilder(Me.ReplacementFormat) |
||||||
|
Dim attribs = __RxAttribute.Matches(Me.ReplacementFormat) |
||||||
|
For Each attrib As Match In attribs |
||||||
|
sb.Replace(attrib.Value, GetAttribute(attrib.Groups("name").Value, formatter)) |
||||||
|
Next |
||||||
|
If Not IsValueFormatted Then |
||||||
|
sb.Append(GetAttribute("value", formatter)) |
||||||
|
End If |
||||||
|
Return sb.ToString() |
||||||
|
End Function |
||||||
|
|
||||||
|
''' <summary>Gets or sets the inner </summary> |
||||||
|
''' <value>The BBCode between the start and end tags.</value> |
||||||
|
Public NotOverridable Overrides Property InnerBBCode() As String |
||||||
|
Get |
||||||
|
Dim sb As New System.Text.StringBuilder() |
||||||
|
For Each n As BBCodeNode In Nodes |
||||||
|
sb.Append(n.OuterBBCode) |
||||||
|
Next |
||||||
|
Return sb.ToString() |
||||||
|
End Get |
||||||
|
Set(ByVal value As String) |
||||||
|
If Not RequireClosingTag Then |
||||||
|
Throw New InvalidOperationException("The InnerBBCode property cannot be set for elements that does not require closing tags.") |
||||||
|
End If |
||||||
|
Me.Nodes.Clear() |
||||||
|
Me.Nodes.AddRange(Me.Parser.Parse(value).Nodes) |
||||||
|
End Set |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary>Gets or sets the outer </summary> |
||||||
|
''' <value>The BBCode of this instance of the <see cref="BBCodeNode" /> .</value> |
||||||
|
Public NotOverridable Overrides ReadOnly Property OuterBBCode() As String |
||||||
|
Get |
||||||
|
Dim sb As New Text.StringBuilder() |
||||||
|
sb.Append("[") |
||||||
|
sb.Append(Me.Name) |
||||||
|
If ((Me.Attributes.Count = 1) AndAlso Me.Attributes.ContainsKey("default")) Then |
||||||
|
sb.AppendFormat(CultureInfo.InvariantCulture, "={0}", Quote(Me.Attributes("default"))) |
||||||
|
Else |
||||||
|
For Each key In Me.Attributes.Keys |
||||||
|
sb.AppendFormat(CultureInfo.InvariantCulture, " {0}={1}", key, Quote(Me.Attributes(key))) |
||||||
|
Next |
||||||
|
End If |
||||||
|
If (Me.RequireClosingTag) Then |
||||||
|
sb.Append("]") |
||||||
|
sb.Append(Me.InnerBBCode) |
||||||
|
sb.Append("[/") |
||||||
|
sb.Append(Me.Name) |
||||||
|
End If |
||||||
|
sb.Append("]") |
||||||
|
Return sb.ToString() |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary>Gets or sets the plain text of the node.</summary> |
||||||
|
''' <value>The plain text between the start and end tags.</value> |
||||||
|
Public NotOverridable Overrides Property InnerText() As String |
||||||
|
Get |
||||||
|
Dim sb As New Text.StringBuilder() |
||||||
|
For Each n In Me.Nodes |
||||||
|
sb.Append(n.InnerText) |
||||||
|
Next |
||||||
|
Return sb.ToString() |
||||||
|
End Get |
||||||
|
Set(ByVal value As String) |
||||||
|
If (Not RequireClosingTag) Then |
||||||
|
Throw New InvalidOperationException("The InnerText property cannot be set for elements that does not require closing tags.") |
||||||
|
End If |
||||||
|
|
||||||
|
'* |
||||||
|
'* Removes all nodex from the element |
||||||
|
'* |
||||||
|
Me.Nodes.Clear() |
||||||
|
If (Not String.IsNullOrEmpty(value)) Then |
||||||
|
'* |
||||||
|
'* Only append a BBCodeText element if the value is not empty |
||||||
|
'* |
||||||
|
Me.Nodes.Add(New BBCodeText(value)) |
||||||
|
End If |
||||||
|
End Set |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Sets the element name of this instance. |
||||||
|
''' </summary> |
||||||
|
''' <param name="name">The new element name of this instance.</param> |
||||||
|
Friend Sub SetName(ByVal name As String) |
||||||
|
__Name = name |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets a value indicating wheter or not the <see cref="BBCodeElement.Nodes"/> have been formatted. |
||||||
|
''' </summary> |
||||||
|
''' <returns><c>True</c> if the values have been formatted; otherwise <c>False</c>.</returns> |
||||||
|
Private Property IsValueFormatted() As Boolean |
||||||
|
Get |
||||||
|
Return __IsValueFormatted |
||||||
|
End Get |
||||||
|
Set(ByVal value As Boolean) |
||||||
|
__IsValueFormatted = value |
||||||
|
End Set |
||||||
|
End Property |
||||||
|
|
||||||
|
Private Function GetAttribute(ByVal name As String, ByVal formatter As ITextFormatter) As String |
||||||
|
Dim attribs = name.ToUpperInvariant().Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries) |
||||||
|
For Each attrib In attribs |
||||||
|
If (String.CompareOrdinal(attrib, "VALUE") = 0) Then |
||||||
|
IsValueFormatted = True |
||||||
|
Dim sb As New Text.StringBuilder() |
||||||
|
For Each node In Me.Nodes |
||||||
|
sb.Append(node.Format(formatter)) |
||||||
|
Next |
||||||
|
Return sb.ToString() |
||||||
|
ElseIf (Me.Attributes.ContainsKey(attrib)) Then |
||||||
|
Return (Me.Attributes.Item(attrib)) |
||||||
|
End If |
||||||
|
Next |
||||||
|
Return String.Empty |
||||||
|
End Function |
||||||
|
|
||||||
|
End Class |
@ -0,0 +1,113 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : BBCodeElementDefinition.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 4/29/2009 10:52:11 PM |
||||||
|
' COPYRIGHT : Copyright © 2009 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' TODO: Add file description |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 4/29/2009 10:52:11 PM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
Imports System.Xml.Serialization |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Represents a way of describing an element. |
||||||
|
''' </summary> |
||||||
|
Public Structure BBCodeElementDefinition |
||||||
|
|
||||||
|
Private __TagName As String |
||||||
|
Private __RequireClosingTag As Boolean |
||||||
|
Private __ReplacementFormat As String |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the name of the element. |
||||||
|
''' </summary> |
||||||
|
<XmlAttribute()> _ |
||||||
|
Public Property TagName() As String |
||||||
|
Get |
||||||
|
Return __TagName |
||||||
|
End Get |
||||||
|
Set(ByVal value As String) |
||||||
|
__TagName = value.ToUpperInvariant() |
||||||
|
End Set |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets or sets the replacement format for this element. |
||||||
|
''' </summary> |
||||||
|
''' <value>The replacement format.</value> |
||||||
|
''' <remarks> |
||||||
|
''' <para>In order to use the any parameter in the replacement format use the following syntax: {paramName}.</para> |
||||||
|
''' <para/> |
||||||
|
''' <para>The parameter names are case insensitive.</para> |
||||||
|
''' <para/> |
||||||
|
''' <para>There are two reserved parameter keywords for formatting: DEFAULT and VALUE.</para> |
||||||
|
''' <para><c>DEFAULT</c> : The text following the first equal sign after the name of the BBCode element.</para> |
||||||
|
''' <para><c>VALUE</c>: The HTML generated by the BBCode between the start and end element tag.</para> |
||||||
|
''' <para><example>[url=http://tempuri.org]text[/url]</example></para> |
||||||
|
''' <para>In the example above the parameter DEFAULT would have the value "http://tempuri.org", while VALUE would be "text".</para> |
||||||
|
''' <para/> |
||||||
|
''' <para>To replace [url=http://tempuri.org]text[/url] the with <a href="http://tempuri.org">text</a> the following ReplacementFormat should be used:</para> |
||||||
|
''' <example> |
||||||
|
''' <a href="{default|value}">{value|default}</a> |
||||||
|
''' </example> |
||||||
|
''' <para>The example above, will set the href attribute with either the default value or the text inside the [url] element. The pipe (|) implies in finding the first non-empty attribute.</para> |
||||||
|
''' </remarks> |
||||||
|
<XmlElement()> _ |
||||||
|
Public Property ReplacementFormat() As String |
||||||
|
Get |
||||||
|
Return __ReplacementFormat |
||||||
|
End Get |
||||||
|
Set(ByVal value As String) |
||||||
|
__ReplacementFormat = value |
||||||
|
End Set |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets or sets a value indicating if the element requires a closing tag. |
||||||
|
''' </summary> |
||||||
|
<XmlAttribute()> _ |
||||||
|
Public Property RequireClosingTag() As Boolean |
||||||
|
Get |
||||||
|
Return __RequireClosingTag |
||||||
|
End Get |
||||||
|
Set(ByVal value As Boolean) |
||||||
|
__RequireClosingTag = value |
||||||
|
End Set |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary>Indicates whether this instance and a specified object are equal.</summary> |
||||||
|
''' <returns>true if <paramref name="obj" /> and this instance are the same type and represent the same value; otherwise, false.</returns> |
||||||
|
''' <param name="obj">Another object to compare to.</param> |
||||||
|
''' <filterpriority>2</filterpriority> |
||||||
|
Public Overrides Function Equals(ByVal obj As Object) As Boolean |
||||||
|
If Not (TypeOf obj Is BBCodeElementDefinition) Then |
||||||
|
Return False |
||||||
|
End If |
||||||
|
Return (Me.TagName = obj.TagName AndAlso Me.ReplacementFormat = obj.ReplacementFormat AndAlso Me.RequireClosingTag = obj.RequireClosingTag) |
||||||
|
End Function |
||||||
|
|
||||||
|
''' <summary>Returns the hash code for this instance.</summary> |
||||||
|
''' <returns>A 32-bit signed integer that is the hash code for this instance.</returns> |
||||||
|
''' <filterpriority>2</filterpriority> |
||||||
|
Public Overrides Function GetHashCode() As Integer |
||||||
|
Dim hash As Long = Me.TagName.GetHashCode() + Me.ReplacementFormat.GetHashCode() + Me.RequireClosingTag.GetHashCode() |
||||||
|
Return hash And Integer.MinValue |
||||||
|
End Function |
||||||
|
|
||||||
|
Public Shared Operator =(ByVal left As BBCodeElementDefinition, ByVal right As BBCodeElementDefinition) As Boolean |
||||||
|
Return left.Equals(right) |
||||||
|
End Operator |
||||||
|
|
||||||
|
Public Shared Operator <>(ByVal left As BBCodeElementDefinition, ByVal right As BBCodeElementDefinition) As Boolean |
||||||
|
Return Not left = right |
||||||
|
End Operator |
||||||
|
|
||||||
|
End Structure |
@ -0,0 +1,158 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : BBCodeDictionary.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 4/29/2009 4:57:05 PM |
||||||
|
' COPYRIGHT : Copyright © 2009 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' TODO: Add file description |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 4/29/2009 4:57:05 PM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
Imports System.Xml.Serialization |
||||||
|
Imports System.Runtime.Serialization |
||||||
|
Imports System.Diagnostics.CodeAnalysis |
||||||
|
Imports System.Globalization |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Represents the dictionary of terms. |
||||||
|
''' </summary> |
||||||
|
<Serializable()> _ |
||||||
|
<XmlRoot(ElementName:=STR_BBCodeDictionaryXmlElement, [Namespace]:=STR_BBCodeSchemaNamespace)> _ |
||||||
|
Public NotInheritable Class BBCodeElementDictionary |
||||||
|
Inherits Dictionary(Of String, BBCodeElementDefinition) |
||||||
|
Implements IXmlSerializable |
||||||
|
Private Const STR_DictionaryItem As String = "tag" |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="BBCodeElementDictionary" /> class. |
||||||
|
''' This is the default constructor for this class.</summary> |
||||||
|
Friend Sub New() |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary>Initializes a new instance of the <see cref="BBCodeElementDictionary" /> class with serialized data.</summary> |
||||||
|
''' <param name="info">A <see cref="T:System.Runtime.Serialization.SerializationInfo" /> object containing the information required to serialize the <see cref="T:System.Collections.Generic.Dictionary`2" />.</param> |
||||||
|
''' <param name="context">A <see cref="T:System.Runtime.Serialization.StreamingContext" /> structure containing the source and destination of the serialized stream associated with the <see cref="T:System.Collections.Generic.Dictionary`2" />.</param> |
||||||
|
Private Sub New(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext) |
||||||
|
MyBase.New(info, context) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Adds the specified key and value to the dictionary. |
||||||
|
''' </summary> |
||||||
|
''' <param name="tagName">The key of the element to add.</param> |
||||||
|
''' <param name="value">The value of the element to add.</param> |
||||||
|
Private Shadows Sub Add(ByVal tagName As String, ByVal value As BBCodeElementDefinition) |
||||||
|
ValidateTagName(tagName) |
||||||
|
MyBase.Add(tagName.ToUpperInvariant(), value) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Adds a new tag definition to the <see cref="BBCodeElementDictionary"/>. |
||||||
|
''' </summary> |
||||||
|
''' <param name="tagName">The name of the tag.</param> |
||||||
|
''' <param name="replacementFormat">The text that the tag will generate, with placeholders for tag parameters.</param> |
||||||
|
Public Shadows Sub Add(ByVal tagName As String, ByVal replacementFormat As String) |
||||||
|
Add(tagName, replacementFormat, False) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Adds a new tag definition to the <see cref="BBCodeElementDictionary"/>. |
||||||
|
''' </summary> |
||||||
|
''' <param name="tagName">The name of the tag.</param> |
||||||
|
''' <param name="replacementFormat">The text that the tag will generate, with placeholders for tag parameters.</param> |
||||||
|
''' <param name="requireClosingTag">A value indicating wether or not the taq requires a closing tag.</param> |
||||||
|
Public Shadows Sub Add(ByVal tagName As String, ByVal replacementFormat As String, ByVal requireClosingTag As Boolean) |
||||||
|
Add(tagName, New BBCodeElementDefinition() With {.TagName = tagName, _ |
||||||
|
.ReplacementFormat = replacementFormat, _ |
||||||
|
.RequireClosingTag = requireClosingTag}) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary>This method is reserved and should not be used. When implementing the IXmlSerializable interface, you should return null (Nothing in Visual Basic) from this method, and instead, if specifying a custom schema is required, apply the <see cref="T:System.Xml.Serialization.XmlSchemaProviderAttribute" /> to the class.</summary> |
||||||
|
''' <returns>An <see cref="T:System.Xml.Schema.XmlSchema" /> that describes the XML representation of the object that is produced by the <see cref="M:System.Xml.Serialization.IXmlSerializable.WriteXml(System.Xml.XmlWriter)" /> method and consumed by the <see cref="M:System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader)" /> method.</returns> |
||||||
|
Private Function GetSchema() As System.Xml.Schema.XmlSchema Implements System.Xml.Serialization.IXmlSerializable.GetSchema |
||||||
|
Return Nothing |
||||||
|
End Function |
||||||
|
|
||||||
|
''' <summary>Generates an object from its XML representation.</summary> |
||||||
|
''' <param name="reader">The <see cref="T:System.Xml.XmlReader" /> stream from which the object is deserialized.</param> |
||||||
|
<SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId:="System.Boolean.TryParse(System.String,System.Boolean@)", Justification:="The return value is not important in this context.")> _ |
||||||
|
Private Sub ReadXml(ByVal reader As System.Xml.XmlReader) Implements System.Xml.Serialization.IXmlSerializable.ReadXml |
||||||
|
|
||||||
|
'* |
||||||
|
'* Check the name of the element |
||||||
|
'* |
||||||
|
If (reader.NamespaceURI <> STR_BBCodeSchemaNamespace) OrElse (reader.LocalName <> STR_BBCodeDictionaryXmlElement) Then |
||||||
|
Exit Sub |
||||||
|
End If |
||||||
|
|
||||||
|
'* |
||||||
|
'* Move to the first item |
||||||
|
'* |
||||||
|
reader.Read() |
||||||
|
|
||||||
|
'* |
||||||
|
'* Reads the items |
||||||
|
'* |
||||||
|
Do While (reader.LocalName = STR_DictionaryItem AndAlso reader.NamespaceURI = STR_BBCodeSchemaNamespace) |
||||||
|
Dim definition As New BBCodeElementDefinition |
||||||
|
Dim escaped As Boolean |
||||||
|
With definition |
||||||
|
.TagName = reader.GetAttribute("name") |
||||||
|
Boolean.TryParse(reader.GetAttribute("requireClosingTag"), .RequireClosingTag) |
||||||
|
Boolean.TryParse(reader.GetAttribute("escaped"), escaped) |
||||||
|
If (escaped) Then |
||||||
|
.ReplacementFormat = reader.ReadElementContentAsString() |
||||||
|
Else |
||||||
|
.ReplacementFormat = reader.ReadInnerXml().Replace(" xmlns=""""", "") |
||||||
|
End If |
||||||
|
End With |
||||||
|
Me.Add(definition.TagName, definition) |
||||||
|
Loop |
||||||
|
|
||||||
|
If (reader.NodeType = Xml.XmlNodeType.EndElement) Then |
||||||
|
reader.Read() |
||||||
|
End If |
||||||
|
|
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary>Converts an object into its XML representation.</summary> |
||||||
|
''' <param name="writer">The <see cref="T:System.Xml.XmlWriter" /> stream to which the object is serialized.</param> |
||||||
|
<SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", justification:="For human legibility purposes the tagname must be lower case in the configuration file.")> _ |
||||||
|
Private Sub WriteXml(ByVal writer As System.Xml.XmlWriter) Implements System.Xml.Serialization.IXmlSerializable.WriteXml |
||||||
|
|
||||||
|
Dim doc = New Xml.XmlDocument() |
||||||
|
Dim xml = doc.CreateElement(STR_DictionaryItem, STR_BBCodeSchemaNamespace) |
||||||
|
For Each it In Me |
||||||
|
xml.Attributes.RemoveAll() |
||||||
|
|
||||||
|
xml.SetAttribute("name", it.Key.ToLower(CultureInfo.InvariantCulture)) |
||||||
|
xml.SetAttribute("requireClosingTag", it.Value.RequireClosingTag.ToString()) |
||||||
|
|
||||||
|
Try |
||||||
|
'* |
||||||
|
'* Check if the Replacement format is valid XML |
||||||
|
'* |
||||||
|
xml.InnerXml = it.Value.ReplacementFormat |
||||||
|
Catch ex As Xml.XmlException |
||||||
|
'* |
||||||
|
'* It's not a valid XML, so adds it as a value |
||||||
|
'* |
||||||
|
xml.SetAttribute("escaped", True) |
||||||
|
xml.InnerText = it.Value.ReplacementFormat |
||||||
|
End Try |
||||||
|
|
||||||
|
'* |
||||||
|
'* OK, we attemp to write it of |
||||||
|
'* |
||||||
|
writer.WriteNode(xml.CreateNavigator(), True) |
||||||
|
Next |
||||||
|
|
||||||
|
End Sub |
||||||
|
|
||||||
|
End Class |
@ -0,0 +1,101 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : BBCodeElementFactory.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 4/30/2009 10:48:21 PM |
||||||
|
' COPYRIGHT : Copyright © 2009 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' TODO: Add file description |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 4/30/2009 10:48:21 PM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Creates instances of <see cref="BBCodeElement"/>. |
||||||
|
''' </summary> |
||||||
|
Friend NotInheritable Class BBCodeElementFactory |
||||||
|
|
||||||
|
Private __Parser As BBCodeParser |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="BBCodeElementFactory" /> class.</summary> |
||||||
|
''' <param name="parser">The <see cref="BBCodeParser"/> that will utilize the new instance of the <see cref="BBCodeElementFactory"/>.</param> |
||||||
|
Friend Sub New(ByVal parser As BBCodeParser) |
||||||
|
__Parser = parser |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the <see cref="BBCodeParser"/> that utilizes this instance of the <see cref="BBCodeElementFactory"/>. |
||||||
|
''' </summary> |
||||||
|
Public ReadOnly Property Parser() As BBCodeParser |
||||||
|
Get |
||||||
|
Return __Parser |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Creates a new <see cref="BBCodeElement"/>. |
||||||
|
''' </summary> |
||||||
|
''' <param name="name">The name of the element.</param> |
||||||
|
''' <param name="attributes">The attributes of the element.</param> |
||||||
|
''' <returns>A new <see cref="BBCodeElement"/>.</returns> |
||||||
|
Public Function CreateElement(ByVal name As String, ByVal attributes As BBCodeAttributeDictionary) As BBCodeElement |
||||||
|
|
||||||
|
Dim el As BBCodeElement |
||||||
|
|
||||||
|
'* |
||||||
|
'* Check if we have a different type to create |
||||||
|
'* |
||||||
|
If (Parser.ElementTypes.ContainsKey(name.ToUpperInvariant())) Then |
||||||
|
'* |
||||||
|
'* Gets the type of the element |
||||||
|
'* |
||||||
|
Dim type = Parser.ElementTypes(name.ToUpperInvariant()) |
||||||
|
|
||||||
|
'* |
||||||
|
'* Check if the type IS BBCodeElement |
||||||
|
'* |
||||||
|
If (type.Equals(GetType(BBCodeElement))) Then |
||||||
|
el = New BBCodeElement() |
||||||
|
Else |
||||||
|
'* |
||||||
|
'* Gets the default constructor |
||||||
|
'* |
||||||
|
Dim ctor = type.GetConstructor(New Type() {}) |
||||||
|
If (ctor Is Nothing) Then |
||||||
|
Throw New InvalidOperationException("The type " & type.FullName & " does not have a default constructor.") |
||||||
|
End If |
||||||
|
|
||||||
|
'* |
||||||
|
'* Creates the new element. |
||||||
|
'* |
||||||
|
el = TryCast(ctor.Invoke(New Object() {}), BBCodeElement) |
||||||
|
If (el Is Nothing) Then |
||||||
|
Throw New InvalidOperationException("The type " & type.FullName & " could not be assingned to BBCodeElement.") |
||||||
|
End If |
||||||
|
End If |
||||||
|
Else |
||||||
|
el = New BBCodeElement() |
||||||
|
End If |
||||||
|
|
||||||
|
'* |
||||||
|
'* Set the element properties |
||||||
|
'* |
||||||
|
el.SetName(name) |
||||||
|
el.SetParser(Parser) |
||||||
|
For Each attr In attributes |
||||||
|
el.Attributes.Add(attr.Key, attr.Value) |
||||||
|
Next |
||||||
|
|
||||||
|
'* |
||||||
|
'* Returns the created element. |
||||||
|
'* |
||||||
|
Return el |
||||||
|
|
||||||
|
End Function |
||||||
|
|
||||||
|
End Class |
@ -0,0 +1,104 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : BBCodeElementTypes.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 4/30/2009 10:16:36 PM |
||||||
|
' COPYRIGHT : Copyright © 2009 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' TODO: Add file description |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 4/30/2009 10:16:36 PM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
Imports System.Xml.Serialization |
||||||
|
Imports System.Globalization |
||||||
|
Imports System.Diagnostics.CodeAnalysis |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Represents a dictionary of types that implements a <see cref="BBCodeElement"/>. |
||||||
|
''' </summary> |
||||||
|
<Serializable()> _ |
||||||
|
<XmlRoot(ElementName:=STR_BBCodeElementTypesXmlElement, [Namespace]:=STR_BBCodeSchemaNamespace)> _ |
||||||
|
Public NotInheritable Class BBCodeElementTypeDictionary |
||||||
|
Inherits Dictionary(Of String, Type) |
||||||
|
Implements IXmlSerializable |
||||||
|
|
||||||
|
Private Const STR_ConfigurationItem As String = "element" |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="BBCodeElementTypeDictionary" /> class. |
||||||
|
''' This is the default constructor for this class.</summary> |
||||||
|
Friend Sub New() |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary>Initializes a new instance of the <see cref="BBCodeElementDictionary" /> class with serialized data.</summary> |
||||||
|
''' <param name="info">A <see cref="T:System.Runtime.Serialization.SerializationInfo" /> object containing the information required to serialize the <see cref="T:System.Collections.Generic.Dictionary`2" />.</param> |
||||||
|
''' <param name="context">A <see cref="T:System.Runtime.Serialization.StreamingContext" /> structure containing the source and destination of the serialized stream associated with the <see cref="T:System.Collections.Generic.Dictionary`2" />.</param> |
||||||
|
Private Sub New(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext) |
||||||
|
MyBase.New(info, context) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Adds the specified key and value to the dictionary. |
||||||
|
''' </summary> |
||||||
|
''' <param name="tagName">The key of the element to add.</param> |
||||||
|
''' <param name="value">The value of the element to add.</param> |
||||||
|
Public Shadows Sub Add(ByVal tagName As String, ByVal value As Type) |
||||||
|
ValidateTagName(tagName) |
||||||
|
ValidateBBCodeElementType(value) |
||||||
|
MyBase.Add(tagName.ToUpperInvariant(), value) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary>This method is reserved and should not be used. When implementing the IXmlSerializable interface, you should return null (Nothing in Visual Basic) from this method, and instead, if specifying a custom schema is required, apply the <see cref="T:System.Xml.Serialization.XmlSchemaProviderAttribute" /> to the class.</summary> |
||||||
|
''' <returns>An <see cref="T:System.Xml.Schema.XmlSchema" /> that describes the XML representation of the object that is produced by the <see cref="M:System.Xml.Serialization.IXmlSerializable.WriteXml(System.Xml.XmlWriter)" /> method and consumed by the <see cref="M:System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader)" /> method.</returns> |
||||||
|
Public Function GetSchema() As System.Xml.Schema.XmlSchema Implements System.Xml.Serialization.IXmlSerializable.GetSchema |
||||||
|
Return Nothing |
||||||
|
End Function |
||||||
|
|
||||||
|
''' <summary>Generates an object from its XML representation.</summary> |
||||||
|
''' <param name="reader">The <see cref="T:System.Xml.XmlReader" /> stream from which the object is deserialized.</param> |
||||||
|
Public Sub ReadXml(ByVal reader As System.Xml.XmlReader) Implements System.Xml.Serialization.IXmlSerializable.ReadXml |
||||||
|
|
||||||
|
'* |
||||||
|
'* Check the name of the element |
||||||
|
'* |
||||||
|
If (reader.NamespaceURI <> STR_BBCodeSchemaNamespace) OrElse (reader.LocalName <> STR_BBCodeElementTypesXmlElement) Then |
||||||
|
Exit Sub |
||||||
|
End If |
||||||
|
|
||||||
|
'* |
||||||
|
'* Reads the items |
||||||
|
'* |
||||||
|
Do While (reader.Read() AndAlso reader.LocalName = STR_ConfigurationItem AndAlso reader.NamespaceURI = STR_BBCodeSchemaNamespace) |
||||||
|
Dim name = reader.GetAttribute("name") |
||||||
|
Dim type = System.Type.GetType(reader.GetAttribute("type")) |
||||||
|
If (type.IsSubclassOf(GetType(BBCodeElement))) Then |
||||||
|
Me.Add(name, type) |
||||||
|
End If |
||||||
|
Loop |
||||||
|
|
||||||
|
If (reader.NodeType = Xml.XmlNodeType.EndElement) Then |
||||||
|
reader.Read() |
||||||
|
End If |
||||||
|
|
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary>Converts an object into its XML representation.</summary> |
||||||
|
''' <param name="writer">The <see cref="T:System.Xml.XmlWriter" /> stream to which the object is serialized.</param> |
||||||
|
<SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", justification:="For human legibility purposes the tagname must be lower case in the configuration file.")> _ |
||||||
|
Public Sub WriteXml(ByVal writer As System.Xml.XmlWriter) Implements System.Xml.Serialization.IXmlSerializable.WriteXml |
||||||
|
|
||||||
|
For Each it In Me |
||||||
|
writer.WriteStartElement(STR_ConfigurationItem, STR_BBCodeSchemaNamespace) |
||||||
|
writer.WriteAttributeString("name", it.Key.ToLower(CultureInfo.InvariantCulture)) |
||||||
|
writer.WriteAttributeString("type", it.Value.AssemblyQualifiedName) |
||||||
|
writer.WriteEndElement() |
||||||
|
Next |
||||||
|
|
||||||
|
End Sub |
||||||
|
|
||||||
|
End Class |
@ -0,0 +1,37 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : BBCodeHtmlGenerator.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 5/2/2009 10:19:43 AM |
||||||
|
' COPYRIGHT : Copyright © 2009 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' TODO: Add file description |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 5/2/2009 10:19:43 AM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Represnts an HTML generator for the <see cref="BBCodeParser"/>. |
||||||
|
''' </summary> |
||||||
|
Public NotInheritable Class BBCodeHtmlFormatter |
||||||
|
Implements ITextFormatter |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Generates the desired text from the specified source. |
||||||
|
''' </summary> |
||||||
|
''' <param name="source">The source to generate the text.</param> |
||||||
|
''' <returns>The text generated by the source.</returns> |
||||||
|
Public Function GenerateText(ByVal source As String) As String Implements ITextFormatter.Format |
||||||
|
Dim sb As New Text.StringBuilder(HtmlEncode(source)) |
||||||
|
sb.Replace(vbCrLf, vbLf) |
||||||
|
sb.Replace(vbCr, String.Empty) |
||||||
|
sb.Replace(vbLf, "<br/>") |
||||||
|
Return sb.ToString() |
||||||
|
End Function |
||||||
|
|
||||||
|
End Class |
@ -0,0 +1,101 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : BBCodeNode.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 4/29/2009 11:30:13 AM |
||||||
|
' COPYRIGHT : Copyright © 2009 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' Represents the basic node of an BBCode document |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 4/29/2009 11:30:13 AM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Represents the basic node of an BBCode document. |
||||||
|
''' </summary> |
||||||
|
Public MustInherit Class BBCodeNode |
||||||
|
|
||||||
|
Private __Parent As BBCodeNode |
||||||
|
Private __Parser As BBCodeParser |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="BBCodeNode" /> class. |
||||||
|
''' This is the default constructor for this class.</summary> |
||||||
|
Protected Sub New() |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="BBCodeNode" /> class.</summary> |
||||||
|
''' <param name="parser">The parser used to create this element.</param> |
||||||
|
Protected Sub New(ByVal parser As BBCodeParser) |
||||||
|
__Parser = parser |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the parent node. |
||||||
|
''' </summary> |
||||||
|
Public ReadOnly Property Parent() As BBCodeNode |
||||||
|
Get |
||||||
|
Return __Parent |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the <see cref="BBCodeParser"/> that create this instance of the <see cref="BBCodeNode"/>. |
||||||
|
''' </summary> |
||||||
|
Protected Friend ReadOnly Property Parser() As BBCodeParser |
||||||
|
Get |
||||||
|
Return __Parser |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' When implemented in a derived class, transforms this instance of <see cref="BBCodeNode"/> into its desired text representation. |
||||||
|
''' </summary> |
||||||
|
''' <param name="formatter">An object that implements the <see cref="ITextFormatter"/> interface.</param> |
||||||
|
''' <returns>The text formatted by the <see cref="ITextFormatter"/>.</returns> |
||||||
|
Public MustOverride Function Format(ByVal formatter As ITextFormatter) As String |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' When implemented in a derived class, gets or sets the inner BBCode. |
||||||
|
''' </summary> |
||||||
|
''' <value>The BBCode between the start and end tags.</value> |
||||||
|
Public MustOverride Property InnerBBCode() As String |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' When implemented in a derived class, gets the outer BBCode. |
||||||
|
''' </summary> |
||||||
|
''' <value>The BBCode of this instance of the <see cref="BBCodeNode"/>.</value> |
||||||
|
Public MustOverride ReadOnly Property OuterBBCode() As String |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' When implemented in a derived class, gets or sets the plain text of the node. |
||||||
|
''' </summary> |
||||||
|
''' <value>The plain text between the start and end tags.</value> |
||||||
|
Public MustOverride Property InnerText() As String |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Sets the <see cref="BBCodeParser"/> of this instance. |
||||||
|
''' </summary> |
||||||
|
''' <param name="parser">The new parser of this instance.</param> |
||||||
|
Friend Sub SetParser(ByVal parser As BBCodeParser) |
||||||
|
__Parser = parser |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' The the parent node of this instance of the <see cref="BBCodeNode"/>. |
||||||
|
''' </summary> |
||||||
|
''' <param name="parentNode">The parent node.</param> |
||||||
|
Protected Friend Sub SetParent(ByVal parentNode As BBCodeNode) |
||||||
|
Dim element = TryCast(parentNode, BBCodeElement) |
||||||
|
If (element Is Nothing) OrElse (String.IsNullOrEmpty(element.Name)) Then |
||||||
|
__Parent = Nothing |
||||||
|
Else |
||||||
|
__Parent = element |
||||||
|
End If |
||||||
|
End Sub |
||||||
|
|
||||||
|
End Class |
@ -0,0 +1,95 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : BBCodeNodeCollection.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 4/29/2009 11:31:52 AM |
||||||
|
' COPYRIGHT : Copyright © 2009 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' TODO: Add file description |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 4/29/2009 11:31:52 AM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Represents a collection of <see cref="BBCodeNode"/>. |
||||||
|
''' </summary> |
||||||
|
Public Class BBCodeNodeCollection |
||||||
|
Inherits ObjectModel.Collection(Of BBCodeNode) |
||||||
|
|
||||||
|
Private __Owner As BBCodeNode |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="BBCodeNodeCollection" /> class. |
||||||
|
''' This is the default constructor for this class.</summary> |
||||||
|
Friend Sub New() |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="BBCodeNodeCollection" /> class.</summary> |
||||||
|
''' <param name="owner">The collection owner.</param> |
||||||
|
''' <exception cref="ArgumentNullException">The argument <paramref name="owner" /> is <langword name="null" />.</exception> |
||||||
|
Friend Sub New(ByVal owner As BBCodeNode) |
||||||
|
If (owner Is Nothing) Then |
||||||
|
Throw New ArgumentNullException("owner") |
||||||
|
End If |
||||||
|
__Owner = owner |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets or sets the owner of the collection. |
||||||
|
''' </summary> |
||||||
|
Friend ReadOnly Property Owner() As BBCodeNode |
||||||
|
Get |
||||||
|
Return __Owner |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary>Adds an object to the end of the <see cref="BBCodeNodeCollection" />.</summary> |
||||||
|
''' <param name="node">The object to be added to the end of the <see cref="BBCodeNodeCollection" />.</param> |
||||||
|
''' <exception cref="ArgumentNullException">The argument <paramref name="node" /> is <langword name="null" />.</exception> |
||||||
|
Public Shadows Sub Add(ByVal node As BBCodeNode) |
||||||
|
If (node Is Nothing) Then |
||||||
|
Throw New ArgumentNullException("node") |
||||||
|
End If |
||||||
|
node.SetParent(Me.Owner) |
||||||
|
MyBase.Add(node) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary>Adds the elements of the specified collection to the end of the <see cref="BBCodeNodeCollection" />.</summary> |
||||||
|
''' <param name="collection">The collection whose elements should be added to the end of the <see cref="BBCodeNodeCollection" />.</param> |
||||||
|
''' <exception cref="ArgumentNullException">The argument <paramref name="collection" /> is <langword name="null" />.</exception> |
||||||
|
Public Shadows Sub AddRange(ByVal collection As IEnumerable(Of BBCodeNode)) |
||||||
|
If (collection Is Nothing) Then |
||||||
|
Throw New ArgumentNullException("collection") |
||||||
|
End If |
||||||
|
For Each n In collection |
||||||
|
Me.Add(n) |
||||||
|
Next |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Inserts an element into the <see cref="BBCodeNodeCollection" /> at the specified index. |
||||||
|
''' </summary> |
||||||
|
''' <param name="index">The zero-based index at which item should be inserted.</param> |
||||||
|
''' <param name="node">The object to insert.</param> |
||||||
|
Public Shadows Sub Insert(ByVal index As Integer, ByVal node As BBCodeNode) |
||||||
|
node.SetParent(Me.Owner) |
||||||
|
MyBase.Insert(index, node) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Inserts the elements of a collection into the <see cref="BBCodeNodeCollection" /> at the specified index. |
||||||
|
''' </summary> |
||||||
|
''' <param name="index">The zero-based index at which item should be inserted.</param> |
||||||
|
''' <param name="collection">The collection whose elements should be inserted into the <see cref="BBCodeNodeCollection" />.</param> |
||||||
|
Public Shadows Sub InsertRange(ByVal index As Integer, ByVal collection As IEnumerable(Of BBCodeNode)) |
||||||
|
For Each node In collection |
||||||
|
node.SetParent(Me.Owner) |
||||||
|
Next |
||||||
|
MyBase.Insert(index, collection) |
||||||
|
End Sub |
||||||
|
|
||||||
|
End Class |
@ -0,0 +1,340 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : BBCodeParser.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 4/29/2009 11:03:53 AM |
||||||
|
' COPYRIGHT : Copyright © 2009 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' TODO: Add file description |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 4/29/2009 11:03:53 AM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
Imports System.Text.RegularExpressions |
||||||
|
Imports System.Diagnostics.CodeAnalysis |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' The parser of |
||||||
|
''' </summary> |
||||||
|
Public NotInheritable Class BBCodeParser |
||||||
|
|
||||||
|
Private __Factory As BBCodeElementFactory |
||||||
|
Private __Configuration As BBCodeConfiguration |
||||||
|
|
||||||
|
Private Shared ReadOnly __ConfigSerializer As New System.Xml.Serialization.XmlSerializer(GetType(BBCodeConfiguration)) |
||||||
|
Private Shared ReadOnly __Tokenizer As Tokenization.Tokenizer = PrepareTokenizer() |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="BBCodeParser" /> class. |
||||||
|
''' This is the default constructor for this class.</summary> |
||||||
|
Public Sub New() |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the dictionary of elements to be replaced by the <see cref="BBCodeParser"/>. |
||||||
|
''' </summary> |
||||||
|
Public ReadOnly Property Dictionary() As BBCodeElementDictionary |
||||||
|
Get |
||||||
|
If (__Configuration Is Nothing) Then |
||||||
|
__Configuration = New BBCodeConfiguration() |
||||||
|
End If |
||||||
|
Return __Configuration.Dictionary |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the dictionary of types created by the parser. |
||||||
|
''' </summary> |
||||||
|
Public ReadOnly Property ElementTypes() As BBCodeElementTypeDictionary |
||||||
|
Get |
||||||
|
If (__Configuration Is Nothing) Then |
||||||
|
__Configuration = New BBCodeConfiguration() |
||||||
|
End If |
||||||
|
Return __Configuration.ElementTypes |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
#Region " LoadConfiguration Methods " |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Loads the configuration from the specified filename. |
||||||
|
''' </summary> |
||||||
|
''' <param name="fileName">The name of the file to read the dictionary from.</param> |
||||||
|
Public Sub LoadConfiguration(ByVal fileName As String) |
||||||
|
If (String.IsNullOrEmpty(fileName)) Then |
||||||
|
Throw New ArgumentNullException("fileName") |
||||||
|
End If |
||||||
|
Using fileStream As New IO.FileStream(fileName, IO.FileMode.Open) |
||||||
|
LoadConfiguration(fileStream) |
||||||
|
End Using |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Loads the configuration from the specified <see cref="IO.Stream"/>. |
||||||
|
''' </summary> |
||||||
|
''' <param name="stream">A <see cref="IO.Stream"/> to read the dictionary from.</param> |
||||||
|
Public Sub LoadConfiguration(ByVal stream As IO.Stream) |
||||||
|
LoadConfiguration(New IO.StreamReader(stream, Text.Encoding.UTF8, True)) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Loads the configuration from the specified <see cref="IO.TextReader"/>. |
||||||
|
''' </summary> |
||||||
|
''' <param name="reader">The <see cref="IO.TextReader"/> to read the dictionary from.</param> |
||||||
|
Public Sub LoadConfiguration(ByVal reader As IO.TextReader) |
||||||
|
Dim dic = __ConfigSerializer.Deserialize(reader) |
||||||
|
If (dic IsNot Nothing) Then |
||||||
|
__Configuration = dic |
||||||
|
End If |
||||||
|
End Sub |
||||||
|
|
||||||
|
#End Region |
||||||
|
|
||||||
|
#Region " SaveConfiguration Methods " |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Saves the conficuration to the specified file. |
||||||
|
''' </summary> |
||||||
|
''' <param name="fileName">The name of the file to save the dictionary.</param> |
||||||
|
Public Sub SaveConfiguration(ByVal fileName As String) |
||||||
|
If (String.IsNullOrEmpty(fileName)) Then |
||||||
|
Throw New ArgumentNullException("fileName") |
||||||
|
End If |
||||||
|
Using fileStream As New IO.FileStream(fileName, IO.FileMode.Create) |
||||||
|
SaveConfiguration(fileStream) |
||||||
|
End Using |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Saves the conficuration to the specified <see cref="IO.Stream"/>. |
||||||
|
''' </summary> |
||||||
|
''' <param name="stream">The <see cref="IO.Stream"/> to save the dictionary.</param> |
||||||
|
Public Sub SaveConfiguration(ByVal stream As IO.Stream) |
||||||
|
SaveConfiguration(New IO.StreamWriter(stream, Text.Encoding.UTF8)) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Saves the conficuration to the specified <see cref="IO.TextWriter"/>. |
||||||
|
''' </summary> |
||||||
|
''' <param name="writer">The <see cref="IO.TextWriter"/> to save the dictionary.</param> |
||||||
|
Public Sub SaveConfiguration(ByVal writer As IO.TextWriter) |
||||||
|
__ConfigSerializer.Serialize(writer, __Configuration) |
||||||
|
End Sub |
||||||
|
|
||||||
|
#End Region |
||||||
|
|
||||||
|
#Region " Parse Methods " |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Parses the specified text, returning a collection of <see cref="BBCodeNode"/>. |
||||||
|
''' </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 |
||||||
|
Using reader As New IO.StringReader(text) |
||||||
|
Return Parse(reader) |
||||||
|
End Using |
||||||
|
End Function |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Parses the specified stream, returning a collection of <see cref="BBCodeNode"/>. |
||||||
|
''' </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 |
||||||
|
Return Parse(stream, Text.Encoding.UTF8) |
||||||
|
End Function |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Parses the specified stream, returning a collection of <see cref="BBCodeNode"/>. |
||||||
|
''' </summary> |
||||||
|
''' <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 |
||||||
|
Return Parse(New IO.StreamReader(stream, encoding)) |
||||||
|
End Function |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Parses the specified <see cref="IO.TextReader"/>, returning a collection of <see cref="BBCodeNode"/>. |
||||||
|
''' </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 |
||||||
|
|
||||||
|
Dim doc = New BBCodeDocument(Me) |
||||||
|
Dim rootElement As New BBCodeElement(Me) |
||||||
|
Dim currentElement As BBCodeElement = rootElement |
||||||
|
|
||||||
|
Dim tk As Tokenization.Token |
||||||
|
Dim sb As New Text.StringBuilder() |
||||||
|
Dim sbText As New Text.StringBuilder() |
||||||
|
Do While (reader.Peek() <> -1) |
||||||
|
Dim line As String = reader.ReadLine() & vbCrLf |
||||||
|
sbText.AppendLine(line) |
||||||
|
Do |
||||||
|
'* |
||||||
|
'* Get the next token |
||||||
|
'* |
||||||
|
tk = Tokenizer.GetToken(line) |
||||||
|
If (tk Is Nothing) Then |
||||||
|
Exit Do |
||||||
|
End If |
||||||
|
|
||||||
|
Dim tag = New BBCodeTag(tk.Value) |
||||||
|
|
||||||
|
ParseElement(rootElement, currentElement, tk, sb, tag) |
||||||
|
Loop |
||||||
|
Loop |
||||||
|
|
||||||
|
'* |
||||||
|
'* Add the text node |
||||||
|
'* |
||||||
|
If (sb.Length > 0) Then |
||||||
|
currentElement.Nodes.Add(New BBCodeText(sb.ToString())) |
||||||
|
End If |
||||||
|
|
||||||
|
'* |
||||||
|
'* Add the nodes to the document |
||||||
|
'* |
||||||
|
doc.Nodes.AddRange(rootElement.Nodes) |
||||||
|
|
||||||
|
'* |
||||||
|
'* Sets the source text |
||||||
|
'* |
||||||
|
doc.SetText(sbText.ToString()) |
||||||
|
|
||||||
|
Return doc |
||||||
|
|
||||||
|
End Function |
||||||
|
|
||||||
|
#End Region |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the <see cref="Tokenization.Tokenizer"/>. |
||||||
|
''' </summary> |
||||||
|
Private Shared ReadOnly Property Tokenizer() As Tokenization.Tokenizer |
||||||
|
Get |
||||||
|
Return __Tokenizer |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the <see cref="BBCodeElementFactory"/>. |
||||||
|
''' </summary> |
||||||
|
Private ReadOnly Property Factory() As BBCodeElementFactory |
||||||
|
Get |
||||||
|
If (__Factory Is Nothing) Then |
||||||
|
__Factory = New BBCodeElementFactory(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) |
||||||
|
|
||||||
|
'* |
||||||
|
'* Check the token Type |
||||||
|
'* |
||||||
|
Select Case token.RuleType |
||||||
|
Case 0, -1 |
||||||
|
'* |
||||||
|
'* Empty tag or char |
||||||
|
'* |
||||||
|
sb.Append(token.Value) |
||||||
|
Case 1 |
||||||
|
'* |
||||||
|
'* Closing tag |
||||||
|
'* |
||||||
|
|
||||||
|
ParseClosingTag(rootElement, currentElement, token, sb, tag) |
||||||
|
Case 2, 3, 4 |
||||||
|
'* |
||||||
|
'* Value Tag, Parametrized Tag, Generic Tag |
||||||
|
'* |
||||||
|
ParseTag(currentElement, sb, tag) |
||||||
|
End Select |
||||||
|
|
||||||
|
End Sub |
||||||
|
|
||||||
|
Private Sub ParseTag(ByRef currentElement As BBCodeElement, 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())) |
||||||
|
sb.Remove(0, sb.Length) |
||||||
|
End If |
||||||
|
|
||||||
|
'* |
||||||
|
'* Add the new element to the list of nodes |
||||||
|
'* |
||||||
|
Dim el = Factory.CreateElement(tag.Name, tag.Paramters) |
||||||
|
currentElement.Nodes.Add(el) |
||||||
|
|
||||||
|
'* |
||||||
|
'* Change the current element, if it requires an closing tag |
||||||
|
'* |
||||||
|
If (el.RequireClosingTag) Then |
||||||
|
currentElement = el |
||||||
|
End If |
||||||
|
|
||||||
|
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) |
||||||
|
|
||||||
|
'* |
||||||
|
'* Check if the closing tag is closing a previously open tag |
||||||
|
'* |
||||||
|
If currentElement.RequireClosingTag AndAlso (String.CompareOrdinal(currentElement.Name, tag.Name) = 0) Then |
||||||
|
'* |
||||||
|
'* Add the inner text |
||||||
|
'* |
||||||
|
If (sb.Length > 0) Then |
||||||
|
currentElement.Nodes.Add(New BBCodeText(sb.ToString())) |
||||||
|
sb.Remove(0, sb.Length) |
||||||
|
End If |
||||||
|
|
||||||
|
'* |
||||||
|
'* Move up a level |
||||||
|
'* |
||||||
|
currentElement = If(currentElement.Parent, rootElement) |
||||||
|
Else |
||||||
|
'* |
||||||
|
'* Adds to the text |
||||||
|
'* |
||||||
|
sb.Append(token.Value) |
||||||
|
End If |
||||||
|
|
||||||
|
End Sub |
||||||
|
|
||||||
|
Private Shared Function PrepareTokenizer() As Tokenization.Tokenizer |
||||||
|
Dim tk As New Tokenization.Tokenizer |
||||||
|
'* |
||||||
|
'* Prepares the BBCode Grammar |
||||||
|
'* |
||||||
|
With tk |
||||||
|
'* |
||||||
|
'* Define the grammar macros |
||||||
|
'* |
||||||
|
AddTokenizerBaseMacros(tk) |
||||||
|
|
||||||
|
'* |
||||||
|
'* Define the grammar rules |
||||||
|
'* |
||||||
|
.AddRule("EmptyTag", 0, "\[{w}\]") |
||||||
|
.AddRule("ClosingTag", 1, "\[/{name}\]") |
||||||
|
.AddRule("ValueTag", 2, "\[{param}\]") |
||||||
|
.AddRule("ParamsTag", 3, "\[{name}{params}\]") |
||||||
|
.AddRule("Tag", 4, "\[[^ \t\r\n\f\]]+?\]") |
||||||
|
.AddRule("Char", -1, ".") |
||||||
|
End With |
||||||
|
Return tk |
||||||
|
End Function |
||||||
|
|
||||||
|
End Class |
@ -0,0 +1,239 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : BBCodeTag.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 4/30/2009 10:14:00 AM |
||||||
|
' COPYRIGHT : Copyright © 2009 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' TODO: Add file description |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 4/30/2009 10:14:00 AM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
Imports System.Text.RegularExpressions |
||||||
|
Imports System.Diagnostics.CodeAnalysis |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Helper class to parse a BBCode tag. |
||||||
|
''' </summary> |
||||||
|
Friend NotInheritable Class BBCodeTag |
||||||
|
|
||||||
|
Private Shared ReadOnly __Tokenizer As Tokenization.Tokenizer = PrepareTokenizer() |
||||||
|
|
||||||
|
Private __Text As String |
||||||
|
Private __TagName As String |
||||||
|
Private __IsClosingTag As Boolean |
||||||
|
Private __Params As New BBCodeAttributeDictionary |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="BBCodeTag" /> class.</summary> |
||||||
|
''' <param name="text">The text that defines the tag.</param> |
||||||
|
Public Sub New(ByVal text As String) |
||||||
|
__Text = text |
||||||
|
|
||||||
|
'* |
||||||
|
'* Read each token to the tag |
||||||
|
'* |
||||||
|
Dim sb As New Text.StringBuilder() |
||||||
|
Dim addParam As Boolean |
||||||
|
Dim paramName As String = String.Empty |
||||||
|
Do |
||||||
|
Dim tk = Tokenizer.GetToken(text) |
||||||
|
If (tk Is Nothing) Then |
||||||
|
Exit Do |
||||||
|
End If |
||||||
|
|
||||||
|
Select Case tk.RuleType |
||||||
|
Case -1 |
||||||
|
'* |
||||||
|
'* Check if it's a closing tag |
||||||
|
'* |
||||||
|
If (String.CompareOrdinal(tk.Name, "EndTagStart") = 0) Then |
||||||
|
__IsClosingTag = True |
||||||
|
End If |
||||||
|
Case 0 |
||||||
|
'* |
||||||
|
'* Whitespace, ignoring |
||||||
|
'* |
||||||
|
Case 1 |
||||||
|
'* |
||||||
|
'* Name. it can be the name of the tag, or the name of a parameter |
||||||
|
'* |
||||||
|
If (String.IsNullOrEmpty(__TagName)) Then |
||||||
|
__TagName = tk.Value.ToUpperInvariant() |
||||||
|
Else |
||||||
|
'* |
||||||
|
'* Check if the paramName is already filled |
||||||
|
'* |
||||||
|
If (Not addParam) Then |
||||||
|
paramName = tk.Value |
||||||
|
Me.Paramters(paramName) = String.Empty |
||||||
|
ElseIf (addParam) Then |
||||||
|
'* |
||||||
|
'* Add the parameter and it's value |
||||||
|
'* |
||||||
|
addParam = False |
||||||
|
AddParamFromToken(paramName, tk) |
||||||
|
End If |
||||||
|
End If |
||||||
|
Case 2 |
||||||
|
'* |
||||||
|
'* Finds the equals sign |
||||||
|
'* |
||||||
|
addParam = True |
||||||
|
Case 3 |
||||||
|
'* |
||||||
|
'* Value: the value of a parameter |
||||||
|
'* |
||||||
|
If (addParam) Then |
||||||
|
addParam = False |
||||||
|
AddParamFromToken(paramName, tk) |
||||||
|
End If |
||||||
|
Case Else |
||||||
|
sb.Append(tk.Value) |
||||||
|
End Select |
||||||
|
Loop |
||||||
|
|
||||||
|
If (sb.Length > 0 AndAlso String.IsNullOrEmpty(__TagName)) Then |
||||||
|
__TagName = sb.ToString() |
||||||
|
End If |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the text of the tag. |
||||||
|
''' </summary> |
||||||
|
<SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")> _ |
||||||
|
Public ReadOnly Property Text() As String |
||||||
|
Get |
||||||
|
Return __Text |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the name of the tag. |
||||||
|
''' </summary> |
||||||
|
Public ReadOnly Property Name() As String |
||||||
|
Get |
||||||
|
Return __TagName |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Indicates wheter or not the tag is an empty tag. |
||||||
|
''' </summary> |
||||||
|
''' <value><c>True</c> if the tag is empty; otherwise <c>False</c>.</value> |
||||||
|
<SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Provide description of the object.")> _ |
||||||
|
Public ReadOnly Property IsEmptyTag() As Boolean |
||||||
|
Get |
||||||
|
Return String.IsNullOrEmpty(Name) |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Indicates wheter or not the tag is a closing tag. |
||||||
|
''' </summary> |
||||||
|
''' <value><c>True</c> if the tag is a closing tag; otherwise <c>False</c>.</value> |
||||||
|
<SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Provide description of the object.")> _ |
||||||
|
Public ReadOnly Property IsClosingTag() As Boolean |
||||||
|
Get |
||||||
|
Return __IsClosingTag |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Indicates wheter or not the tag is a value tag. |
||||||
|
''' </summary> |
||||||
|
''' <value><c>True</c> if the tag is a value tag; otherwise <c>False</c>.</value> |
||||||
|
<SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Provide description of the object.")> _ |
||||||
|
Public ReadOnly Property IsValueTag() As Boolean |
||||||
|
Get |
||||||
|
Return Me.Paramters.Count = 1 AndAlso Me.Paramters.Keys(0) = "default" |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Indicates wheter or not the tag is a parametrized tag. |
||||||
|
''' </summary> |
||||||
|
''' <value><c>True</c> if the tag is a parametrized tag; otherwise <c>False</c>.</value> |
||||||
|
<SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Provide description of the object.")> _ |
||||||
|
Public ReadOnly Property IsParamTag() As Boolean |
||||||
|
Get |
||||||
|
Return Me.Paramters.Count > 0 |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Indicates wheter or not the tag is a tag. |
||||||
|
''' </summary> |
||||||
|
''' <value><c>True</c> if the tag is a tag; otherwise <c>False</c>.</value> |
||||||
|
<SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Provide description of the object.")> _ |
||||||
|
Public ReadOnly Property IsTag() As Boolean |
||||||
|
Get |
||||||
|
Return (Not Me.IsEmptyTag) AndAlso (Not Me.IsClosingTag) |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the paramters of the tag. |
||||||
|
''' </summary> |
||||||
|
Public ReadOnly Property Paramters() As BBCodeAttributeDictionary |
||||||
|
Get |
||||||
|
Return __Params |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the <see cref="Tokenization.Tokenizer"/>. |
||||||
|
''' </summary> |
||||||
|
Private Shared ReadOnly Property Tokenizer() As Tokenization.Tokenizer |
||||||
|
Get |
||||||
|
Return __Tokenizer |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
Private Sub AddParamFromToken(ByRef paramName As String, ByVal tk As Tokenization.Token) |
||||||
|
|
||||||
|
If (String.IsNullOrEmpty(paramName)) Then |
||||||
|
Me.Paramters("default") = UnQuote(tk.Value) |
||||||
|
Else |
||||||
|
Me.Paramters(paramName) = UnQuote(tk.Value) |
||||||
|
End If |
||||||
|
paramName = String.Empty |
||||||
|
|
||||||
|
End Sub |
||||||
|
|
||||||
|
Private Shared Function PrepareTokenizer() As Tokenization.Tokenizer |
||||||
|
|
||||||
|
Dim tk As New Tokenization.Tokenizer |
||||||
|
|
||||||
|
'* |
||||||
|
'* Prepares the BBCode Grammar |
||||||
|
'* |
||||||
|
With tk |
||||||
|
'* |
||||||
|
'* Define the grammar macros |
||||||
|
'* |
||||||
|
AddTokenizerBaseMacros(tk) |
||||||
|
|
||||||
|
'* |
||||||
|
'* Define the grammar rules |
||||||
|
'* |
||||||
|
.AddRule("TagStart", -1, "\[") |
||||||
|
.AddRule("EndTagStart", -1, "\[/") |
||||||
|
.AddRule("TagEnd", -1, "\]") |
||||||
|
.AddRule("Space", 0, "{w}") |
||||||
|
.AddRule("Name", 1, "{name}") |
||||||
|
.AddRule("Equals", 2, "{w}={w}") |
||||||
|
.AddRule("Value", 3, "{value}") |
||||||
|
.AddRule("Text", 99, ".") |
||||||
|
End With |
||||||
|
|
||||||
|
Return tk |
||||||
|
|
||||||
|
End Function |
||||||
|
|
||||||
|
End Class |
@ -0,0 +1,81 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : BBCodeText.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 4/29/2009 2:20:10 PM |
||||||
|
' COPYRIGHT : Copyright © 2009 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' TODO: Add file description |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 4/29/2009 2:20:10 PM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Represents a simple text in the BBCode. |
||||||
|
''' </summary> |
||||||
|
Public NotInheritable Class BBCodeText |
||||||
|
Inherits BBCodeNode |
||||||
|
|
||||||
|
Private __InnerText As String |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="BBCodeText" /> class. |
||||||
|
''' This is the default constructor for this class.</summary> |
||||||
|
Friend Sub New() |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="BBCodeText" /> class.</summary> |
||||||
|
''' <param name="text">The text of the <see cref="BBCodeText"/>.</param> |
||||||
|
Friend Sub New(ByVal text As String) |
||||||
|
Me.InnerText = text |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary>Transforms this instance of <see cref="BBCodeText" /> into its desired text representation.</summary> |
||||||
|
''' <param name="formatter">An object that implements the <see cref="ITextFormatter" /> interface.</param> |
||||||
|
''' <returns>The text formatted by the <see cref="ITextFormatter" />.</returns> |
||||||
|
Public Overrides Function Format(ByVal formatter As ITextFormatter) As String |
||||||
|
Return formatter.Format(__InnerText) |
||||||
|
End Function |
||||||
|
|
||||||
|
''' <summary>Gets or sets the inner BBCode.</summary> |
||||||
|
''' <value>The BBCode between the start and end tags.</value> |
||||||
|
Public Overrides Property InnerBBCode() As String |
||||||
|
Get |
||||||
|
Return Me.InnerText |
||||||
|
End Get |
||||||
|
Set(ByVal value As String) |
||||||
|
Me.InnerText = value |
||||||
|
End Set |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary>Gets or sets the plain text of the node.</summary> |
||||||
|
''' <value>The plain text between the start and end tags.</value> |
||||||
|
Public Overrides Property InnerText() As String |
||||||
|
Get |
||||||
|
Return __InnerText |
||||||
|
End Get |
||||||
|
Set(ByVal value As String) |
||||||
|
__InnerText = value |
||||||
|
End Set |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary>Gets the outer BBCode.</summary> |
||||||
|
''' <value>The BBCode of this instance of the <see cref="BBCodeNode" /> .</value> |
||||||
|
Public Overrides ReadOnly Property OuterBBCode() As String |
||||||
|
Get |
||||||
|
Return Me.InnerText |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary>Returns a <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />.</summary> |
||||||
|
''' <returns>A <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />.</returns> |
||||||
|
''' <filterpriority>2</filterpriority> |
||||||
|
Public Overrides Function ToString() As String |
||||||
|
Return Me.InnerText |
||||||
|
End Function |
||||||
|
|
||||||
|
End Class |
@ -0,0 +1,107 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : CircularReferenceException.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 9/30/2007 12:12:13 AM |
||||||
|
' COPYRIGHT : Copyright © 2007 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' Represents an error when a macro has a circular reference. |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 9/30/2007 12:12:13 AM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
Imports System.Runtime.Serialization |
||||||
|
Imports System.Security.Permissions |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Represents an error when a macro has a circular reference. |
||||||
|
''' </summary> |
||||||
|
<Serializable()> _ |
||||||
|
Public Class CircularReferenceException |
||||||
|
Inherits Exception |
||||||
|
|
||||||
|
Dim __Path As String |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="CircularReferenceException" /> class. |
||||||
|
''' This is the default constructor for this class.</summary> |
||||||
|
Public Sub New() |
||||||
|
MyBase.New(My.Resources.CircularReferenceException_Message) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="CircularReferenceException" /> class.</summary> |
||||||
|
''' <param name="circularReferencePath ">The path of the circular reference.</param> |
||||||
|
Public Sub New(ByVal circularReferencePath As String) |
||||||
|
MyBase.New(My.Resources.CircularReferenceException_Message) |
||||||
|
__Path = circularReferencePath.Replace("}{", "} -> {") |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary>Initializes a new instance of the <see cref="CircularReferenceException" /> class with a specified error message and a reference to the inner exception that is the cause of this exception.</summary> |
||||||
|
''' <param name="circularReferencePath ">The path of the circular reference.</param> |
||||||
|
''' <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param> |
||||||
|
Public Sub New(ByVal circularReferencePath As String, ByVal innerException As System.Exception) |
||||||
|
MyBase.New(My.Resources.CircularReferenceException_Message, innerException) |
||||||
|
__Path = circularReferencePath.Replace("}{", "} -> {") |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Initializes an instance of the <see cref="CircularReferenceException" /> class. |
||||||
|
''' </summary> |
||||||
|
''' <param name="message">The message that describes the error.</param> |
||||||
|
''' <param name="circularReferencePath ">The path of the circular reference.</param> |
||||||
|
Public Sub New(ByVal message As String, ByVal circularReferencePath As String) |
||||||
|
MyBase.New(message) |
||||||
|
__Path = circularReferencePath.Replace("}{", "} -> {") |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Initializes an instance of the <see cref="CircularReferenceException" /> class. |
||||||
|
''' </summary> |
||||||
|
''' <param name="message">The message that describes the error.</param> |
||||||
|
''' <param name="circularReferencePath ">The path of the circular reference.</param> |
||||||
|
''' <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param> |
||||||
|
Public Sub New(ByVal message As String, ByVal circularReferencePath As String, ByVal innerException As System.Exception) |
||||||
|
MyBase.New(message, innerException) |
||||||
|
__Path = circularReferencePath.Replace("}{", "} -> {") |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary>Initializes a new instance of the <see cref="CircularReferenceException" /> class with serialized data.</summary> |
||||||
|
''' <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that holds the serialized object data about the exception being thrown.</param> |
||||||
|
''' <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext" /> that contains contextual information about the source or destination.</param> |
||||||
|
''' <exception cref="T:System.ArgumentNullException">The <paramref name="info" /> parameter is null.</exception> |
||||||
|
''' <exception cref="T:System.Runtime.Serialization.SerializationException">The class name is null or <see cref="P:System.CircularReferenceException.HResult" /> is zero (0).</exception> |
||||||
|
Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext) |
||||||
|
MyBase.New(info, context) |
||||||
|
__Path = info.GetString("__Path") |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the path of the circular reference. |
||||||
|
''' </summary> |
||||||
|
''' <value>The path of the circular reference.</value> |
||||||
|
Public ReadOnly Property CircularReferencePath() As String |
||||||
|
Get |
||||||
|
Return __Path |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary>When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo" /> with information about the exception.</summary> |
||||||
|
''' <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that holds the serialized object data about the exception being thrown.</param> |
||||||
|
''' <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext" /> that contains contextual information about the source or destination.</param> |
||||||
|
''' <exception cref="T:System.ArgumentNullException">The <paramref name="info" /> parameter is a null reference (Nothing in Visual Basic).</exception> |
||||||
|
''' <filterpriority>2</filterpriority> |
||||||
|
''' <PermissionSet> |
||||||
|
''' <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="*AllFiles*" PathDiscovery="*AllFiles*" /> |
||||||
|
''' <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="SerializationFormatter" /> |
||||||
|
''' </PermissionSet> |
||||||
|
<SecurityPermission(SecurityAction.LinkDemand, flags:=SecurityPermissionFlag.SerializationFormatter)> _ |
||||||
|
Public Overrides Sub GetObjectData(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext) |
||||||
|
MyBase.GetObjectData(info, context) |
||||||
|
info.AddValue("__Path", __Path, GetType(String)) |
||||||
|
End Sub |
||||||
|
|
||||||
|
End Class |
@ -0,0 +1,120 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : ReferencedMacroNotFoundException.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 9/29/2007 11:40:10 PM |
||||||
|
' COPYRIGHT : Copyright © 2007 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' Represents an error when a macro reference |
||||||
|
' an unknown macro. |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 9/29/2007 11:40:10 PM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
Imports System.Globalization |
||||||
|
Imports System.Runtime.Serialization |
||||||
|
Imports System.Security.Permissions |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Represents an error when a referenced macro is not found in the collection. |
||||||
|
''' </summary> |
||||||
|
<Serializable()> _ |
||||||
|
Public Class ReferencedMacroNotFoundException |
||||||
|
Inherits Exception |
||||||
|
|
||||||
|
Private __ReferencedMacroName As String |
||||||
|
|
||||||
|
#Region " Constructors " |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Initializes an instance of the <see cref="ReferencedMacroNotFoundException" /> class. |
||||||
|
''' This is the default constructor for this class. |
||||||
|
''' </summary> |
||||||
|
Public Sub New() |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Initializes an instance of the <see cref="ReferencedMacroNotFoundException" /> class. |
||||||
|
''' </summary> |
||||||
|
''' <param name="referencedMacroName">The name of the macro not found.</param> |
||||||
|
Public Sub New(ByVal referencedMacroName As String) |
||||||
|
Me.New(String.Format(CultureInfo.InvariantCulture, My.Resources.ReferencedMacroNotFoundException_Message, referencedMacroName), referencedMacroName) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Initializes an instance of the <see cref="ReferencedMacroNotFoundException" /> class. |
||||||
|
''' </summary> |
||||||
|
''' <param name="message">The message that describes the error.</param> |
||||||
|
''' <param name="referencedMacroName">The name of the macro not found.</param> |
||||||
|
Public Sub New(ByVal message As String, ByVal referencedMacroName As String) |
||||||
|
MyBase.New(message) |
||||||
|
__ReferencedMacroName = referencedMacroName |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Initializes an instance of the <see cref="ReferencedMacroNotFoundException" /> class. |
||||||
|
''' </summary> |
||||||
|
''' <param name="message">The message that describes the error.</param> |
||||||
|
''' <param name="innerException">The exception that is the cause of the current exception, or a <langword name="null"/> if no inner exception is specified.</param> |
||||||
|
Public Sub New(ByVal message As String, ByVal innerException As Exception) |
||||||
|
MyBase.New(message, innerException) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Initializes an instance of the <see cref="ReferencedMacroNotFoundException" /> class. |
||||||
|
''' </summary> |
||||||
|
''' <param name="message">The message that describes the error.</param> |
||||||
|
''' <param name="referencedMacroName">The name of the macro not found.</param> |
||||||
|
''' <param name="innerException">The exception that is the cause of the current exception, or a <langword name="null"/> if no inner exception is specified.</param> |
||||||
|
Public Sub New(ByVal message As String, ByVal referencedMacroName As String, ByVal innerException As Exception) |
||||||
|
Me.New(message, innerException) |
||||||
|
__ReferencedMacroName = referencedMacroName |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary>Initializes a new instance of the <see cref="CircularReferenceException" /> class with serialized data.</summary> |
||||||
|
''' <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that holds the serialized object data about the exception being thrown.</param> |
||||||
|
''' <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext" /> that contains contextual information about the source or destination.</param> |
||||||
|
''' <exception cref="T:System.ArgumentNullException">The <paramref name="info" /> parameter is null.</exception> |
||||||
|
''' <exception cref="T:System.Runtime.Serialization.SerializationException">The class name is null or <see cref="P:System.CircularReferenceException.HResult" /> is zero (0).</exception> |
||||||
|
Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext) |
||||||
|
MyBase.New(info, context) |
||||||
|
__ReferencedMacroName = info.GetString("__ReferencedMacroName") |
||||||
|
End Sub |
||||||
|
|
||||||
|
#End Region |
||||||
|
|
||||||
|
#Region " Public Properties " |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the name of the referenced macro not found in the collection. |
||||||
|
''' </summary> |
||||||
|
''' <value>The name of the referenced macro not found in the collection.</value> |
||||||
|
Public ReadOnly Property ReferencedMacroName() As String |
||||||
|
Get |
||||||
|
Return __ReferencedMacroName |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
#End Region |
||||||
|
|
||||||
|
''' <summary>When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo" /> with information about the exception.</summary> |
||||||
|
''' <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that holds the serialized object data about the exception being thrown.</param> |
||||||
|
''' <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext" /> that contains contextual information about the source or destination.</param> |
||||||
|
''' <exception cref="T:System.ArgumentNullException">The <paramref name="info" /> parameter is a null reference (Nothing in Visual Basic).</exception> |
||||||
|
''' <filterpriority>2</filterpriority> |
||||||
|
''' <PermissionSet> |
||||||
|
''' <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="*AllFiles*" PathDiscovery="*AllFiles*" /> |
||||||
|
''' <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="SerializationFormatter" /> |
||||||
|
''' </PermissionSet> |
||||||
|
<SecurityPermission(SecurityAction.LinkDemand, flags:=SecurityPermissionFlag.SerializationFormatter)> _ |
||||||
|
Public Overrides Sub GetObjectData(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext) |
||||||
|
MyBase.GetObjectData(info, context) |
||||||
|
info.AddValue("__ReferencedMacroName", __ReferencedMacroName, GetType(String)) |
||||||
|
End Sub |
||||||
|
|
||||||
|
End Class |
@ -0,0 +1,161 @@ |
|||||||
|
Imports System.Text |
||||||
|
Imports System.Text.RegularExpressions |
||||||
|
Imports System.Collections.Generic |
||||||
|
Imports System.Globalization |
||||||
|
Imports System.Collections.Specialized |
||||||
|
|
||||||
|
Namespace Tokenization |
||||||
|
''' <summary> |
||||||
|
''' Represents a Tokenizer MACRO. |
||||||
|
''' </summary> |
||||||
|
Public Structure Macro |
||||||
|
|
||||||
|
#Region " Private Variables " |
||||||
|
|
||||||
|
Private Const __MacroNamePattern As String = "\{(?<name>[_A-Z].*?)\}" |
||||||
|
Private __Name As String |
||||||
|
Private __Pattern As String |
||||||
|
Private __ExpandedPattern As String |
||||||
|
Private __References As StringCollection |
||||||
|
Private __CircularReferencePath As String |
||||||
|
|
||||||
|
#End Region |
||||||
|
|
||||||
|
#Region " Public Properties " |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets or sets the name of the macro. |
||||||
|
''' </summary> |
||||||
|
''' <value>The name of the macro.</value> |
||||||
|
''' <exception cref="ArgumentException">The specified name of the macro contains invalid characters.</exception> |
||||||
|
''' <exception cref="ArgumentNullException">The argument <paramref name="value" /> is <langword name="null" />.</exception> |
||||||
|
Public Property Name() As String |
||||||
|
Get |
||||||
|
Return __Name |
||||||
|
End Get |
||||||
|
Set(ByVal value As String) |
||||||
|
If (String.IsNullOrEmpty(value)) Then |
||||||
|
Throw New ArgumentNullException("value") |
||||||
|
End If |
||||||
|
If ((value.IndexOf("{", StringComparison.Ordinal) <> (-1)) OrElse (value.IndexOf("}", StringComparison.Ordinal) <> (-1))) Then |
||||||
|
Throw New ArgumentException(String.Format(CultureInfo.InvariantCulture, My.Resources.Name_ArgumentException_Message, "macro"), "value") |
||||||
|
End If |
||||||
|
__Name = value |
||||||
|
End Set |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets or sets the pattern of the macro. |
||||||
|
''' </summary> |
||||||
|
''' <value>The pattern of the macro.</value> |
||||||
|
''' <exception cref="ArgumentNullException">The argument <paramref name="value" /> is <langword name="null" />.</exception> |
||||||
|
Public Property Pattern() As String |
||||||
|
Get |
||||||
|
Return __Pattern |
||||||
|
End Get |
||||||
|
Set(ByVal value As String) |
||||||
|
If (String.IsNullOrEmpty(value)) Then |
||||||
|
Throw New ArgumentNullException("value") |
||||||
|
End If |
||||||
|
|
||||||
|
'* |
||||||
|
'* Set the references |
||||||
|
'* |
||||||
|
Dim mc As MatchCollection = Regex.Matches(value, __MacroNamePattern, RegexOptions.IgnoreCase) |
||||||
|
Me.References.Clear() |
||||||
|
For Each m As Match In mc |
||||||
|
Me.References.Add(m.Groups("name").Value) |
||||||
|
Next |
||||||
|
|
||||||
|
'* |
||||||
|
'* Set the property |
||||||
|
'* |
||||||
|
__Pattern = value |
||||||
|
End Set |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the expanded pattern of the macro. |
||||||
|
''' </summary> |
||||||
|
''' <value>The expanded pattern of the macro.</value> |
||||||
|
Public ReadOnly Property ExpandedPattern() As String |
||||||
|
Get |
||||||
|
If (String.IsNullOrEmpty(__ExpandedPattern)) Then |
||||||
|
Return __Pattern |
||||||
|
End If |
||||||
|
Return __ExpandedPattern |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets a list of macro names referenced by this macro. |
||||||
|
''' </summary> |
||||||
|
''' <value>A list of macro names referenced by this macro.</value> |
||||||
|
Public ReadOnly Property References() As StringCollection |
||||||
|
Get |
||||||
|
If (__References Is Nothing) Then |
||||||
|
__References = New StringCollection() |
||||||
|
End If |
||||||
|
Return __References |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
#End Region |
||||||
|
|
||||||
|
#Region " Friend Properties " |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets a value indicating whether this instance is expanded. |
||||||
|
''' </summary> |
||||||
|
''' <value> |
||||||
|
''' <c>true</c> if this instance is expanded; otherwise, <c>false</c>. |
||||||
|
''' </value> |
||||||
|
Friend ReadOnly Property IsExpanded() As Boolean |
||||||
|
Get |
||||||
|
Return Not String.IsNullOrEmpty(__ExpandedPattern) |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
#End Region |
||||||
|
|
||||||
|
#Region " Friend Methods " |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Sets the expanded pattern of the macro. |
||||||
|
''' </summary> |
||||||
|
''' <param name="pattern">The pattern of the macro.</param> |
||||||
|
Friend Sub SetExpandedPattern(ByVal pattern As String) |
||||||
|
__ExpandedPattern = pattern |
||||||
|
End Sub |
||||||
|
|
||||||
|
#End Region |
||||||
|
|
||||||
|
''' <summary>Indicates whether this instance and a specified object are equal.</summary> |
||||||
|
''' <returns>true if <paramref name="obj" /> and this instance are the same type and represent the same value; otherwise, false.</returns> |
||||||
|
''' <param name="obj">Another object to compare to.</param> |
||||||
|
''' <filterpriority>2</filterpriority> |
||||||
|
Public Overrides Function Equals(ByVal obj As Object) As Boolean |
||||||
|
If (TypeOf obj Is Macro) Then |
||||||
|
Return Me.Name = obj.Name AndAlso Me.Pattern = obj.Pattern |
||||||
|
End If |
||||||
|
Return False |
||||||
|
End Function |
||||||
|
|
||||||
|
''' <summary>Returns the hash code for this instance.</summary> |
||||||
|
''' <returns>A 32-bit signed integer that is the hash code for this instance.</returns> |
||||||
|
''' <filterpriority>2</filterpriority> |
||||||
|
Public Overrides Function GetHashCode() As Integer |
||||||
|
Dim hash As Long = Me.Name.GetHashCode() + Me.Pattern.GetHashCode() |
||||||
|
Return hash And Integer.MinValue |
||||||
|
End Function |
||||||
|
|
||||||
|
Public Shared Operator =(ByVal left As Macro, ByVal right As Macro) As Boolean |
||||||
|
Return left.Equals(right) |
||||||
|
End Operator |
||||||
|
|
||||||
|
Public Shared Operator <>(ByVal left As Macro, ByVal right As Macro) As Boolean |
||||||
|
Return Not left = right |
||||||
|
End Operator |
||||||
|
|
||||||
|
End Structure |
||||||
|
End Namespace |
@ -0,0 +1,37 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : MacroCollection.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 4/30/2009 1:07:21 PM |
||||||
|
' COPYRIGHT : Copyright © 2009 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' TODO: Add file description |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 4/30/2009 1:07:21 PM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
Imports System.Collections.ObjectModel |
||||||
|
|
||||||
|
Namespace Tokenization |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' A read-only collection of <see cref="Macro"/>. |
||||||
|
''' </summary> |
||||||
|
Public NotInheritable Class MacroCollection |
||||||
|
Inherits ReadOnlyCollection(Of Macro) |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="MacroCollection" /> class.</summary> |
||||||
|
''' <param name="items">The items of the collection.</param> |
||||||
|
Friend Sub New(ByVal items As IEnumerable(Of Macro)) |
||||||
|
MyBase.New(items) |
||||||
|
End Sub |
||||||
|
|
||||||
|
End Class |
||||||
|
|
||||||
|
End Namespace |
||||||
|
|
@ -0,0 +1,201 @@ |
|||||||
|
Imports System.Text |
||||||
|
Imports System.Text.RegularExpressions |
||||||
|
Imports System.Collections.Generic |
||||||
|
Imports System.Globalization |
||||||
|
Imports System.Collections.Specialized |
||||||
|
|
||||||
|
Namespace Tokenization |
||||||
|
''' <summary> |
||||||
|
''' Represents a Tokenizer RULE. |
||||||
|
''' </summary> |
||||||
|
Public Structure Rule |
||||||
|
|
||||||
|
#Region " Private Variables " |
||||||
|
|
||||||
|
Private Const __MacroNamePattern As String = "\{(?<name>[_A-Z].*?)\}" |
||||||
|
|
||||||
|
Private __Name As String |
||||||
|
Private __Type As Integer |
||||||
|
Private __Pattern As String |
||||||
|
Private __ExpandedPattern As String |
||||||
|
Private __References As StringCollection |
||||||
|
Private __RegexOptions As Text.RegularExpressions.RegexOptions |
||||||
|
Private __Regex As Text.RegularExpressions.Regex |
||||||
|
|
||||||
|
#End Region |
||||||
|
|
||||||
|
#Region " Public Properties " |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets or sets the name of the rule. |
||||||
|
''' </summary> |
||||||
|
''' <value>The name of the rule.</value> |
||||||
|
''' <exception cref="ArgumentException">The specified name of the rule contains invalid characters.</exception> |
||||||
|
''' <exception cref="ArgumentNullException">The argument <paramref name="value" /> is <langword name="null" />.</exception> |
||||||
|
Public Property Name() As String |
||||||
|
Get |
||||||
|
Return __Name |
||||||
|
End Get |
||||||
|
Set(ByVal value As String) |
||||||
|
If (String.IsNullOrEmpty(value)) Then |
||||||
|
Throw New ArgumentNullException("value") |
||||||
|
End If |
||||||
|
If ((value.IndexOf("{", StringComparison.Ordinal) <> (-1)) OrElse (value.IndexOf("}", StringComparison.Ordinal) <> (-1))) Then |
||||||
|
Throw New ArgumentException(String.Format(CultureInfo.InvariantCulture, My.Resources.Name_ArgumentException_Message, "rule", "value")) |
||||||
|
End If |
||||||
|
__Name = value |
||||||
|
End Set |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets or sets the type of the rule. |
||||||
|
''' </summary> |
||||||
|
''' <value>The type of the rule.</value> |
||||||
|
''' <remarks> |
||||||
|
''' The type of the rule is an implementation-specific value that has no meaning outside such implementation. |
||||||
|
''' </remarks> |
||||||
|
Public Property RuleType() As Integer |
||||||
|
Get |
||||||
|
Return __Type |
||||||
|
End Get |
||||||
|
Set(ByVal value As Integer) |
||||||
|
__Type = value |
||||||
|
End Set |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets or sets the pattern of the rule. |
||||||
|
''' </summary> |
||||||
|
''' <value>The pattern of the rule.</value> |
||||||
|
''' <exception cref="ArgumentNullException">The argument <paramref name="value" /> is <langword name="null" />.</exception> |
||||||
|
Public Property Pattern() As String |
||||||
|
Get |
||||||
|
Return __Pattern |
||||||
|
End Get |
||||||
|
Set(ByVal value As String) |
||||||
|
If (String.IsNullOrEmpty(value)) Then |
||||||
|
Throw New ArgumentNullException("value") |
||||||
|
End If |
||||||
|
|
||||||
|
'* |
||||||
|
'* Set the references |
||||||
|
'* |
||||||
|
Dim mc As MatchCollection = RegEx.Matches(value, __MacroNamePattern, RegexOptions.IgnoreCase) |
||||||
|
Me.References.Clear() |
||||||
|
For Each m As Match In mc |
||||||
|
Me.References.Add(m.Groups("name").Value) |
||||||
|
Next |
||||||
|
|
||||||
|
'* |
||||||
|
'* Set the property |
||||||
|
'* |
||||||
|
__Pattern = value |
||||||
|
End Set |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the expanded pattern of the rule. |
||||||
|
''' </summary> |
||||||
|
''' <value>The expanded pattern of the rule.</value> |
||||||
|
Public ReadOnly Property ExpandedPattern() As String |
||||||
|
Get |
||||||
|
If (String.IsNullOrEmpty(__ExpandedPattern)) Then |
||||||
|
Return __Pattern |
||||||
|
End If |
||||||
|
Return __ExpandedPattern |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets a list of rule names referenced by this rule. |
||||||
|
''' </summary> |
||||||
|
''' <value>A list of rule names referenced by this rule.</value> |
||||||
|
Public ReadOnly Property References() As StringCollection |
||||||
|
Get |
||||||
|
If (__References Is Nothing) Then |
||||||
|
__References = New StringCollection() |
||||||
|
End If |
||||||
|
Return __References |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the regular expression used to validate this rule. |
||||||
|
''' </summary> |
||||||
|
''' <value>A <see cref="Text.RegularExpressions.Regex"/> object used to validate this rule.</value> |
||||||
|
Public ReadOnly Property Regex() As Text.RegularExpressions.Regex |
||||||
|
Get |
||||||
|
If (Not Me.IsExpanded) Then |
||||||
|
Return Nothing |
||||||
|
End If |
||||||
|
If (__Regex Is Nothing) Then |
||||||
|
If (Me.ExpandedPattern.StartsWith("^", StringComparison.Ordinal)) Then |
||||||
|
__Regex = New Text.RegularExpressions.Regex(Me.ExpandedPattern, __RegexOptions) |
||||||
|
Else |
||||||
|
__Regex = New Text.RegularExpressions.Regex("^" & Me.ExpandedPattern, __RegexOptions) |
||||||
|
End If |
||||||
|
End If |
||||||
|
Return __Regex |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
#End Region |
||||||
|
|
||||||
|
#Region " Friend Properties " |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets a value indicating whether this instance is expanded. |
||||||
|
''' </summary> |
||||||
|
''' <value> |
||||||
|
''' <c>true</c> if this instance is expanded; otherwise, <c>false</c>. |
||||||
|
''' </value> |
||||||
|
Friend ReadOnly Property IsExpanded() As Boolean |
||||||
|
Get |
||||||
|
Return Not String.IsNullOrEmpty(__ExpandedPattern) |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
#End Region |
||||||
|
|
||||||
|
#Region " Friend Methods " |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Sets the expanded pattern of the rule. |
||||||
|
''' </summary> |
||||||
|
''' <param name="pattern">The pattern of the rule.</param> |
||||||
|
Friend Sub SetExpandedPattern(ByVal pattern As String, ByVal options As Text.RegularExpressions.RegexOptions) |
||||||
|
__ExpandedPattern = pattern |
||||||
|
__RegexOptions = options And (Not RegexOptions.Compiled) |
||||||
|
End Sub |
||||||
|
|
||||||
|
#End Region |
||||||
|
|
||||||
|
''' <summary>Indicates whether this instance and a specified object are equal.</summary> |
||||||
|
''' <returns>true if <paramref name="obj" /> and this instance are the same type and represent the same value; otherwise, false.</returns> |
||||||
|
''' <param name="obj">Another object to compare to.</param> |
||||||
|
''' <filterpriority>2</filterpriority> |
||||||
|
Public Overrides Function Equals(ByVal obj As Object) As Boolean |
||||||
|
If (TypeOf obj Is Rule) Then |
||||||
|
Return Me.Name = obj.Name AndAlso Me.Pattern = obj.Pattern |
||||||
|
End If |
||||||
|
Return False |
||||||
|
End Function |
||||||
|
|
||||||
|
''' <summary>Returns the hash code for this instance.</summary> |
||||||
|
''' <returns>A 32-bit signed integer that is the hash code for this instance.</returns> |
||||||
|
''' <filterpriority>2</filterpriority> |
||||||
|
Public Overrides Function GetHashCode() As Integer |
||||||
|
Dim hash As Long = Me.Name.GetHashCode() + Me.Pattern.GetHashCode() |
||||||
|
Return hash And Integer.MinValue |
||||||
|
End Function |
||||||
|
|
||||||
|
Public Shared Operator =(ByVal left As Rule, ByVal right As Rule) As Boolean |
||||||
|
Return left.Equals(right) |
||||||
|
End Operator |
||||||
|
|
||||||
|
Public Shared Operator <>(ByVal left As Rule, ByVal right As Rule) As Boolean |
||||||
|
Return Not left = right |
||||||
|
End Operator |
||||||
|
|
||||||
|
End Structure |
||||||
|
End Namespace |
@ -0,0 +1,36 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : RuleCollection.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 4/30/2009 1:11:18 PM |
||||||
|
' COPYRIGHT : Copyright © 2009 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' TODO: Add file description |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 4/30/2009 1:11:18 PM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
Imports System.Collections.ObjectModel |
||||||
|
|
||||||
|
Namespace Tokenization |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' A read-only collection of <see cref="Rule"/>. |
||||||
|
''' </summary> |
||||||
|
Public NotInheritable Class RuleCollection |
||||||
|
Inherits ReadOnlyCollection(Of Rule) |
||||||
|
|
||||||
|
''' <summary>Initializes an instance of the <see cref="RuleCollection" /> class.</summary> |
||||||
|
''' <param name="items">The items of the collection.</param> |
||||||
|
Friend Sub New(ByVal items As IEnumerable(Of Rule)) |
||||||
|
MyBase.New(items) |
||||||
|
End Sub |
||||||
|
|
||||||
|
End Class |
||||||
|
|
||||||
|
End Namespace |
@ -0,0 +1,76 @@ |
|||||||
|
Imports System.Text |
||||||
|
Imports System.Text.RegularExpressions |
||||||
|
Imports System.Collections.Generic |
||||||
|
|
||||||
|
Namespace Tokenization |
||||||
|
''' <summary> |
||||||
|
''' Represents a Tokenized TOKEN. |
||||||
|
''' </summary> |
||||||
|
Public Class Token |
||||||
|
|
||||||
|
#Region " Private Variables " |
||||||
|
|
||||||
|
Private __Name As String |
||||||
|
Private __Type As Integer |
||||||
|
Private __Value As String |
||||||
|
|
||||||
|
#End Region |
||||||
|
|
||||||
|
#Region " Constructors " |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Initializes an instance of the <see cref="Token" /> class. |
||||||
|
''' </summary> |
||||||
|
''' <param name="name">The name of the token.</param> |
||||||
|
''' <param name="type">The type of the token.</param> |
||||||
|
''' <param name="value">The literal value of the token.</param> |
||||||
|
Friend Sub New(ByVal name, ByVal type, ByVal value) |
||||||
|
__Name = name |
||||||
|
__Type = type |
||||||
|
__Value = value |
||||||
|
End Sub |
||||||
|
|
||||||
|
#End Region |
||||||
|
|
||||||
|
#Region " Public Properties " |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the name of the rule that matched the token. |
||||||
|
''' </summary> |
||||||
|
''' <value>The name of the rule that matched the token.</value> |
||||||
|
''' <remarks> |
||||||
|
''' The name of the token is the name of the rule that matched the toklen. |
||||||
|
''' </remarks> |
||||||
|
Public ReadOnly Property Name() As String |
||||||
|
Get |
||||||
|
Return __Name |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the type of the rule that matched the token. |
||||||
|
''' </summary> |
||||||
|
''' <value>The type of the rule.</value> |
||||||
|
''' <remarks> |
||||||
|
''' The type of the rule is an implementation-specific value that has no meaning outside such implementation. |
||||||
|
''' </remarks> |
||||||
|
Public ReadOnly Property RuleType() As Integer |
||||||
|
Get |
||||||
|
Return __Type |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets the literal value of the token. |
||||||
|
''' </summary> |
||||||
|
''' <value>The literal value of the token.</value> |
||||||
|
Public ReadOnly Property Value() As String |
||||||
|
Get |
||||||
|
Return __Value |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
#End Region |
||||||
|
|
||||||
|
End Class |
||||||
|
End Namespace |
@ -0,0 +1,315 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : Tokenizer.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 9/29/2007 10:18:09 PM |
||||||
|
' COPYRIGHT : Copyright © 2007 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' Implements a class that retrieves tokens from an input. |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 9/29/2007 10:18:09 PM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
Imports System.Text |
||||||
|
Imports System.Text.RegularExpressions |
||||||
|
Imports System.Collections.Generic |
||||||
|
Imports System.Diagnostics.CodeAnalysis |
||||||
|
|
||||||
|
Namespace Tokenization |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' An utility class to get tokens from an input. |
||||||
|
''' </summary> |
||||||
|
<SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId:="Tokenizer", Justification:="The name is correct")> _ |
||||||
|
Public Class Tokenizer |
||||||
|
|
||||||
|
Private Const __MacroNamePattern As String = "\{(?<name>[_A-Z].*?)\}" |
||||||
|
|
||||||
|
Private __Macros As New Dictionary(Of String, Macro) |
||||||
|
Private __Rules As New Dictionary(Of String, Rule) |
||||||
|
Private __Options As RegexOptions |
||||||
|
|
||||||
|
#Region " Public Properties " |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets a read-only list of the macros of this instance of the <see cref="Tokenizer"/> class. |
||||||
|
''' </summary> |
||||||
|
''' <value>A read-only list of the macros of this instance of the <see cref="Tokenizer"/> class.</value> |
||||||
|
Public ReadOnly Property Macros() As MacroCollection |
||||||
|
Get |
||||||
|
Return New MacroCollection(__Macros.Values) |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets a read-only list of the rules of this instance of the <see cref="Tokenizer"/> class. |
||||||
|
''' </summary> |
||||||
|
''' <value>A read-only list of the rules of this instance of the <see cref="Tokenizer"/> class.</value> |
||||||
|
Public ReadOnly Property Rules() As RuleCollection |
||||||
|
Get |
||||||
|
Return New RuleCollection(__Rules.Values) |
||||||
|
End Get |
||||||
|
End Property |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Gets or sets the regular expression options used to match the rules. |
||||||
|
''' </summary> |
||||||
|
''' <value>The regular expression options used to match the rules.</value> |
||||||
|
Public Property Options() As RegexOptions |
||||||
|
Get |
||||||
|
Return __Options |
||||||
|
End Get |
||||||
|
Set(ByVal value As RegexOptions) |
||||||
|
__Options = value |
||||||
|
End Set |
||||||
|
End Property |
||||||
|
|
||||||
|
#End Region |
||||||
|
|
||||||
|
#Region " Public Methods " |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Adds a new macro to the list. |
||||||
|
''' </summary> |
||||||
|
''' <param name="macro">The macro to be added.</param> |
||||||
|
''' <exception cref="ReferencedMacroNotFoundException">One or more referenced macros was not found in the collection.</exception> |
||||||
|
''' <exception cref="CircularReferenceException">The macro has a circular reference.</exception> |
||||||
|
Public Sub AddMacro(ByVal macro As Macro) |
||||||
|
For Each s As String In macro.References |
||||||
|
If (Not __Macros.ContainsKey(s)) Then |
||||||
|
Throw New ReferencedMacroNotFoundException(s) |
||||||
|
End If |
||||||
|
Next |
||||||
|
EnsureNoCircularReference(macro) |
||||||
|
Expand(macro) |
||||||
|
__Macros.Add(macro.Name, macro) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Adds a new macro to the list. |
||||||
|
''' </summary> |
||||||
|
''' <param name="name">The name of the macro to add.</param> |
||||||
|
''' <param name="pattern">The pattern of the macro to add.</param> |
||||||
|
Public Sub AddMacro(ByVal name As String, ByVal pattern As String) |
||||||
|
If (String.IsNullOrEmpty(name) OrElse String.IsNullOrEmpty(pattern)) Then |
||||||
|
Throw New ArgumentNullException(IIf(String.IsNullOrEmpty(name), "name", "pattern")) |
||||||
|
End If |
||||||
|
Dim m As New Macro |
||||||
|
m.Name = name |
||||||
|
m.Pattern = pattern |
||||||
|
Me.AddMacro(m) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Adds a new rule to the list. |
||||||
|
''' </summary> |
||||||
|
''' <param name="rule">The rule to be added.</param> |
||||||
|
''' <exception cref="ReferencedMacroNotFoundException">One or more referenced macro was not found in the collection.</exception> |
||||||
|
Public Sub AddRule(ByVal rule As Rule) |
||||||
|
For Each s As String In rule.References |
||||||
|
If (Not __Macros.ContainsKey(s)) Then |
||||||
|
Throw New ReferencedMacroNotFoundException(s) |
||||||
|
End If |
||||||
|
Next |
||||||
|
Expand(rule) |
||||||
|
__Rules.Add(rule.Name, rule) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Adds a new rule to the list. |
||||||
|
''' </summary> |
||||||
|
''' <param name="name">The name of the rule to add.</param> |
||||||
|
''' <param name="type">The type of the rule to add.</param> |
||||||
|
''' <param name="pattern">The pattern of the rule to add.</param> |
||||||
|
Public Sub AddRule(ByVal name As String, ByVal type As Integer, ByVal pattern As String) |
||||||
|
If (String.IsNullOrEmpty(name) OrElse String.IsNullOrEmpty(pattern)) Then |
||||||
|
Throw New ArgumentNullException(IIf(String.IsNullOrEmpty(name), "name", "pattern")) |
||||||
|
End If |
||||||
|
Dim m As New Rule |
||||||
|
m.Name = name |
||||||
|
m.RuleType = type |
||||||
|
m.Pattern = pattern |
||||||
|
Me.AddRule(m) |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Returns a token from the specified text, consuming it. |
||||||
|
''' </summary> |
||||||
|
''' <param name="text">The text from which to extract the token.</param> |
||||||
|
''' <returns>A token from the specified text if a matching rule is found; otherwise <langword name="null"/>.</returns> |
||||||
|
''' <remarks> |
||||||
|
''' The text is passed by reference and the token is consumed, i.e., |
||||||
|
''' the token will be removed from the specified text. |
||||||
|
''' |
||||||
|
''' If the text is <see cref="String.Empty"/> or <langword name="null"/> GetToken also returns <langword name="null"/>. |
||||||
|
''' </remarks> |
||||||
|
<SuppressMessage("Microsoft.Design", "CA1045:DoNotPassTypesByReference", MessageId:="0#", Justification:="Once a token is read from the string, the token must be consumed, therefore, the string needs to be changed.")> _ |
||||||
|
Public Function GetToken(ByRef text As String) As Token |
||||||
|
|
||||||
|
'* |
||||||
|
'* Check the passed parameters |
||||||
|
'* |
||||||
|
If (String.IsNullOrEmpty(text)) Then |
||||||
|
Return Nothing |
||||||
|
End If |
||||||
|
|
||||||
|
Dim token As Token |
||||||
|
Dim matchedToken As Token = Nothing |
||||||
|
|
||||||
|
Dim maxLen As Integer = -1 |
||||||
|
For Each name As String In __Rules.Keys |
||||||
|
Dim r As Rule = __Rules(name) |
||||||
|
If (Not r.IsExpanded) Then |
||||||
|
Expand(r) |
||||||
|
End If |
||||||
|
|
||||||
|
'* |
||||||
|
'* Try to match the rule |
||||||
|
'* |
||||||
|
Dim match As Match = r.Regex.Match(text) |
||||||
|
|
||||||
|
'* |
||||||
|
'* If the match is a success |
||||||
|
'* |
||||||
|
If (match.Success) Then |
||||||
|
'* |
||||||
|
'* Add the token to the match list |
||||||
|
'* |
||||||
|
token = New Token(r.Name, r.RuleType, match.Value) |
||||||
|
|
||||||
|
'* |
||||||
|
'* Check for the maximum amount of characters consumed |
||||||
|
'* |
||||||
|
If (maxLen < match.Value.Length) Then |
||||||
|
maxLen = match.Value.Length |
||||||
|
matchedToken = token |
||||||
|
End If |
||||||
|
End If |
||||||
|
Next |
||||||
|
|
||||||
|
'* |
||||||
|
'* Was any token found? |
||||||
|
'* |
||||||
|
If (matchedToken IsNot Nothing) Then |
||||||
|
'* |
||||||
|
'* Consumes the token |
||||||
|
'* |
||||||
|
text = text.Substring(matchedToken.Value.Length) |
||||||
|
End If |
||||||
|
|
||||||
|
Return matchedToken |
||||||
|
|
||||||
|
End Function |
||||||
|
|
||||||
|
#End Region |
||||||
|
|
||||||
|
#Region " Private Methods " |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Determines whether the specified macro has circular reference. |
||||||
|
''' </summary> |
||||||
|
''' <param name="macro">The macro to be tested.</param> |
||||||
|
Private Sub EnsureNoCircularReference(ByVal macro As Macro, Optional ByVal path As String = "") |
||||||
|
|
||||||
|
If (path.IndexOf("{" & macro.Name & "}", StringComparison.OrdinalIgnoreCase) <> (-1)) Then |
||||||
|
Throw New CircularReferenceException(path & "{" & macro.Name & "}") |
||||||
|
End If |
||||||
|
|
||||||
|
For Each s As String In macro.References |
||||||
|
EnsureNoCircularReference(__Macros.Item(s), path & "{" & macro.Name & "}") |
||||||
|
Next |
||||||
|
|
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Expands all referenced macros in the rule. |
||||||
|
''' </summary> |
||||||
|
''' <param name="rule">The rule to be expanded.</param> |
||||||
|
Private Sub Expand(ByRef rule As Rule) |
||||||
|
|
||||||
|
'* |
||||||
|
'* Resolve literals |
||||||
|
'* |
||||||
|
Dim iPos As Integer = 0 |
||||||
|
Dim sb As New StringBuilder |
||||||
|
For Each m As Match In Regex.Matches(rule.Pattern, """([^""]|\\"")*?""") |
||||||
|
sb.Append(rule.Pattern.Substring(iPos, m.Index - iPos)) |
||||||
|
sb.Append(EscapeRegExpChars(m.Value.Substring(1, m.Value.Length - 2).Replace("\""", """"))) |
||||||
|
iPos = m.Index + m.Length |
||||||
|
Next |
||||||
|
sb.Append(rule.Pattern.Substring(iPos)) |
||||||
|
Dim expanded As String = sb.ToString() |
||||||
|
|
||||||
|
'* |
||||||
|
'* Expand macros |
||||||
|
'* |
||||||
|
For Each s As String In rule.References |
||||||
|
Dim m As Macro = __Macros(s) |
||||||
|
If (Not m.IsExpanded) Then |
||||||
|
Expand(m) |
||||||
|
End If |
||||||
|
|
||||||
|
expanded = expanded.Replace("{" & m.Name & "}", "(" & m.ExpandedPattern & ")") |
||||||
|
Next |
||||||
|
|
||||||
|
rule.SetExpandedPattern(expanded, Me.Options) |
||||||
|
|
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Expands all referenced macros in the macro. |
||||||
|
''' </summary> |
||||||
|
''' <param name="macro">The macro to be expanded.</param> |
||||||
|
Private Sub Expand(ByRef macro As Macro) |
||||||
|
|
||||||
|
Dim expanded As String = macro.Pattern |
||||||
|
For Each s As String In macro.References |
||||||
|
Dim im As Macro = __Macros(s) |
||||||
|
If (Not im.IsExpanded) Then |
||||||
|
Expand(im) |
||||||
|
End If |
||||||
|
|
||||||
|
expanded = expanded.Replace("{" & im.Name & "}", "(" & im.ExpandedPattern & ")") |
||||||
|
Next |
||||||
|
|
||||||
|
macro.SetExpandedPattern(expanded) |
||||||
|
|
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Escapes all regular expression special characters. |
||||||
|
''' </summary> |
||||||
|
''' <param name="text">The regular expression pattern to be escaped.</param> |
||||||
|
''' <returns>A string with all the regular expression special characters escaped.</returns> |
||||||
|
Private Shared Function EscapeRegExpChars(ByVal text As String) As String |
||||||
|
|
||||||
|
Dim s As String = text |
||||||
|
s = s.Replace("\", "\\") |
||||||
|
s = s.Replace("^", "\^") |
||||||
|
s = s.Replace("$", "\$") |
||||||
|
s = s.Replace("*", "\*") |
||||||
|
s = s.Replace("+", "\+") |
||||||
|
s = s.Replace("?", "\?") |
||||||
|
s = s.Replace("{", "\{") |
||||||
|
s = s.Replace("}", "\}") |
||||||
|
s = s.Replace(".", "\.") |
||||||
|
s = s.Replace("(", "\(") |
||||||
|
s = s.Replace(")", "\)") |
||||||
|
s = s.Replace("[", "\[") |
||||||
|
s = s.Replace("]", "\]") |
||||||
|
s = s.Replace("|", "\|") |
||||||
|
Return s |
||||||
|
|
||||||
|
End Function |
||||||
|
|
||||||
|
#End Region |
||||||
|
|
||||||
|
End Class |
||||||
|
|
||||||
|
End Namespace |
||||||
|
|
@ -0,0 +1,30 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : ITextFormatter.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 5/2/2009 10:22:55 AM |
||||||
|
' COPYRIGHT : Copyright © 2009 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' TODO: Add file description |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 5/2/2009 10:22:55 AM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Defines a generic text formatter. |
||||||
|
''' </summary> |
||||||
|
Public Interface ITextFormatter |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Formats the specified text. |
||||||
|
''' </summary> |
||||||
|
''' <param name="source">The text to be formatted.</param> |
||||||
|
''' <returns>The formatted text.</returns> |
||||||
|
Function Format(ByVal source As String) As String |
||||||
|
|
||||||
|
End Interface |
@ -0,0 +1,411 @@ |
|||||||
|
'************************************************** |
||||||
|
' FILE : Utils.vb |
||||||
|
' AUTHOR : Paulo Santos |
||||||
|
' CREATION : 4/29/2009 2:14:26 PM |
||||||
|
' COPYRIGHT : Copyright © 2009 |
||||||
|
' PJ on Development |
||||||
|
' All Rights Reserved. |
||||||
|
' |
||||||
|
' Description: |
||||||
|
' TODO: Add file description |
||||||
|
' |
||||||
|
' Change log: |
||||||
|
' 0.1 4/29/2009 2:14:26 PM |
||||||
|
' Paulo Santos |
||||||
|
' Created. |
||||||
|
'*************************************************** |
||||||
|
|
||||||
|
Imports System.Text.RegularExpressions |
||||||
|
Imports System.Diagnostics.CodeAnalysis |
||||||
|
|
||||||
|
Friend Module Utils |
||||||
|
|
||||||
|
Public Const STR_BBCodeSchemaNamespace As String = "" '= "http://pjondevelopment.50webs.com/schema/bbcode" |
||||||
|
Public Const STR_BBCodeDictionaryXmlElement As String = "Dictionary" |
||||||
|
Public Const STR_BBCodeElementTypesXmlElement As String = "ElementTypes" |
||||||
|
Public Const STR_BBCodeConfigurationXmlElement As String = "Configuration" |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Returns the specified text between quotes. |
||||||
|
''' </summary> |
||||||
|
''' <param name="text">The text to be placed between quotes.</param> |
||||||
|
''' <returns>The text between quotes.</returns> |
||||||
|
Public Function Quote(ByVal text As String) As String |
||||||
|
Return "'" & text.Replace("'", "''") & "'" |
||||||
|
End Function |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Unquotes the specified text. |
||||||
|
''' </summary> |
||||||
|
''' <param name="text">The text to be unquoted.</param> |
||||||
|
''' <returns>The unquoted text.</returns> |
||||||
|
Public Function UnQuote(ByVal text As String) As String |
||||||
|
Dim rx As New Text.RegularExpressions.Regex("^(?<quote>'(?<text>(?:''|[^'])*)')|(?<doubleQuote>""(?<text>(?:""""|[^""])*)"")$") |
||||||
|
Dim m = rx.Match(text) |
||||||
|
If (Not m.Success) Then |
||||||
|
Return text |
||||||
|
End If |
||||||
|
If (m.Groups("quote").Success) Then |
||||||
|
Return m.Groups("text").Value.Replace("''", "'") |
||||||
|
End If |
||||||
|
Return m.Groups("text").Value.Replace("""""", """") |
||||||
|
End Function |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Validates the specified tag name. |
||||||
|
''' </summary> |
||||||
|
''' <param name="tagName">The tagname to be validated.</param> |
||||||
|
Public Sub ValidateTagName(ByVal tagName As String) |
||||||
|
If (String.IsNullOrEmpty(tagName)) Then |
||||||
|
Throw New ArgumentNullException("tagName") |
||||||
|
End If |
||||||
|
If (tagName.IndexOf("=", StringComparison.Ordinal) <> -1) OrElse (tagName.IndexOf("[", StringComparison.Ordinal) <> -1) OrElse (tagName.IndexOf("]", StringComparison.Ordinal) <> -1) Then |
||||||
|
Throw New ArgumentException("Invalid tag name. The tag name cannot contain '=' '[' or ']'.", "tagName") |
||||||
|
End If |
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Validates the specified type to ensure that it is a subclass of <see cref="BBCodeElement"/>. |
||||||
|
''' </summary> |
||||||
|
''' <param name="value">The <see cref="Type"/> to be validated.</param> |
||||||
|
Public Sub ValidateBBCodeElementType(ByVal value As Type) |
||||||
|
|
||||||
|
'* |
||||||
|
'* Validate is nothing |
||||||
|
'* |
||||||
|
If (value Is Nothing) Then |
||||||
|
Throw New ArgumentNullException("value") |
||||||
|
End If |
||||||
|
|
||||||
|
'* |
||||||
|
'* Validates the BBCodeElement itself |
||||||
|
'* |
||||||
|
Dim bbcodeType = GetType(BBCodeElement) |
||||||
|
If (value.Equals(bbcodeType)) Then |
||||||
|
Exit Sub |
||||||
|
End If |
||||||
|
|
||||||
|
'* |
||||||
|
'* Validate subclass |
||||||
|
'* |
||||||
|
If Not bbcodeType.IsAssignableFrom(value) Then |
||||||
|
Throw New InvalidOperationException("The type " & value.FullName & " must be a assingable to BBCodeElement.") |
||||||
|
End If |
||||||
|
|
||||||
|
'* |
||||||
|
'* Validate default constructor |
||||||
|
'* |
||||||
|
If (value.GetConstructor(New Type() {}) Is Nothing) Then |
||||||
|
Throw New InvalidOperationException("The type " & value.FullName & " does not provide a public default constructor.") |
||||||
|
End If |
||||||
|
|
||||||
|
End Sub |
||||||
|
|
||||||
|
''' <summary> |
||||||
|
''' Encodes the specified text as HTML. |
||||||
|
''' </summary> |
||||||
|
''' <param name="text">The text to be encoded.</param> |
||||||
|
''' <returns>The encoded HTML.</returns> |
||||||
|
<SuppressMessage("Microsoft.Maintainability", "CA1505:AvoidUnmaintainableCode", Justification:="This methos is simple a list of substuition character by its HTML representation.")> _ |
||||||
|
Public Function HtmlEncode(ByVal text As String) As String |
||||||
|
Dim sb As New Text.StringBuilder(text) |
||||||
|
sb.Replace(ChrW(&H26), "&") |
||||||
|
sb.Replace(ChrW(&H22), """) |
||||||
|
sb.Replace(ChrW(&H27), "'") |
||||||
|
sb.Replace(ChrW(&H3C), "<") |
||||||
|
sb.Replace(ChrW(&H3E), ">") |
||||||
|
sb.Replace(ChrW(&HA0), " ") |
||||||
|
sb.Replace(ChrW(&HA1), "¡") |
||||||
|
sb.Replace(ChrW(&HA2), "¢") |
||||||
|
sb.Replace(ChrW(&HA3), "£") |
||||||
|
sb.Replace(ChrW(&HA4), "¤") |
||||||
|
sb.Replace(ChrW(&HA5), "¥") |
||||||
|
sb.Replace(ChrW(&HA6), "¦") |
||||||
|
sb.Replace(ChrW(&HA7), "§") |
||||||
|
sb.Replace(ChrW(&HA8), "¨") |
||||||
|
sb.Replace(ChrW(&HA9), "©") |
||||||
|
sb.Replace(ChrW(&HAA), "ª") |
||||||
|
sb.Replace(ChrW(&HAB), "«") |
||||||
|
sb.Replace(ChrW(&HAC), "¬") |
||||||
|
sb.Replace(ChrW(&HAD), "­") |
||||||
|
sb.Replace(ChrW(&HAE), "®") |
||||||
|
sb.Replace(ChrW(&HAF), "¯") |
||||||
|
sb.Replace(ChrW(&HB0), "°") |
||||||
|
sb.Replace(ChrW(&HB1), "±") |
||||||
|
sb.Replace(ChrW(&HB2), "²") |
||||||
|
sb.Replace(ChrW(&HB3), "³") |
||||||
|
sb.Replace(ChrW(&HB4), "´") |
||||||
|
sb.Replace(ChrW(&HB5), "µ") |
||||||
|
sb.Replace(ChrW(&HB6), "¶") |
||||||
|
sb.Replace(ChrW(&HB7), "·") |
||||||
|
sb.Replace(ChrW(&HB8), "¸") |
||||||
|
sb.Replace(ChrW(&HB9), "¹") |
||||||
|
sb.Replace(ChrW(&HBA), "º") |
||||||
|
sb.Replace(ChrW(&HBB), "»") |
||||||
|
sb.Replace(ChrW(&HBC), "¼") |
||||||
|
sb.Replace(ChrW(&HBD), "½") |
||||||
|
sb.Replace(ChrW(&HBE), "¾") |
||||||
|
sb.Replace(ChrW(&HBF), "¿") |
||||||
|
sb.Replace(ChrW(&HC0), "À") |
||||||
|
sb.Replace(ChrW(&HC1), "Á") |
||||||
|
sb.Replace(ChrW(&HC2), "Â") |
||||||
|
sb.Replace(ChrW(&HC3), "Ã") |
||||||
|
sb.Replace(ChrW(&HC4), "Ä") |
||||||
|
sb.Replace(ChrW(&HC5), "Å") |
||||||
|
sb.Replace(ChrW(&HC6), "Æ") |
||||||
|
sb.Replace(ChrW(&HC7), "Ç") |
||||||
|
sb.Replace(ChrW(&HC8), "È") |
||||||
|
sb.Replace(ChrW(&HC9), "É") |
||||||
|
sb.Replace(ChrW(&HCA), "Ê") |
||||||
|
sb.Replace(ChrW(&HCB), "Ë") |
||||||
|
sb.Replace(ChrW(&HCC), "Ì") |
||||||
|
sb.Replace(ChrW(&HCD), "Í") |
||||||
|
sb.Replace(ChrW(&HCE), "Î") |
||||||
|
sb.Replace(ChrW(&HCF), "Ï") |
||||||
|
sb.Replace(ChrW(&HD0), "Ð") |
||||||
|
sb.Replace(ChrW(&HD1), "Ñ") |
||||||
|
sb.Replace(ChrW(&HD2), "Ò") |
||||||
|
sb.Replace(ChrW(&HD3), "Ó") |
||||||
|
sb.Replace(ChrW(&HD4), "Ô") |
||||||
|
sb.Replace(ChrW(&HD5), "Õ") |
||||||
|
sb.Replace(ChrW(&HD6), "Ö") |
||||||
|
sb.Replace(ChrW(&HD7), "×") |
||||||
|
sb.Replace(ChrW(&HD8), "Ø") |
||||||
|
sb.Replace(ChrW(&HD9), "Ù") |
||||||
|
sb.Replace(ChrW(&HDA), "Ú") |
||||||
|
sb.Replace(ChrW(&HDB), "Û") |
||||||
|
sb.Replace(ChrW(&HDC), "Ü") |
||||||
|
sb.Replace(ChrW(&HDD), "Ý") |
||||||
|
sb.Replace(ChrW(&HDE), "Þ") |
||||||
|
sb.Replace(ChrW(&HDF), "ß") |
||||||
|
sb.Replace(ChrW(&HE0), "à") |
||||||
|
sb.Replace(ChrW(&HE1), "á") |
||||||
|
sb.Replace(ChrW(&HE2), "â") |
||||||
|
sb.Replace(ChrW(&HE3), "ã") |
||||||
|
sb.Replace(ChrW(&HE4), "ä") |
||||||
|
sb.Replace(ChrW(&HE5), "å") |
||||||
|
sb.Replace(ChrW(&HE6), "æ") |
||||||
|
sb.Replace(ChrW(&HE7), "ç") |
||||||
|
sb.Replace(ChrW(&HE8), "è") |
||||||
|
sb.Replace(ChrW(&HE9), "é") |
||||||
|
sb.Replace(ChrW(&HEA), "ê") |
||||||
|
sb.Replace(ChrW(&HEB), "ë") |
||||||
|
sb.Replace(ChrW(&HEC), "ì") |
||||||
|
sb.Replace(ChrW(&HED), "í") |
||||||
|
sb.Replace(ChrW(&HEE), "î") |
||||||
|
sb.Replace(ChrW(&HEF), "ï") |
||||||
|
sb.Replace(ChrW(&HF0), "ð") |
||||||
|
sb.Replace(ChrW(&HF1), "ñ") |
||||||
|
sb.Replace(ChrW(&HF2), "ò") |
||||||
|
sb.Replace(ChrW(&HF3), "ó") |
||||||
|
sb.Replace(ChrW(&HF4), "ô") |
||||||
|
sb.Replace(ChrW(&HF5), "õ") |
||||||
|
sb.Replace(ChrW(&HF6), "ö") |
||||||
|
sb.Replace(ChrW(&HF7), "÷") |
||||||
|
sb.Replace(ChrW(&HF8), "ø") |
||||||
|
sb.Replace(ChrW(&HF9), "ù") |
||||||
|
sb.Replace(ChrW(&HFA), "ú") |
||||||
|
sb.Replace(ChrW(&HFB), "û") |
||||||
|
sb.Replace(ChrW(&HFC), "ü") |
||||||
|
sb.Replace(ChrW(&HFD), "ý") |
||||||
|
sb.Replace(ChrW(&HFE), "þ") |
||||||
|
sb.Replace(ChrW(&HFF), "ÿ") |
||||||
|
sb.Replace(ChrW(&H152), "Œ") |
||||||
|
sb.Replace(ChrW(&H153), "œ") |
||||||
|
sb.Replace(ChrW(&H160), "Š") |
||||||
|
sb.Replace(ChrW(&H161), "š") |
||||||
|
sb.Replace(ChrW(&H178), "Ÿ") |
||||||
|
sb.Replace(ChrW(&H192), "ƒ") |
||||||
|
sb.Replace(ChrW(&H2C6), "ˆ") |
||||||
|
sb.Replace(ChrW(&H2DC), "˜") |
||||||
|
sb.Replace(ChrW(&H391), "Α") |
||||||
|
sb.Replace(ChrW(&H392), "Β") |
||||||
|
sb.Replace(ChrW(&H393), "Γ") |
||||||
|
sb.Replace(ChrW(&H394), "Δ") |
||||||
|
sb.Replace(ChrW(&H395), "Ε") |
||||||
|
sb.Replace(ChrW(&H396), "Ζ") |
||||||
|
sb.Replace(ChrW(&H397), "Η") |
||||||
|
sb.Replace(ChrW(&H398), "Θ") |
||||||
|
sb.Replace(ChrW(&H399), "Ι") |
||||||
|
sb.Replace(ChrW(&H39A), "Κ") |
||||||
|
sb.Replace(ChrW(&H39B), "Λ") |
||||||
|
sb.Replace(ChrW(&H39C), "Μ") |
||||||
|
sb.Replace(ChrW(&H39D), "Ν") |
||||||
|
sb.Replace(ChrW(&H39E), "Ξ") |
||||||
|
sb.Replace(ChrW(&H39F), "Ο") |
||||||
|
sb.Replace(ChrW(&H3A0), "Π") |
||||||
|
sb.Replace(ChrW(&H3A1), "Ρ") |
||||||
|
sb.Replace(ChrW(&H3A3), "Σ") |
||||||
|
sb.Replace(ChrW(&H3A4), "Τ") |
||||||
|
sb.Replace(ChrW(&H3A5), "Υ") |
||||||
|
sb.Replace(ChrW(&H3A6), "Φ") |
||||||
|
sb.Replace(ChrW(&H3A7), "Χ") |
||||||
|
sb.Replace(ChrW(&H3A8), "Ψ") |
||||||
|
sb.Replace(ChrW(&H3A9), "Ω") |
||||||
|
sb.Replace(ChrW(&H3B1), "α") |
||||||
|
sb.Replace(ChrW(&H3B2), "β") |
||||||
|
sb.Replace(ChrW(&H3B3), "γ") |
||||||
|
sb.Replace(ChrW(&H3B4), "δ") |
||||||
|
sb.Replace(ChrW(&H3B5), "ε") |
||||||
|
sb.Replace(ChrW(&H3B6), "ζ") |
||||||
|
sb.Replace(ChrW(&H3B7), "η") |
||||||
|
sb.Replace(ChrW(&H3B8), "θ") |
||||||
|
sb.Replace(ChrW(&H3B9), "ι") |
||||||
|
sb.Replace(ChrW(&H3BA), "κ") |
||||||
|
sb.Replace(ChrW(&H3BB), "λ") |
||||||
|
sb.Replace(ChrW(&H3BC), "μ") |
||||||
|
sb.Replace(ChrW(&H3BD), "ν") |
||||||
|
sb.Replace(ChrW(&H3BE), "ξ") |
||||||
|
sb.Replace(ChrW(&H3BF), "ο") |
||||||
|
sb.Replace(ChrW(&H3C0), "π") |
||||||
|
sb.Replace(ChrW(&H3C1), "ρ") |
||||||
|
sb.Replace(ChrW(&H3C2), "ς") |
||||||
|
sb.Replace(ChrW(&H3C3), "σ") |
||||||
|
sb.Replace(ChrW(&H3C4), "τ") |
||||||
|
sb.Replace(ChrW(&H3C5), "υ") |
||||||
|
sb.Replace(ChrW(&H3C6), "φ") |
||||||
|
sb.Replace(ChrW(&H3C7), "χ") |
||||||
|
sb.Replace(ChrW(&H3C8), "ψ") |
||||||
|
sb.Replace(ChrW(&H3C9), "ω") |
||||||
|
sb.Replace(ChrW(&H3D1), "ϑ") |
||||||
|
sb.Replace(ChrW(&H3D2), "ϒ") |
||||||
|
sb.Replace(ChrW(&H3D6), "ϖ") |
||||||
|
sb.Replace(ChrW(&H2002), " ") |
||||||
|
sb.Replace(ChrW(&H2003), " ") |
||||||
|
sb.Replace(ChrW(&H2009), " ") |
||||||
|
sb.Replace(ChrW(&H200C), "‌") |
||||||
|
sb.Replace(ChrW(&H200D), "‍") |
||||||
|
sb.Replace(ChrW(&H200E), "‎") |
||||||
|
sb.Replace(ChrW(&H200F), "‏") |
||||||
|
sb.Replace(ChrW(&H2013), "–") |
||||||
|
sb.Replace(ChrW(&H2014), "—") |
||||||
|
sb.Replace(ChrW(&H2018), "‘") |
||||||
|
sb.Replace(ChrW(&H2019), "’") |
||||||
|
sb.Replace(ChrW(&H201A), "‚") |
||||||
|
sb.Replace(ChrW(&H201C), "“") |
||||||
|
sb.Replace(ChrW(&H201D), "”") |
||||||
|
sb.Replace(ChrW(&H201E), "„") |
||||||
|
sb.Replace(ChrW(&H2020), "†") |
||||||
|
sb.Replace(ChrW(&H2021), "‡") |
||||||
|
sb.Replace(ChrW(&H2022), "•") |
||||||
|
sb.Replace(ChrW(&H2026), "…") |
||||||
|
sb.Replace(ChrW(&H2030), "‰") |
||||||
|
sb.Replace(ChrW(&H2032), "′") |
||||||
|
sb.Replace(ChrW(&H2033), "″") |
||||||
|
sb.Replace(ChrW(&H2039), "‹") |
||||||
|
sb.Replace(ChrW(&H203A), "›") |
||||||
|
sb.Replace(ChrW(&H203E), "‾") |
||||||
|
sb.Replace(ChrW(&H2044), "⁄") |
||||||
|
sb.Replace(ChrW(&H20AC), "€") |
||||||
|
sb.Replace(ChrW(&H2111), "ℑ") |
||||||
|
sb.Replace(ChrW(&H2118), "℘") |
||||||
|
sb.Replace(ChrW(&H211C), "ℜ") |
||||||
|
sb.Replace(ChrW(&H2122), "™") |
||||||
|
sb.Replace(ChrW(&H2135), "ℵ") |
||||||
|
sb.Replace(ChrW(&H2190), "←") |
||||||
|
sb.Replace(ChrW(&H2191), "↑") |
||||||
|
sb.Replace(ChrW(&H2192), "→") |
||||||
|
sb.Replace(ChrW(&H2193), "↓") |
||||||
|
sb.Replace(ChrW(&H2194), "↔") |
||||||
|
sb.Replace(ChrW(&H21B5), "↵") |
||||||
|
sb.Replace(ChrW(&H21D0), "⇐") |
||||||
|
sb.Replace(ChrW(&H21D1), "⇑") |
||||||
|
sb.Replace(ChrW(&H21D2), "⇒") |
||||||
|
sb.Replace(ChrW(&H21D3), "⇓") |
||||||
|
sb.Replace(ChrW(&H21D4), "⇔") |
||||||
|
sb.Replace(ChrW(&H2200), "∀") |
||||||
|
sb.Replace(ChrW(&H2202), "∂") |
||||||
|
sb.Replace(ChrW(&H2203), "∃") |
||||||
|
sb.Replace(ChrW(&H2205), "∅") |
||||||
|
sb.Replace(ChrW(&H2207), "∇") |
||||||
|
sb.Replace(ChrW(&H2208), "∈") |
||||||
|
sb.Replace(ChrW(&H2209), "∉") |
||||||
|
sb.Replace(ChrW(&H220B), "∋") |
||||||
|
sb.Replace(ChrW(&H220F), "∏") |
||||||
|
sb.Replace(ChrW(&H2211), "∑") |
||||||
|
sb.Replace(ChrW(&H2212), "−") |
||||||
|
sb.Replace(ChrW(&H2217), "∗") |
||||||
|
sb.Replace(ChrW(&H221A), "√") |
||||||
|
sb.Replace(ChrW(&H221D), "∝") |
||||||
|
sb.Replace(ChrW(&H221E), "∞") |
||||||
|
sb.Replace(ChrW(&H2220), "∠") |
||||||
|
sb.Replace(ChrW(&H2227), "∧") |
||||||
|
sb.Replace(ChrW(&H2228), "∨") |
||||||
|
sb.Replace(ChrW(&H2229), "∩") |
||||||
|
sb.Replace(ChrW(&H222A), "∪") |
||||||
|
sb.Replace(ChrW(&H222B), "∫") |
||||||
|
sb.Replace(ChrW(&H2234), "∴") |
||||||
|
sb.Replace(ChrW(&H223C), "∼") |
||||||
|
sb.Replace(ChrW(&H2245), "≅") |
||||||
|
sb.Replace(ChrW(&H2248), "≈") |
||||||
|
sb.Replace(ChrW(&H2260), "≠") |
||||||
|
sb.Replace(ChrW(&H2261), "≡") |
||||||
|
sb.Replace(ChrW(&H2264), "≤") |
||||||
|
sb.Replace(ChrW(&H2265), "≥") |
||||||
|
sb.Replace(ChrW(&H2282), "⊂") |
||||||
|
sb.Replace(ChrW(&H2283), "⊃") |
||||||
|
sb.Replace(ChrW(&H2284), "⊄") |
||||||
|
sb.Replace(ChrW(&H2286), "⊆") |
||||||
|
sb.Replace(ChrW(&H2287), "⊇") |
||||||
|
sb.Replace(ChrW(&H2295), "⊕") |
||||||
|
sb.Replace(ChrW(&H2297), "⊗") |
||||||
|
sb.Replace(ChrW(&H22A5), "⊥") |
||||||
|
sb.Replace(ChrW(&H22C5), "⋅") |
||||||
|
sb.Replace(ChrW(&H2308), "⌈") |
||||||
|
sb.Replace(ChrW(&H2309), "⌉") |
||||||
|
sb.Replace(ChrW(&H230A), "⌊") |
||||||
|
sb.Replace(ChrW(&H230B), "⌋") |
||||||
|
sb.Replace(ChrW(&H2329), "⟨") |
||||||
|
sb.Replace(ChrW(&H232A), "⟩") |
||||||
|
sb.Replace(ChrW(&H25CA), "◊") |
||||||
|
sb.Replace(ChrW(&H2660), "♠") |
||||||
|
sb.Replace(ChrW(&H2663), "♣") |
||||||
|
sb.Replace(ChrW(&H2665), "♥") |
||||||
|
sb.Replace(ChrW(&H2666), "♦") |
||||||
|
sb.Replace(" ", " ") |
||||||
|
Return sb.ToString() |
||||||
|
End Function |
||||||
|
|
||||||
|
Sub AddTokenizerBaseMacros(ByVal tokenizer As Tokenization.Tokenizer) |
||||||
|
|
||||||
|
'* |
||||||
|
'* Prepares the BBCode Grammar |
||||||
|
'* |
||||||
|
With tokenizer |
||||||
|
.Options = RegexOptions.Singleline Or RegexOptions.IgnoreCase |
||||||
|
|
||||||
|
'* |
||||||
|
'* Define the grammar macros |
||||||
|
'* |
||||||
|
.AddMacro("h", "[0-9a-f]") |
||||||
|
.AddMacro("nl", "\n|\r\n|\r|\f") |
||||||
|
.AddMacro("space", "[ \t\r\n\f]+") |
||||||
|
.AddMacro("s", "[ \t\r\n\f]*") |
||||||
|
.AddMacro("w", "{s}?") |
||||||
|
.AddMacro("nonascii", "[\u0080-\uffff]") |
||||||
|
.AddMacro("unicode", "\\{h}{1,6}(\r\n|[ \t\r\n\f])?") |
||||||
|
.AddMacro("escape", "{unicode}|\\[^\r\n\f0-9a-f]") |
||||||
|
.AddMacro("nmstart", "[_a-z]|{nonascii}|{escape}") |
||||||
|
.AddMacro("nmchar", "[_a-z0-9-]|{nonascii}|{escape}") |
||||||
|
.AddMacro("string1", "\""([^\n\r\f\\""]|\\{nl}|{escape})*\""") |
||||||
|
.AddMacro("string2", "\'([^\n\r\f\\']|\\{nl}|{escape})*\'") |
||||||
|
.AddMacro("invalid1", "\""([^\n\r\f\\""]|\\{nl}|{escape})*") |
||||||
|
.AddMacro("invalid2", "\'([^\n\r\f\\']|\\{nl}|{escape})*") |
||||||
|
.AddMacro("name", "{nmchar}+") |
||||||
|
.AddMacro("num", "[0-9]+|[0-9]*\.[0-9]+") |
||||||
|
.AddMacro("string", "{string1}|{string2}") |
||||||
|
.AddMacro("invalid", "{invalid1}|{invalid2}") |
||||||
|
.AddMacro("url", "(ftp|https?://)" & _ |
||||||
|
"(([0-9a-z_!~*'().&=+$%-]+):([0-9a-z_!~*'().&=+$%-]+@))?" & _ |
||||||
|
"(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z_!~*'()-]+\.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.[a-z]{2,6})" & _ |
||||||
|
"(:[0-9]{1,4})?" & _ |
||||||
|
"((/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?|(/?))") |
||||||
|
.AddMacro("mail", "(?:mailto:)?[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}") |
||||||
|
.AddMacro("value", "{string}|{mail}|{url}|{num}|{name}") |
||||||
|
.AddMacro("param", "{name}{w}={w}{value}") |
||||||
|
.AddMacro("params", "({space}({param}|{name}))+") |
||||||
|
|
||||||
|
End With |
||||||
|
End Sub |
||||||
|
|
||||||
|
End Module |
Binary file not shown.
Loading…
Reference in new issue