/// <inheritdoc/>
        public Boolean Equals(ShapedString other)
        {
            if (other == null || other.Length != Length)
            {
                return(false);
            }

            if (IsEmpty && other.Length == 0)
            {
                return(true);
            }

            if (Source is IStringSource <ShapedChar> src)
            {
                for (int ixstr = Start, ixother = 0; ixother < Length; ixstr++, ixother++)
                {
                    if (src[ixstr] != other[ixother])
                    {
                        return(false);
                    }
                }
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ShapedStringSegment"/> structure.
        /// </summary>
        /// <param name="source">The source <see cref="ShapedString"/> object from which the segment's shaped characters are retrieved.</param>
        public ShapedStringSegment(ShapedString source)
        {
            Contract.Require(source, nameof(source));

            this.Source = source;
            this.Start  = 0;
            this.Length = source.Length;

            this.hashCode = CalculateHashCode(source, 0, source.Length);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ShapedStringSegment"/> structure.
        /// </summary>
        /// <param name="source">The source <see cref="ShapedString"/> object from which the segment's shaped characters are retrieved.</param>
        /// <param name="start">The index of the segment's first shaped character within its parent shaped string.</param>
        /// <param name="length">The number of shaped characters in the segment.</param>
        public ShapedStringSegment(ShapedString source, Int32 start, Int32 length)
        {
            Contract.Require(source, nameof(source));
            Contract.EnsureRange(start >= 0 && start <= source.Length, nameof(start));
            Contract.EnsureRange(length >= 0 && start + length <= source.Length, nameof(length));

            this.Source = source;
            this.Start  = start;
            this.Length = length;

            this.hashCode = CalculateHashCode(source, start, length);
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShapedStringBuilder"/> class.
        /// </summary>
        /// <param name="value">The string that is used to initialize this instance.</param>
        /// <param name="capacity">The initial capacity of this instance's buffer, in characters.</param>
        public ShapedStringBuilder(ShapedString value, Int32 capacity = 0)
        {
            Contract.EnsureRange(capacity >= 0, nameof(capacity));

            if (capacity == 0)
            {
                capacity = DefaultCapacity;
            }

            this.buffer = new ShapedChar[capacity];

            if (value != null)
            {
                value.CopyTo(0, this.buffer, 0, value.Length);
                this.length = value.Length;
            }
        }
        /// <summary>
        /// Creates a new instance of <see cref="ShapedString"/> with the same value as a specified <see cref="ShapedString"/>.
        /// </summary>
        /// <param name="str">The string to copy.</param>
        /// <returns>A new string with the same value as <paramref name="str"/>.</returns>
        public static ShapedString Copy(ShapedString str)
        {
            Contract.Require(str, nameof(str));

            return(new ShapedString(str.FontFace, str.Language, str.Script, str.Direction, str.buffer));
        }
 /// <summary>
 /// Indicates whether the specified string is <see langword="null"/> or an empty string.
 /// </summary>
 /// <param name="value">The string to test.</param>
 /// <returns><see langword="true"/> if the <paramref name="value"/> parameter is <see langword="null"/>
 /// or an empty string; otherwise, <see langword="false"/>.</returns>
 public static Boolean IsNullOrEmpty(ShapedString value) =>
 (value == null || value.buffer.Length == 0);