Skip to content

TextStudioTextUnitBoundary

ClassTextStudioTextStudio
public static class TextStudioTextUnitBoundary

Allocation-free Unicode text-unit traversal using UTF-16 offsets. Inline objects remain atomic.

public static int Count(string text)

Counts Unicode text units in a string, returning zero for null or empty text.

Parameters

NameType
textSystem.String

Returns

System.Int32

public static int GetPrefixLength(string text, int maximumUnits)

Returns the UTF-16 length of a prefix containing at most the requested number of complete text units.

Parameters

NameType
textSystem.String
maximumUnitsSystem.Int32

Returns

System.Int32

public static int FloorBoundary(string text, int index)

Returns the nearest text-unit boundary at or before the supplied UTF-16 offset, clamped to the string.

Parameters

NameType
textSystem.String
indexSystem.Int32

Returns

System.Int32

public static int CeilingBoundary(string text, int index)

Returns the nearest text-unit boundary at or after the supplied UTF-16 offset, clamped to the string.

Parameters

NameType
textSystem.String
indexSystem.Int32

Returns

System.Int32

public static int Move(string text, int index, int offset)

Moves by a signed number of complete text units from the floored UTF-16 offset, stopping at string boundaries.

Parameters

NameType
textSystem.String
indexSystem.Int32
offsetSystem.Int32

Returns

System.Int32

public static int CountBefore(string text, int index)

Counts complete text units ending at or before the supplied UTF-16 offset.

Parameters

NameType
textSystem.String
indexSystem.Int32

Returns

System.Int32

public static int GetPreviousBoundary(string text, int index)

Returns the preceding text-unit boundary for the supplied UTF-16 offset, or zero at the start of the string.

Parameters

NameType
textSystem.String
indexSystem.Int32

Returns

System.Int32

public static int GetUnitEnd(string text, int unitStart)

Returns the UTF-16 end offset of the text unit beginning at the supplied offset, keeping inline objects atomic.

Parameters

NameType
textSystem.String
unitStartSystem.Int32

Returns

System.Int32