docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct TMP_TextProcessingStack<T>

    Structure used to track XML tags of various types.

    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    ValueType.ToString()
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: TMPro
    Assembly: Unity.TextMeshPro.dll
    Syntax
    public struct TMP_TextProcessingStack<T>
    Type Parameters
    Name Description
    T

    The element type of the stack.

    Constructors

    TMP_TextProcessingStack(int)

    Constructor for a new item stack with the given capacity.

    Declaration
    public TMP_TextProcessingStack(int capacity)
    Parameters
    Type Name Description
    int capacity

    Number of slots to allocate in the internal item array before any push operations.

    Remarks

    Allocates capacity entries up front so nested rich-text tags can push state without resizing during typical markup depth.

    TMP_TextProcessingStack(int, int)

    Declaration
    public TMP_TextProcessingStack(int capacity, int rolloverSize)
    Parameters
    Type Name Description
    int capacity
    int rolloverSize

    TMP_TextProcessingStack(T[])

    Constructor to create a new item stack.

    Declaration
    public TMP_TextProcessingStack(T[] stack)
    Parameters
    Type Name Description
    T[] stack

    Backing array that stores stack entries; capacity equals this array length.

    Remarks

    Initializes internal counters so the stack starts empty while reusing the provided buffer to avoid an extra allocation when the caller already sized the array.

    Fields

    index

    Declaration
    public int index
    Field Value
    Type Description
    int

    itemStack

    Declaration
    public T[] itemStack
    Field Value
    Type Description
    T[]

    Properties

    Count

    Gets the number of items currently stored on the stack.

    Declaration
    public int Count { get; }
    Property Value
    Type Description
    int
    Remarks

    Backed by m_Count, which push, pop, and remove operations keep aligned with the logical depth of active rich-text scopes.

    current

    Returns the current item on the stack.

    Declaration
    public T current { get; }
    Property Value
    Type Description
    T

    rolloverSize

    Gets or sets the rollover size used when the stack wraps in circular-buffer mode.

    Declaration
    public int rolloverSize { get; set; }
    Property Value
    Type Description
    int
    Remarks

    When set to zero, pushes grow the backing array; when positive, the stack index wraps modulo the rollover size to cap memory for unbounded tag nesting.

    Methods

    Add(T)

    Adds a new item to the stack.

    Declaration
    public void Add(T item)
    Parameters
    Type Name Description
    T item

    Value to store at the current write index when capacity allows further growth.

    Remarks

    Writes only when index is below the backing array length; this legacy path does not expand storage, unlike Push(T).

    Clear()

    Clears and resets stack to first item.

    Declaration
    public void Clear()
    Remarks

    Resets the logical count and index so the next push or set default rebuilds state from scratch without reallocating the backing array reference.

    CurrentItem()

    Function to retrieve the current item from the stack.

    Declaration
    public T CurrentItem()
    Returns
    Type Description
    T

    The current item T from the stack.

    Peek()

    Returns the top item on the stack without removing it.

    Declaration
    public T Peek()
    Returns
    Type Description
    T

    The most recently pushed value, or the baseline entry at index zero when nothing has been pushed yet.

    Remarks

    Non-destructive read used when parsers need the active style without mutating the stack during lookahead.

    Pop()

    Declaration
    public T Pop()
    Returns
    Type Description
    T

    PreviousItem()

    Retrieves the previous item without affecting the stack.

    Declaration
    public T PreviousItem()
    Returns
    Type Description
    T

    The value one level below the top when at least two entries exist; otherwise the first slot.

    Remarks

    Useful when comparing the prior style to the active style while leaving the stack unchanged for subsequent characters.

    Push(T)

    Declaration
    public void Push(T item)
    Parameters
    Type Name Description
    T item

    Remove()

    Retrieves an item from the stack.

    Declaration
    public T Remove()
    Returns
    Type Description
    T

    The value exposed after decrementing the stack pointer, or the default slot when collapsing to one entry.

    Remarks

    Decrements both index and count, clamping to one level so current always has a defined fallback entry at index zero.

    SetDefault(T)

    Sets the first item on the stack and reset index.

    Declaration
    public void SetDefault(T item)
    Parameters
    Type Name Description
    T item

    Baseline value written to index zero and returned when the stack would otherwise be empty.

    Remarks

    Lazily allocates the backing array when null, then sets index to one so subsequent adds append rich-text overrides above the default style.

    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)