// 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;
namespace Rauchy.Regionerate.Shared.Components.Rendering
{
///
/// A textual sign which can be embedded in strings and later be identified in them.
/// The symbol replaces all occurances of the space character
/// with the special hidden dragon character, which looks like a space but helps
/// Regionerate to differentiate a symbolized text from a normal text.
///
public sealed class HiddenDragon : Symbol
{
#region Fields (1)
private static readonly char HiddenDragonCharacter = Convert.ToChar( 160 );
#endregion Fields
#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 )
{
// Replace all spaces with hidden dragon characters;
text = text.Replace( ' ', HiddenDragonCharacter );
// Add hidden dragon characters at the beginning & end of the text.
text = text.Insert( 0, HiddenDragonCharacter.ToString() );
text = text.Insert( text.Length, HiddenDragonCharacter.ToString() );
return text;
}
///
/// Determines whether the textual chariteristics of this are embedded in the specified text.
///
public override bool IsEmbeddedIn( string text )
{
bool doesNotContainSpaces = !text.Contains( " " );
bool containsAtLeastOneHiddenDragonCharacter = text.Contains( HiddenDragonCharacter.ToString() );
return doesNotContainSpaces && containsAtLeastOneHiddenDragonCharacter;
}
#endregion Methods
}
}