using System;
namespace Substrate.Nbt
{
///
/// A concrete representing a .
///
public sealed class SchemaNodeString : SchemaNode
{
private string _value = "";
private int _length;
///
/// Gets the maximum length of a valid string.
///
public int Length
{
get { return _length; }
}
///
/// Gets the expected value of a valid string.
///
/// A must be set to this value to be considered valid.
public string Value
{
get { return _value; }
}
///
/// Indicates whether there is a maximum-length constraint on strings in this node.
///
public bool HasMaxLength
{
get { return _length > 0; }
}
///
/// Constructs a new representing a named .
///
/// The name of the corresponding .
public SchemaNodeString (string name)
: base(name)
{
}
///
/// Constructs a new with additional options.
///
/// The name of the corresponding .
/// One or more option flags modifying the processing of this node.
public SchemaNodeString (string name, SchemaOptions options)
: base(name, options)
{
}
///
/// Constructs a new representing a named set to .
///
/// The name of the corresponding .
/// The value that the corresponding must be set to.
public SchemaNodeString (string name, string value)
: base(name)
{
_value = value;
}
///
/// Constructs a new with additional options.
///
/// The name of the corresponding .
/// The value that the corresponding must be set to.
/// One or more option flags modifying the processing of this node.
public SchemaNodeString (string name, string value, SchemaOptions options)
: base(name, options)
{
_value = value;
}
///
/// Constructs a new representing a named with maximum length .
///
/// The name of the corresponding .
/// The maximum length of strings in the corresponding .
public SchemaNodeString (string name, int length)
: base(name)
{
_length = length;
}
///
/// Constructs a new with additional options.
///
/// The name of the corresponding .
/// The maximum length of strings in the corresponding .
/// One or more option flags modifying the processing of this node.
public SchemaNodeString (string name, int length, SchemaOptions options)
: base(name, options)
{
_length = length;
}
///
/// Constructs a default satisfying the constraints of this node.
///
/// A with a sensible default value. If this node represents a particular string, the constructed will be set to that string.
public override TagNode BuildDefaultTree ()
{
if (_value.Length > 0) {
return new TagNodeString(_value);
}
return new TagNodeString();
}
}
}