// 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 . namespace Rauchy.Regionerate.Shared.Components.Rendering { /// /// A textual sign which can be embedded in strings and later be identified in them. /// The symbol wraps a text by adding a /// prefix and suffix to the embedded text. /// public sealed class Wrapper : Symbol { #region Fields (2)  private readonly string _prefix; private readonly string _suffix; #endregion Fields  #region Constructors (1)  /// /// Initializes a new instance of the class. /// /// The prefix. /// The suffix. public Wrapper( string prefix, string suffix ) { _prefix = prefix; _suffix = suffix; } #endregion Constructors  #region Properties (2)  /// /// Gets the prefix. /// /// The prefix. public string Prefix { get { return _prefix; } } /// /// Gets the suffix. /// /// The suffix. public string Suffix { get { return _suffix; } } #endregion Properties  #region Methods (2)  // Public Methods (2)  /// /// Embeds the textual chariteristics of this inside the specified text. /// /// /// The provided text with the embedded in it. /// public override string Embed( string text ) { string embeddedText = string.Format( " {0} {1} {2}", Prefix, text, Suffix ); return embeddedText; } /// /// Determines whether the textual chariteristics of this are embedded in the specified text. /// public override bool IsEmbeddedIn( string text ) { bool startsWithSomethingElseThanPrefix = !text.StartsWith(Prefix); bool containsPrefix = text.Contains(Prefix); bool endsWithSuffix = text.TrimEnd().EndsWith(Suffix); bool prefixIsBeforeSuffix = text.IndexOf(Prefix) < text.LastIndexOf(Suffix); bool isNotAnIndexer = !text.Contains("this") && text.IndexOf("this") < text.IndexOf(Prefix); //PELTON: added. bool embeddedInText = startsWithSomethingElseThanPrefix && containsPrefix && endsWithSuffix & prefixIsBeforeSuffix && isNotAnIndexer; //PELTON: added. return embeddedInText; } #endregion Methods  } }