API reference
GD.text
Entry for formatting and comparing text.
Methods
closest(word: String, options: PackedStringArray) -> Stringellipsis(text: String, width: int) -> Stringsize_of(bytes: int) -> Stringduration(ms: float) -> Stringdistance(a: String, b: String) -> intsnake(text: String) -> Stringcamel(text: String) -> Stringtitle(text: String) -> Stringtable(rows: Array, gap: int = 2) -> Stringdistance_async(a: String, b: String) -> await intclosest_async(word: String, options: PackedStringArray) -> await Stringellipsis_async(text: String, width: int) -> await Stringsnake_async(text: String) -> await Stringcamel_async(text: String) -> await Stringtitle_async(text: String) -> await Stringtable_async(rows: Array, gap: int = 2) -> await String
closest
closest(word: String, options: PackedStringArray) -> StringChoose the candidate closest to the supplied text. This is useful for suggesting corrections to a mistyped command or option.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
word | String | Required | Input to compare against candidates. |
options | PackedStringArray | Required | Candidate strings in selection order. |
Return value
String
The first candidate with the smallest edit distance, or an empty string if its distance exceeds max(2, word.length() / 3) or there are no candidates.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
See also
ellipsis
ellipsis(text: String, width: int) -> StringShorten text to fit a width and append an ellipsis.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
text | String | Required | Input string. |
width | int | Required | Maximum output length in characters. |
Return value
String
The original text when it fits, otherwise a shortened form.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
size_of
size_of(bytes: int) -> StringFormat a byte count with readable units.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
bytes | int | Required | Byte count to format. |
Return value
String
A human-readable size string.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
duration
duration(ms: float) -> StringFormat milliseconds as a readable duration.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
ms | float | Required | Duration in milliseconds. |
Return value
String
A human-readable duration string.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
distance
distance(a: String, b: String) -> intCompute the edit distance between two strings. A lower result means fewer single-character edits are needed; zero means the strings match.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
a | String | Required | First string. |
b | String | Required | Second string. |
Return value
int
A nonnegative edit count.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
See also
snake
snake(text: String) -> StringConvert text to snake_case.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
text | String | Required | Text to inspect, decode or transform; the input is not modified in place. |
Return value
String
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
camel
camel(text: String) -> StringConvert text to camelCase.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
text | String | Required | Text to inspect, decode or transform; the input is not modified in place. |
Return value
String
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
title
title(text: String) -> StringConvert text to Title Case.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
text | String | Required | Text to inspect, decode or transform; the input is not modified in place. |
Return value
String
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
table
table(rows: Array, gap: int = 2) -> StringFormat rows as an aligned text table.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
rows | Array | Required | Rows in input order. Batch database calls use one parameter set per row. |
gap | int | 2 | Number of spaces between formatted table columns. |
Return value
String
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
distance_async
distance_async(a: String, b: String) -> await intCompute the edit distance between two strings. A lower result means fewer single-character edits are needed; zero means the strings match.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
a | String | Required | First string. |
b | String | Required | Second string. |
Return value
await int
A nonnegative edit count.
Returns a Signal. Use await to receive the completion value shown in the signature.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
See also
closest_async
closest_async(word: String, options: PackedStringArray) -> await StringChoose the candidate closest to the supplied text. This is useful for suggesting corrections to a mistyped command or option.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
word | String | Required | Input to compare against candidates. |
options | PackedStringArray | Required | Candidate strings in selection order. |
Return value
await String
The first candidate with the smallest edit distance, or an empty string if its distance exceeds max(2, word.length() / 3) or there are no candidates.
Returns a Signal. Use await to receive the completion value shown in the signature.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
See also
ellipsis_async
ellipsis_async(text: String, width: int) -> await StringDispatch text shortening to a CPU worker.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
text | String | Required | Text to inspect, decode or transform; the input is not modified in place. |
width | int | Required | Maximum width in characters for the formatted text. |
Return value
await String
Returns a Signal. Use await to receive the completion value shown in the signature.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
snake_async
snake_async(text: String) -> await StringDispatch snake-case conversion to a CPU worker.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
text | String | Required | Text to inspect, decode or transform; the input is not modified in place. |
Return value
await String
Returns a Signal. Use await to receive the completion value shown in the signature.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
camel_async
camel_async(text: String) -> await StringDispatch camel-case conversion to a CPU worker.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
text | String | Required | Text to inspect, decode or transform; the input is not modified in place. |
Return value
await String
Returns a Signal. Use await to receive the completion value shown in the signature.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
title_async
title_async(text: String) -> await StringDispatch title-case conversion to a CPU worker.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
text | String | Required | Text to inspect, decode or transform; the input is not modified in place. |
Return value
await String
Returns a Signal. Use await to receive the completion value shown in the signature.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
table_async
table_async(rows: Array, gap: int = 2) -> await StringDispatch text-table formatting to a CPU worker.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
rows | Array | Required | Rows in input order. Batch database calls use one parameter set per row. |
gap | int | 2 | Number of spaces between formatted table columns. |
Return value
await String
Returns a Signal. Use await to receive the completion value shown in the signature.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.