-
Notifications
You must be signed in to change notification settings - Fork 2
StringFormatter
| Jump To | Go Back |
Methods | Variables |
|---|
Used to store a set of rules than can then be applied to strings to return a formatted result. For example, if you wanted to remove all the white space from a given string, or convert it to lower case letters. While GML does have built-in functions for this, StringFormatter can apply multiple rules to a string. It is generally designed for working with external files to produce a format that is easier for someone writing a parser.
var _formatter = new StringFormatter();
_formatter.set_rule( "\t ", "remove" );
var _string = _formatter.format( "Hel lo W o r ld!" );
show_debug_message( _string );
Output: HelloWorld! is written to the output console.
| Jump To | top |
format | set_rule | toString | remove | insert | replace | advance | safexor | safe | unsafe |
|---|
Returns: string
| Name | Type | Purpose |
|---|---|---|
| string | String | A string to format |
Formats the given string and returns it.
Throws: ValueNotFound, InvalidArgumentType
| Name | Type | Purpose |
|---|---|---|
| chars | String | A string containing the characters you would like to apply the rule to |
| func | Mixed | Either a string, the name of the rule to apply, or a function to apply |
Each character in the string will have the provided rule applied to it. There are a number of pre-made rules that can be applied: advance, remove, safe, unsafe, safexor. Otherwise, the provided function will be bound to the character. If a string is provided, but the rule does not exist, ValueNotFound is thrown. Otherwise InvalidArgumentType will be thrown if a method was not provided.
Returns: string
| Name | Type | Purpose |
|---|---|---|
| None |
Returns the last formatted string.
| Name | Type | Purpose |
|---|---|---|
| None |
Removes the last character read from the string
| Name | Type | Purpose |
|---|---|---|
| string | String | The string to insert |
No description.
| Name | Type | Purpose |
|---|---|---|
| string | String | The string to insert |
No description.
| Name | Type | Purpose |
|---|---|---|
| None |
Advances the read position. Can be used to skip a character, or to find a position to insert at.
| Name | Type | Purpose |
|---|---|---|
| None |
Toggles the ignore state. When ignoring, remove, insert and replace do not work. Can be used to preserve text between quotation marks, for example.
| Name | Type | Purpose |
|---|---|---|
| None |
Toggles the ignore state to true. When ignoring, remove, insert and replace do not work.
| Name | Type | Purpose |
|---|---|---|
| None |
Toggles the ignore state to false. When ignoring, remove, insert and replace do not work.
| Jump To | top |
|---|
| Name | Type | Initial | Purpose |
|---|---|---|---|
| __Rules | undef |
{} | No description. |
| __String | undef |
"" | No description. |
| __Ignore | undef |
false | No description. |
| __Read | undef |
0 | No description. |
Devon Mullane 2020