// Copyright (c) 2007 Omer Rauchwerger (a.k.a rauchy) (omer@rauchy.net) // All rights reserved. // // This file is part of Regionerate. // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 3 of the License, // or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . using System.Collections.Generic; using System.Text.RegularExpressions; using Rauchy.Regionerate.Shared.Components; namespace Rauchy.Regionerate.ServiceLayer.Components { public class Document { #region Fields (3)  private string _text; private readonly string _title; private const string ClassPattern = @"(?:((?:public|private|internal|abstract|sealed|static)\s*))*class\s(?:[\w.,\:\(\)\<\>\?]\s*)+\{[^\{\}]*(?:(?:(?\{)[^\{\}]*)+(?:(?\})[^\{\}]*)+)*(?(Open)(?!))\}"; private const string StructPattern = @"^\s*(?:((?:public|private|internal|abstract|sealed|static)\s*))*struct\s(?:[\w.,\:\(\)\<\>\?]\s*)+\{[^\{\}]*(?:(?:(?\{)[^\{\}]*)+(?:(?\})[^\{\}]*)+)*(?(Open)(?!))\}"; private const string InterfacePattern = @"^\s*(?:((?:public|private|internal|protected|new)\s*))*interface\s(?:[\w.,\:\(\)\<\>\?]\s*)+\{[^\{\}]*(?:(?:(?\{)[^\{\}]*)+(?:(?\})[^\{\}]*)+)*(?(Open)(?!))\}"; #endregion Fields  #region Constructors (1)  /// /// Initializes a new instance of the class. /// /// The title of this . /// The text. public Document( string title, string text ) { _title = title; _text = text.EncodeBrackets(); } #endregion Constructors  #region Properties (3)  /// /// Gets the classes inside this . /// public IList Classes { get { IList classes = new List(); Match match = new Regex( ClassPattern, RegexOptions.Multiline ).Match( Text ); if ( match.Success ) { while ( match.Success ) { classes.Add( match.Value ); match = match.NextMatch(); } } return classes; } } /// /// Gets the structs inside this . /// public IList Structs { get { IList structs = new List(); Match match = new Regex( StructPattern, RegexOptions.Multiline ).Match( Text ); if ( match.Success ) { while ( match.Success ) { structs.Add( match.Value ); match = match.NextMatch(); } } return structs; } } /// /// Gets the interfaces inside this . /// public IList Interfaces { get { IList interfaces = new List(); Match match = new Regex( InterfacePattern, RegexOptions.Multiline ).Match( Text ); if ( match.Success ) { while ( match.Success ) { interfaces.Add( match.Value ); match = match.NextMatch(); } } return interfaces; } } /// /// Gets or sets the text. /// /// The text. protected virtual string Text { get { return _text; } set { _text = value.DecodeBrackets(); } } /// /// Gets the title of this . /// public string Title { get { return _title; } } #endregion Properties  #region Methods (2)  // Public Methods (2)  /// /// Replaces the old value with the new value. /// /// The old value. /// The new value. public void Replace( string oldValue, string newValue ) { Text = Text.Replace( oldValue, newValue ); } /// /// Returns a that represents the current . /// /// /// A that represents the current . /// public override string ToString() { return Text.DecodeBrackets(); } #endregion Methods  } }