Table of Contents

Method TruncateAtTextElementBoundary

Namespace
MailFathom.Domain.Emails
Assembly
MailFathom.Domain.dll

TruncateAtTextElementBoundary(string, int)

Cuts text to at most a number of characters, never through the middle of one.

public static string TruncateAtTextElementBoundary(string text, int maxCharacters)

Parameters

text string

The text to bound.

maxCharacters int

The greatest number of UTF-16 characters the result may hold.

Returns

string

The text unchanged when it already fits; otherwise its longest prefix that ends on a text-element boundary.

Remarks

Text whose very first element is longer than the bound yields an empty string rather than a partial character. A caller for which nothing left is a meaningful outcome has to say what it means, which is why this reports it rather than substituting a replacement character.

Exceptions

ArgumentNullException

Thrown when text is null.

ArgumentOutOfRangeException

Thrown when maxCharacters is negative.