Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

StringFormatter

Hyomoto edited this page Jun 24, 2021 · 14 revisions
Jump To Go Back Methods Variables

StringFormatter( )

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.

Methods

Jump To top format set_rule toString remove insert replace advance safexor safe unsafe

format( string )

Returns: string

Name Type Purpose
string String A string to format

Formats the given string and returns it.


set_rule( chars, func )

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.


toString( )

Returns: string

Name Type Purpose
None

Returns the last formatted string.


remove( )

Name Type Purpose
None

Removes the last character read from the string


insert( string )

Name Type Purpose
string String The string to insert

No description.


replace( string )

Name Type Purpose
string String The string to insert

No description.


advance( )

Name Type Purpose
None

Advances the read position. Can be used to skip a character, or to find a position to insert at.


safexor( )

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.


safe( )

Name Type Purpose
None

Toggles the ignore state to true. When ignoring, remove, insert and replace do not work.


unsafe( )

Name Type Purpose
None

Toggles the ignore state to false. When ignoring, remove, insert and replace do not work.


Variables

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.

Clone this wiki locally