BBCode parser by PJonDevelopment added to svn

main
Inga 🏳‍🌈 14 years ago
parent 0591fb8474
commit 971fcf4e38
  1. 2
      Builder/IISMainHandler/build.txt
  2. 10
      Builder/IISMainHandler/product.wxs
  3. 2
      Builder/IISUploadHandler/build.txt
  4. 10
      FLocal.sln
  5. 134
      ThirdParty/BBCode/BBCode.vbproj
  6. 86
      ThirdParty/BBCode/BBCodeConfiguration.xsd
  7. 183
      ThirdParty/BBCode/Classes/BBCodeAttributeCollection.vb
  8. 148
      ThirdParty/BBCode/Classes/BBCodeConfiguration.vb
  9. 94
      ThirdParty/BBCode/Classes/BBCodeDocument.vb
  10. 259
      ThirdParty/BBCode/Classes/BBCodeElement.vb
  11. 113
      ThirdParty/BBCode/Classes/BBCodeElementDefinition.vb
  12. 158
      ThirdParty/BBCode/Classes/BBCodeElementDictionary.vb
  13. 101
      ThirdParty/BBCode/Classes/BBCodeElementFactory.vb
  14. 104
      ThirdParty/BBCode/Classes/BBCodeElementTypeDictionary.vb
  15. 37
      ThirdParty/BBCode/Classes/BBCodeHtmlFormatter.vb
  16. 101
      ThirdParty/BBCode/Classes/BBCodeNode.vb
  17. 95
      ThirdParty/BBCode/Classes/BBCodeNodeCollection.vb
  18. 340
      ThirdParty/BBCode/Classes/BBCodeParser.vb
  19. 239
      ThirdParty/BBCode/Classes/BBCodeTag.vb
  20. 81
      ThirdParty/BBCode/Classes/BBCodeText.vb
  21. 107
      ThirdParty/BBCode/Classes/Exceptions/CircularReferenceException.vb
  22. 120
      ThirdParty/BBCode/Classes/Exceptions/ReferencedMacroNotFoundException.vb
  23. 161
      ThirdParty/BBCode/Classes/Tokenizer/Macro.vb
  24. 37
      ThirdParty/BBCode/Classes/Tokenizer/MacroCollection.vb
  25. 201
      ThirdParty/BBCode/Classes/Tokenizer/Rule.vb
  26. 36
      ThirdParty/BBCode/Classes/Tokenizer/RuleCollection.vb
  27. 76
      ThirdParty/BBCode/Classes/Tokenizer/Token.vb
  28. 315
      ThirdParty/BBCode/Classes/Tokenizer/Tokenizer.vb
  29. 30
      ThirdParty/BBCode/Interfaces/ITextFormatter.vb
  30. 411
      ThirdParty/BBCode/Modules/Utils.vb
  31. 13
      ThirdParty/BBCode/My Project/Application.Designer.vb
  32. 10
      ThirdParty/BBCode/My Project/Application.myapp
  33. 37
      ThirdParty/BBCode/My Project/AssemblyInfo.vb
  34. 90
      ThirdParty/BBCode/My Project/Resources.Designer.vb
  35. 129
      ThirdParty/BBCode/My Project/Resources.resx
  36. 73
      ThirdParty/BBCode/My Project/Settings.Designer.vb
  37. 7
      ThirdParty/BBCode/My Project/Settings.settings
  38. BIN
      ThirdParty/BBCode/PJonDevelopment.Key.snk

@ -64,6 +64,12 @@
<Component Id="NConsoler.dll" Guid="F39FD087-8961-4871-9D59-FDB83002BC91">
<File Id="NConsoler.dll" Source="..\..\ThirdParty\NConsoler\NConsoler.dll" KeyPath="yes" Checksum="yes"/>
</Component>
<Component Id="PJonDevelopment.BBCode.dll" Guid="5271E184-FCCB-433C-B789-959B410D6DDA">
<File Id="PJonDevelopment.BBCode.dll" Source="..\..\ThirdParty\BBCode\bin\Release\PJonDevelopment.BBCode.dll" KeyPath="yes" Checksum="yes"/>
</Component>
<Component Id="PJonDevelopment.BBCode.pdb" Guid="EFFBA1FA-A3A8-4D20-8894-AFD255B9F005">
<File Id="PJonDevelopment.BBCode.pdb" Source="..\..\ThirdParty\BBCode\bin\Release\PJonDevelopment.BBCode.pdb" KeyPath="yes" Checksum="yes"/>
</Component>
<!--Component Id="MySql.Data.dll" Guid="90646729-6B21-4BEE-94C3-F39F5288EFB3">
<File Id="MySql.Data.dll" Source="..\..\ThirdParty\mysql-connector-net-6.2.3\MySql.Data\Provider\bin\Release\MySql.Data.dll" KeyPath="yes" Checksum="yes"/>
</Component>
@ -112,6 +118,10 @@
<Feature Id='NConsoler' Title='NConsoler' Level='1'>
<ComponentRef Id='NConsoler.dll' />
</Feature>
<Feature Id='BBCode' Title='BBCode parser by PJonDevelopment' Level='1'>
<ComponentRef Id='PJonDevelopment.BBCode.dll' />
<ComponentRef Id='PJonDevelopment.BBCode.pdb' />
</Feature>
<!--Feature Id='MySql.Data' Title='MySql Connector/NET' Level='1'>
<ComponentRef Id='MySql.Data.dll' />
<ComponentRef Id='MySql.Data.pdb' />

@ -1,6 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual C# Express 2008
# Visual Web Developer Express 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IISMainHandler", "IISMainHandler\IISMainHandler.csproj", "{9A902732-E7F1-4F41-869B-316AF2254B36}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "Core\Core.csproj", "{6F532626-E9F8-498E-9683-1538E7CD62CB}"
@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImportConsole", "ImportCons
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IISUploadHandler", "IISUploadHandler\IISUploadHandler.csproj", "{09F13185-3B2A-4FCB-AB6A-750112FFF920}"
EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "BBCode", "ThirdParty\BBCode\BBCode.vbproj", "{ACDDD5D1-119F-4B82-8FE6-6515C812795B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -81,6 +83,12 @@ Global
{09F13185-3B2A-4FCB-AB6A-750112FFF920}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09F13185-3B2A-4FCB-AB6A-750112FFF920}.Release|Any CPU.Build.0 = Release|Any CPU
{09F13185-3B2A-4FCB-AB6A-750112FFF920}.Release|x86.ActiveCfg = Release|Any CPU
{ACDDD5D1-119F-4B82-8FE6-6515C812795B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ACDDD5D1-119F-4B82-8FE6-6515C812795B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ACDDD5D1-119F-4B82-8FE6-6515C812795B}.Debug|x86.ActiveCfg = Debug|Any CPU
{ACDDD5D1-119F-4B82-8FE6-6515C812795B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ACDDD5D1-119F-4B82-8FE6-6515C812795B}.Release|Any CPU.Build.0 = Release|Any CPU
{ACDDD5D1-119F-4B82-8FE6-6515C812795B}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -0,0 +1,134 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{ACDDD5D1-119F-4B82-8FE6-6515C812795B}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>PJonDevelopment.BBCode</RootNamespace>
<AssemblyName>PJonDevelopment.BBCode</AssemblyName>
<FileAlignment>512</FileAlignment>
<MyType>Windows</MyType>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<OptionExplicit>On</OptionExplicit>
<OptionCompare>Binary</OptionCompare>
<OptionStrict>Off</OptionStrict>
<OptionInfer>On</OptionInfer>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>PJonDevelopment.Key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<OutputPath>bin\Debug\</OutputPath>
<DocumentationFile>PJonDevelopment.BBCode.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<DefineDebug>false</DefineDebug>
<DefineTrace>true</DefineTrace>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DocumentationFile>PJonDevelopment.BBCode.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Import Include="Microsoft.VisualBasic" />
<Import Include="System" />
<Import Include="System.Collections" />
<Import Include="System.Collections.Generic" />
<Import Include="System.Data" />
<Import Include="System.Diagnostics" />
<Import Include="System.Linq" />
<Import Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="Classes\BBCodeAttributeCollection.vb" />
<Compile Include="Classes\BBCodeConfiguration.vb" />
<Compile Include="Classes\BBCodeElementDictionary.vb" />
<Compile Include="Classes\BBCodeDocument.vb" />
<Compile Include="Classes\BBCodeElement.vb" />
<Compile Include="Classes\BBCodeElementDefinition.vb" />
<Compile Include="Classes\BBCodeElementFactory.vb" />
<Compile Include="Classes\BBCodeHtmlFormatter.vb" />
<Compile Include="Classes\BBCodeNode.vb" />
<Compile Include="Classes\BBCodeNodeCollection.vb" />
<Compile Include="Classes\BBCodeParser.vb" />
<Compile Include="Classes\BBCodeTag.vb" />
<Compile Include="Classes\BBCodeText.vb" />
<Compile Include="Classes\Exceptions\CircularReferenceException.vb" />
<Compile Include="Classes\Exceptions\ReferencedMacroNotFoundException.vb" />
<Compile Include="Classes\BBCodeElementTypeDictionary.vb" />
<Compile Include="Classes\Tokenizer\Macro.vb" />
<Compile Include="Classes\Tokenizer\MacroCollection.vb" />
<Compile Include="Classes\Tokenizer\Rule.vb" />
<Compile Include="Classes\Tokenizer\RuleCollection.vb" />
<Compile Include="Classes\Tokenizer\Token.vb" />
<Compile Include="Classes\Tokenizer\Tokenizer.vb" />
<Compile Include="Interfaces\ITextFormatter.vb" />
<Compile Include="Modules\Utils.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Application.myapp</DependentUpon>
</Compile>
<Compile Include="My Project\Resources.Designer.vb">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="My Project\Settings.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="My Project\Resources.resx">
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
<CustomToolNamespace>My.Resources</CustomToolNamespace>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="My Project\Application.myapp">
<Generator>MyApplicationCodeGenerator</Generator>
<LastGenOutput>Application.Designer.vb</LastGenOutput>
</None>
<None Include="My Project\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<CustomToolNamespace>My</CustomToolNamespace>
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
</None>
<None Include="BBCodeConfiguration.xsd" />
<None Include="PJonDevelopment.Key.snk" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified"
attributeFormDefault="unqualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:documentation xml:lang="en">
BBCode Configuration Schema
Copyright (c) 2009 - PJ on Development.
</xs:documentation>
</xs:annotation>
<xs:element name="Configuration" type="TConfiguration" />
<xs:complexType name="TConfiguration">
<xs:annotation>
<xs:documentation>
This type is the root of the configuration file.
</xs:documentation>
</xs:annotation>
<xs:choice>
<xs:group ref="GDictionaryFirst" minOccurs="0" maxOccurs="1"/>
<xs:group ref="GDictionaryLast" minOccurs="0" maxOccurs="1"/>
</xs:choice>
<xs:attribute name="version" type="xs:string" use="required" />
</xs:complexType>
<!-- GDictionaryFirst and GDictionaryLast allow us to define the xsd to be order-independent for the Dictionary element & EntityTypes element. -->
<xs:group name="GDictionaryFirst">
<xs:sequence>
<xs:element name="Dictionary" type="TDictionary" minOccurs="1" maxOccurs="1"/>
<xs:element name="ElementTypes" type="TElementTypes" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:group>
<xs:group name="GDictionaryLast">
<xs:sequence>
<xs:element name="ElementTypes" type="TElementTypes" minOccurs="1" maxOccurs="1"/>
<xs:element name="Dictionary" type="TDictionary" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:group>
<xs:complexType name="TElementTypes">
<xs:annotation>
<xs:documentation>
Describes the list of known BBCode element that requires an specific type.
</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="Element">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="type" type="xs:string" use="required">
<xs:annotation>
<xs:documentation>
The type must be assignable to a BBCodeElement.
</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="TDictionary">
<xs:annotation>
<xs:documentation>
Describes the known BBCode elements.
</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="item">
<xs:complexType mixed="true">
<xs:sequence minOccurs="0">
<xs:any processContents ="lax" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="requireClosingTag" type="xs:string" use="required" />
<xs:attribute name="escaped" type="xs:boolean" use="optional" />
<xs:anyAttribute processContents="lax"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>

@ -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 &lt;a href="http://tempuri.org"&gt;text&lt;/a&gt; the following ReplacementFormat should be used:</para>
''' <example>
''' &lt;a href="{default|value}"&gt;{value|default}&lt;/a&gt;
''' </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 &lt;a href="http://tempuri.org"&gt;text&lt;/a&gt; the following ReplacementFormat should be used:</para>
''' <example>
''' &lt;a href="{default|value}"&gt;{value|default}&lt;/a&gt;
''' </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), "&amp;")
sb.Replace(ChrW(&H22), "&quot;")
sb.Replace(ChrW(&H27), "&apos;")
sb.Replace(ChrW(&H3C), "&lt;")
sb.Replace(ChrW(&H3E), "&gt;")
sb.Replace(ChrW(&HA0), "&nbsp;")
sb.Replace(ChrW(&HA1), "&iexcl;")
sb.Replace(ChrW(&HA2), "&cent;")
sb.Replace(ChrW(&HA3), "&pound;")
sb.Replace(ChrW(&HA4), "&curren;")
sb.Replace(ChrW(&HA5), "&yen;")
sb.Replace(ChrW(&HA6), "&brvbar;")
sb.Replace(ChrW(&HA7), "&sect;")
sb.Replace(ChrW(&HA8), "&uml;")
sb.Replace(ChrW(&HA9), "&copy;")
sb.Replace(ChrW(&HAA), "&ordf;")
sb.Replace(ChrW(&HAB), "&laquo;")
sb.Replace(ChrW(&HAC), "&not;")
sb.Replace(ChrW(&HAD), "&shy;")
sb.Replace(ChrW(&HAE), "&reg;")
sb.Replace(ChrW(&HAF), "&macr;")
sb.Replace(ChrW(&HB0), "&deg;")
sb.Replace(ChrW(&HB1), "&plusmn;")
sb.Replace(ChrW(&HB2), "&sup2;")
sb.Replace(ChrW(&HB3), "&sup3;")
sb.Replace(ChrW(&HB4), "&acute;")
sb.Replace(ChrW(&HB5), "&micro;")
sb.Replace(ChrW(&HB6), "&para;")
sb.Replace(ChrW(&HB7), "&middot;")
sb.Replace(ChrW(&HB8), "&cedil;")
sb.Replace(ChrW(&HB9), "&sup1;")
sb.Replace(ChrW(&HBA), "&ordm;")
sb.Replace(ChrW(&HBB), "&raquo;")
sb.Replace(ChrW(&HBC), "&frac14;")
sb.Replace(ChrW(&HBD), "&frac12;")
sb.Replace(ChrW(&HBE), "&frac34;")
sb.Replace(ChrW(&HBF), "&iquest;")
sb.Replace(ChrW(&HC0), "&Agrave;")
sb.Replace(ChrW(&HC1), "&Aacute;")
sb.Replace(ChrW(&HC2), "&Acirc;")
sb.Replace(ChrW(&HC3), "&Atilde;")
sb.Replace(ChrW(&HC4), "&Auml;")
sb.Replace(ChrW(&HC5), "&Aring;")
sb.Replace(ChrW(&HC6), "&AElig;")
sb.Replace(ChrW(&HC7), "&Ccedil;")
sb.Replace(ChrW(&HC8), "&Egrave;")
sb.Replace(ChrW(&HC9), "&Eacute;")
sb.Replace(ChrW(&HCA), "&Ecirc;")
sb.Replace(ChrW(&HCB), "&Euml;")
sb.Replace(ChrW(&HCC), "&Igrave;")
sb.Replace(ChrW(&HCD), "&Iacute;")
sb.Replace(ChrW(&HCE), "&Icirc;")
sb.Replace(ChrW(&HCF), "&Iuml;")
sb.Replace(ChrW(&HD0), "&ETH;")
sb.Replace(ChrW(&HD1), "&Ntilde;")
sb.Replace(ChrW(&HD2), "&Ograve;")
sb.Replace(ChrW(&HD3), "&Oacute;")
sb.Replace(ChrW(&HD4), "&Ocirc;")
sb.Replace(ChrW(&HD5), "&Otilde;")
sb.Replace(ChrW(&HD6), "&Ouml;")
sb.Replace(ChrW(&HD7), "&times;")
sb.Replace(ChrW(&HD8), "&Oslash;")
sb.Replace(ChrW(&HD9), "&Ugrave;")
sb.Replace(ChrW(&HDA), "&Uacute;")
sb.Replace(ChrW(&HDB), "&Ucirc;")
sb.Replace(ChrW(&HDC), "&Uuml;")
sb.Replace(ChrW(&HDD), "&Yacute;")
sb.Replace(ChrW(&HDE), "&THORN;")
sb.Replace(ChrW(&HDF), "&szlig;")
sb.Replace(ChrW(&HE0), "&agrave;")
sb.Replace(ChrW(&HE1), "&aacute;")
sb.Replace(ChrW(&HE2), "&acirc;")
sb.Replace(ChrW(&HE3), "&atilde;")
sb.Replace(ChrW(&HE4), "&auml;")
sb.Replace(ChrW(&HE5), "&aring;")
sb.Replace(ChrW(&HE6), "&aelig;")
sb.Replace(ChrW(&HE7), "&ccedil;")
sb.Replace(ChrW(&HE8), "&egrave;")
sb.Replace(ChrW(&HE9), "&eacute;")
sb.Replace(ChrW(&HEA), "&ecirc;")
sb.Replace(ChrW(&HEB), "&euml;")
sb.Replace(ChrW(&HEC), "&igrave;")
sb.Replace(ChrW(&HED), "&iacute;")
sb.Replace(ChrW(&HEE), "&icirc;")
sb.Replace(ChrW(&HEF), "&iuml;")
sb.Replace(ChrW(&HF0), "&eth;")
sb.Replace(ChrW(&HF1), "&ntilde;")
sb.Replace(ChrW(&HF2), "&ograve;")
sb.Replace(ChrW(&HF3), "&oacute;")
sb.Replace(ChrW(&HF4), "&ocirc;")
sb.Replace(ChrW(&HF5), "&otilde;")
sb.Replace(ChrW(&HF6), "&ouml;")
sb.Replace(ChrW(&HF7), "&divide;")
sb.Replace(ChrW(&HF8), "&oslash;")
sb.Replace(ChrW(&HF9), "&ugrave;")
sb.Replace(ChrW(&HFA), "&uacute;")
sb.Replace(ChrW(&HFB), "&ucirc;")
sb.Replace(ChrW(&HFC), "&uuml;")
sb.Replace(ChrW(&HFD), "&yacute;")
sb.Replace(ChrW(&HFE), "&thorn;")
sb.Replace(ChrW(&HFF), "&yuml;")
sb.Replace(ChrW(&H152), "&OElig;")
sb.Replace(ChrW(&H153), "&oelig;")
sb.Replace(ChrW(&H160), "&Scaron;")
sb.Replace(ChrW(&H161), "&scaron;")
sb.Replace(ChrW(&H178), "&Yuml;")
sb.Replace(ChrW(&H192), "&fnof;")
sb.Replace(ChrW(&H2C6), "&circ;")
sb.Replace(ChrW(&H2DC), "&tilde;")
sb.Replace(ChrW(&H391), "&Alpha;")
sb.Replace(ChrW(&H392), "&Beta;")
sb.Replace(ChrW(&H393), "&Gamma;")
sb.Replace(ChrW(&H394), "&Delta;")
sb.Replace(ChrW(&H395), "&Epsilon;")
sb.Replace(ChrW(&H396), "&Zeta;")
sb.Replace(ChrW(&H397), "&Eta;")
sb.Replace(ChrW(&H398), "&Theta;")
sb.Replace(ChrW(&H399), "&Iota;")
sb.Replace(ChrW(&H39A), "&Kappa;")
sb.Replace(ChrW(&H39B), "&Lambda;")
sb.Replace(ChrW(&H39C), "&Mu;")
sb.Replace(ChrW(&H39D), "&Nu;")
sb.Replace(ChrW(&H39E), "&Xi;")
sb.Replace(ChrW(&H39F), "&Omicron;")
sb.Replace(ChrW(&H3A0), "&Pi;")
sb.Replace(ChrW(&H3A1), "&Rho;")
sb.Replace(ChrW(&H3A3), "&Sigma;")
sb.Replace(ChrW(&H3A4), "&Tau;")
sb.Replace(ChrW(&H3A5), "&Upsilon;")
sb.Replace(ChrW(&H3A6), "&Phi;")
sb.Replace(ChrW(&H3A7), "&Chi;")
sb.Replace(ChrW(&H3A8), "&Psi;")
sb.Replace(ChrW(&H3A9), "&Omega;")
sb.Replace(ChrW(&H3B1), "&alpha;")
sb.Replace(ChrW(&H3B2), "&beta;")
sb.Replace(ChrW(&H3B3), "&gamma;")
sb.Replace(ChrW(&H3B4), "&delta;")
sb.Replace(ChrW(&H3B5), "&epsilon;")
sb.Replace(ChrW(&H3B6), "&zeta;")
sb.Replace(ChrW(&H3B7), "&eta;")
sb.Replace(ChrW(&H3B8), "&theta;")
sb.Replace(ChrW(&H3B9), "&iota;")
sb.Replace(ChrW(&H3BA), "&kappa;")
sb.Replace(ChrW(&H3BB), "&lambda;")
sb.Replace(ChrW(&H3BC), "&mu;")
sb.Replace(ChrW(&H3BD), "&nu;")
sb.Replace(ChrW(&H3BE), "&xi;")
sb.Replace(ChrW(&H3BF), "&omicron;")
sb.Replace(ChrW(&H3C0), "&pi;")
sb.Replace(ChrW(&H3C1), "&rho;")
sb.Replace(ChrW(&H3C2), "&sigmaf;")
sb.Replace(ChrW(&H3C3), "&sigma;")
sb.Replace(ChrW(&H3C4), "&tau;")
sb.Replace(ChrW(&H3C5), "&upsilon;")
sb.Replace(ChrW(&H3C6), "&phi;")
sb.Replace(ChrW(&H3C7), "&chi;")
sb.Replace(ChrW(&H3C8), "&psi;")
sb.Replace(ChrW(&H3C9), "&omega;")
sb.Replace(ChrW(&H3D1), "&thetasym;")
sb.Replace(ChrW(&H3D2), "&upsih;")
sb.Replace(ChrW(&H3D6), "&piv;")
sb.Replace(ChrW(&H2002), "&ensp;")
sb.Replace(ChrW(&H2003), "&emsp;")
sb.Replace(ChrW(&H2009), "&thinsp;")
sb.Replace(ChrW(&H200C), "&zwnj;")
sb.Replace(ChrW(&H200D), "&zwj;")
sb.Replace(ChrW(&H200E), "&lrm;")
sb.Replace(ChrW(&H200F), "&rlm;")
sb.Replace(ChrW(&H2013), "&ndash;")
sb.Replace(ChrW(&H2014), "&mdash;")
sb.Replace(ChrW(&H2018), "&lsquo;")
sb.Replace(ChrW(&H2019), "&rsquo;")
sb.Replace(ChrW(&H201A), "&sbquo;")
sb.Replace(ChrW(&H201C), "&ldquo;")
sb.Replace(ChrW(&H201D), "&rdquo;")
sb.Replace(ChrW(&H201E), "&bdquo;")
sb.Replace(ChrW(&H2020), "&dagger;")
sb.Replace(ChrW(&H2021), "&Dagger;")
sb.Replace(ChrW(&H2022), "&bull;")
sb.Replace(ChrW(&H2026), "&hellip;")
sb.Replace(ChrW(&H2030), "&permil;")
sb.Replace(ChrW(&H2032), "&prime;")
sb.Replace(ChrW(&H2033), "&Prime;")
sb.Replace(ChrW(&H2039), "&lsaquo;")
sb.Replace(ChrW(&H203A), "&rsaquo;")
sb.Replace(ChrW(&H203E), "&oline;")
sb.Replace(ChrW(&H2044), "&frasl;")
sb.Replace(ChrW(&H20AC), "&euro;")
sb.Replace(ChrW(&H2111), "&image;")
sb.Replace(ChrW(&H2118), "&weierp;")
sb.Replace(ChrW(&H211C), "&real;")
sb.Replace(ChrW(&H2122), "&trade;")
sb.Replace(ChrW(&H2135), "&alefsym;")
sb.Replace(ChrW(&H2190), "&larr;")
sb.Replace(ChrW(&H2191), "&uarr;")
sb.Replace(ChrW(&H2192), "&rarr;")
sb.Replace(ChrW(&H2193), "&darr;")
sb.Replace(ChrW(&H2194), "&harr;")
sb.Replace(ChrW(&H21B5), "&crarr;")
sb.Replace(ChrW(&H21D0), "&lArr;")
sb.Replace(ChrW(&H21D1), "&uArr;")
sb.Replace(ChrW(&H21D2), "&rArr;")
sb.Replace(ChrW(&H21D3), "&dArr;")
sb.Replace(ChrW(&H21D4), "&hArr;")
sb.Replace(ChrW(&H2200), "&forall;")
sb.Replace(ChrW(&H2202), "&part;")
sb.Replace(ChrW(&H2203), "&exist;")
sb.Replace(ChrW(&H2205), "&empty;")
sb.Replace(ChrW(&H2207), "&nabla;")
sb.Replace(ChrW(&H2208), "&isin;")
sb.Replace(ChrW(&H2209), "&notin;")
sb.Replace(ChrW(&H220B), "&ni;")
sb.Replace(ChrW(&H220F), "&prod;")
sb.Replace(ChrW(&H2211), "&sum;")
sb.Replace(ChrW(&H2212), "&minus;")
sb.Replace(ChrW(&H2217), "&lowast;")
sb.Replace(ChrW(&H221A), "&radic;")
sb.Replace(ChrW(&H221D), "&prop;")
sb.Replace(ChrW(&H221E), "&infin;")
sb.Replace(ChrW(&H2220), "&ang;")
sb.Replace(ChrW(&H2227), "&and;")
sb.Replace(ChrW(&H2228), "&or;")
sb.Replace(ChrW(&H2229), "&cap;")
sb.Replace(ChrW(&H222A), "&cup;")
sb.Replace(ChrW(&H222B), "&int;")
sb.Replace(ChrW(&H2234), "&there4;")
sb.Replace(ChrW(&H223C), "&sim;")
sb.Replace(ChrW(&H2245), "&cong;")
sb.Replace(ChrW(&H2248), "&asymp;")
sb.Replace(ChrW(&H2260), "&ne;")
sb.Replace(ChrW(&H2261), "&equiv;")
sb.Replace(ChrW(&H2264), "&le;")
sb.Replace(ChrW(&H2265), "&ge;")
sb.Replace(ChrW(&H2282), "&sub;")
sb.Replace(ChrW(&H2283), "&sup;")
sb.Replace(ChrW(&H2284), "&nsub;")
sb.Replace(ChrW(&H2286), "&sube;")
sb.Replace(ChrW(&H2287), "&supe;")
sb.Replace(ChrW(&H2295), "&oplus;")
sb.Replace(ChrW(&H2297), "&otimes;")
sb.Replace(ChrW(&H22A5), "&perp;")
sb.Replace(ChrW(&H22C5), "&sdot;")
sb.Replace(ChrW(&H2308), "&lceil;")
sb.Replace(ChrW(&H2309), "&rceil;")
sb.Replace(ChrW(&H230A), "&lfloor;")
sb.Replace(ChrW(&H230B), "&rfloor;")
sb.Replace(ChrW(&H2329), "&lang;")
sb.Replace(ChrW(&H232A), "&rang;")
sb.Replace(ChrW(&H25CA), "&loz;")
sb.Replace(ChrW(&H2660), "&spades;")
sb.Replace(ChrW(&H2663), "&clubs;")
sb.Replace(ChrW(&H2665), "&hearts;")
sb.Replace(ChrW(&H2666), "&diams;")
sb.Replace(" ", " &nbsp;")
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

@ -0,0 +1,13 @@
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:2.0.50727.3053
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MySubMain>false</MySubMain>
<SingleInstance>false</SingleInstance>
<ShutdownMode>0</ShutdownMode>
<EnableVisualStyles>true</EnableVisualStyles>
<AuthenticationMode>0</AuthenticationMode>
<ApplicationType>1</ApplicationType>
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
</MyApplicationData>

@ -0,0 +1,37 @@
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices
' General Information about an assembly is controlled through the following
' set of attributes. Change these attribute values to modify the information
' associated with an assembly.
' Review the values of the assembly attributes
<Assembly: AssemblyTitle("BBCode Parser")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("PJ on Development")>
<Assembly: AssemblyProduct("BBCode Parser")>
<Assembly: AssemblyCopyright("Copyright © 2009 - PJ on Development - All Rights reserved.")>
<Assembly: AssemblyTrademark("")>
<Assembly: ComVisible(False)>
<Assembly: Resources.NeutralResourcesLanguage("en")>
<Assembly: CLSCompliant(True)>
'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("f1ab9900-95fe-4241-b7ab-cdc8eb2ad486")>
' Version information for an assembly consists of the following four values:
'
' Major Version
' Minor Version
' Build Number
' Revision
'
' You can specify all the values or you can default the Build and Revision Numbers
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.0.0.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")>

@ -0,0 +1,90 @@
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:2.0.50727.3053
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Imports System
Namespace My.Resources
'This class was auto-generated by the StronglyTypedResourceBuilder
'class via a tool like ResGen or Visual Studio.
'To add or remove a member, edit your .ResX file then rerun ResGen
'with the /str option, or rebuild your VS project.
'''<summary>
''' A strongly-typed resource class, for looking up localized strings, etc.
'''</summary>
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0"), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
Friend Module Resources
Private resourceMan As Global.System.Resources.ResourceManager
Private resourceCulture As Global.System.Globalization.CultureInfo
'''<summary>
''' Returns the cached ResourceManager instance used by this class.
'''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
Get
If Object.ReferenceEquals(resourceMan, Nothing) Then
Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("PJonDevelopment.BBCode.Resources", GetType(Resources).Assembly)
resourceMan = temp
End If
Return resourceMan
End Get
End Property
'''<summary>
''' Overrides the current thread's CurrentUICulture property for all
''' resource lookups using this strongly typed resource class.
'''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Friend Property Culture() As Global.System.Globalization.CultureInfo
Get
Return resourceCulture
End Get
Set
resourceCulture = value
End Set
End Property
'''<summary>
''' Looks up a localized string similar to A circular reference was found..
'''</summary>
Friend ReadOnly Property CircularReferenceException_Message() As String
Get
Return ResourceManager.GetString("CircularReferenceException_Message", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to The name of a {0} cannot have &apos;{&apos; or &apos;}&apos;..
'''</summary>
Friend ReadOnly Property Name_ArgumentException_Message() As String
Get
Return ResourceManager.GetString("Name_ArgumentException_Message", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to A referenced macro ({0}) was not found in the collection..
'''</summary>
Friend ReadOnly Property ReferencedMacroNotFoundException_Message() As String
Get
Return ResourceManager.GetString("ReferencedMacroNotFoundException_Message", resourceCulture)
End Get
End Property
End Module
End Namespace

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="CircularReferenceException_Message" xml:space="preserve">
<value>A circular reference was found.</value>
</data>
<data name="Name_ArgumentException_Message" xml:space="preserve">
<value>The name of a {0} cannot have '{' or '}'.</value>
</data>
<data name="ReferencedMacroNotFoundException_Message" xml:space="preserve">
<value>A referenced macro ({0}) was not found in the collection.</value>
</data>
</root>

@ -0,0 +1,73 @@
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:2.0.50727.3053
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Namespace My
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0"), _
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Partial Friend NotInheritable Class MySettings
Inherits Global.System.Configuration.ApplicationSettingsBase
Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings),MySettings)
#Region "My.Settings Auto-Save Functionality"
#If _MyType = "WindowsForms" Then
Private Shared addedHandler As Boolean
Private Shared addedHandlerLockObject As New Object
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs)
If My.Application.SaveMySettingsOnExit Then
My.Settings.Save()
End If
End Sub
#End If
#End Region
Public Shared ReadOnly Property [Default]() As MySettings
Get
#If _MyType = "WindowsForms" Then
If Not addedHandler Then
SyncLock addedHandlerLockObject
If Not addedHandler Then
AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
addedHandler = True
End If
End SyncLock
End If
#End If
Return defaultInstance
End Get
End Property
End Class
End Namespace
Namespace My
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
Friend Module MySettingsProperty
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
Friend ReadOnly Property Settings() As Global.PJonDevelopment.BBCode.My.MySettings
Get
Return Global.PJonDevelopment.BBCode.My.MySettings.Default
End Get
End Property
End Module
End Namespace

@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" UseMySettingsClassName="true">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

Binary file not shown.
Loading…
Cancel
Save