FormattingUtil

Description

static class Tinman.Core.Formatting.FormattingUtil

Helper class for dealing with unicode characters.

Public / Methods

FormatBytes


[Pure]
public static method FormatBytes → (1)

bytes in : int64

The binary size, in bytes.

returns → string

The formatted size string.

Formats the given binary size using up to four decimal digits.

The following units are used:

  • 'b': byte

  • 'kb': kilo-byte (2^10)

  • 'mb': mega-byte (2^20)

  • 'gb': giga-byte (2^30)

  • 'tb': tera-byte (2^40)

  • 'pb': peta-byte (2^50)

  • 'eb': exa-byte (2^60)

FormatDegrees


[Pure]
public static method FormatDegrees → (1)

value in : float64

The angle value, in degrees.

returns → string

The formatted angle value.

Formats an angle value: '123°'

FormatMetric


[Pure]
public static method FormatMetric → (1)

length in : float64

The length, in metres.

returns → string

The formatted length string.

Formats the given metric length in a readable way (e.g. '10.5 cm').

The metric unit is chosen (km, m, cm or mm) so that the resulting string has a minimum number of decimal digits.

FormatOnOff


[Pure]
public static method FormatOnOff → (1)

value in : bool

The value.

returns → string

The formatted value.

Formats the given value as 'ON' resp. 'OFF'.

FormatPercent


[Pure]
public static method FormatPercent → (1)

value in : float64

The decimal value.

returns → string

The formatted angle in degrees.

Formats a percent value: '100%'

FormatRadians


[Pure]
public static method FormatRadians → (1)

value in : float64

The angle value, in radians.

returns → string

The formatted angle in degrees.

Formats an angle value: '123°'

FormatReadable


[Pure]
public static method FormatReadable → (1)

value in : float64

Some value.

returns → float64

The nicely readable value.

Returns the largest positive nicely readable value that is less than or equal to the given value.

A nicely readable value can be expressed with 10^N*M where N is an integer and M is one of: 1, 2, 5.
For example:
0.1, 0.2, 0.5, 1, 2, 5, 10

FormatTimeSpan

2 overloads


[Pure]
public static method FormatTimeSpan1 → (2)

time in : float64

[>=0]
The time span, in milliseconds.

format opt : int32 = 0

[0..5]
The time index format:
0: 1w 1d 1h 1m 1s
1: HH:MM:SS,FFF
2: HH:MM:SS,FF
3: HH:MM:SS,F
4: HH:MM:SS
5: HH:MM

returns → string

The formatted time index string.

Formats the given time span as HH:MM:SS,FFF.


[Pure]
public static method FormatTimeSpan2 → (2)

time in : int64

[>=0]
The time span, in milliseconds.

format opt : int32 = 0

[0..5]
The time index format:
0: 1w 1d 1h 1m 1s
1: HH:MM:SS,FFF
2: HH:MM:SS,FF
3: HH:MM:SS,F
4: HH:MM:SS
5: HH:MM

returns → string

The formatted time index string.

Formats the given time span as HH:MM:SS,FFF.

GetCategory


[Pure]
public static method GetCategory → (1)

in : char

The character value.

returns → CharacterCategory

The unicode category.

Returns the unicode category of the given character.

GetCharacters

2 overloads


public static method GetCharacters1 → (3)

from in : char

Start of character range (inclusive).

to in : char

End of character range (inclusive).

bag opt : IBag<char> = null

Optional output bag.

returns → IBag<char>

The characters.

Returns all characters in the given range.


public static method GetCharacters2 → (2)

categories in : CharacterCategory

The character categories.

bag opt : IBag<char> = null

Optional output bag.

returns → IBag<char>

The characters.

Returns all characters that belong to the given categories.

IsCategory


[Pure]
public static method IsCategory → (2)

in : char

The character value.

categories in : CharacterCategory

The character categories.

returns → bool

true if in has at least one category given by categories in, false if not.

Checks if the given character belongs to any of the given categories.

IsNewline


[Pure]
public static method IsNewline → (1)

in : char

The character to check.

returns → bool

true if in is a newline, false if not.

Checks if the given character represents or is part of a line ending (see LineEnding).

IsWhitespace


[Pure]
public static method IsWhitespace → (1)

in : char

The character to check.

returns → bool

true if in is a whitespace, false if not.

Checks if the given character is a whitespace.

Using this method is equivalent to calling IsCategory with the CharacterCategory.Whitespace and CharacterCategory.OtherControl flags. However, this method is more efficient.

Newline

2 overloads


public static method Newline1 → (2)

text in : string

The text to normalize.

lineEnding opt : LineEnding = LineEnding.Native

The line ending to use.

returns → string

The normalized text or null if text in was null.

Replaces all newline tokens in text in with the specified newline token.


[Pure]
public static method Newline2 → (1)

lineEnding opt : LineEnding = LineEnding.Native

The line ending.

returns → string

The newline token.

Returns the newline token string.

TextToLines


[Pure]
public static method TextToLines → (2)

text in : string

[not-null]
The text to split.

trim opt : bool = false

Trim text lines?

returns → string [ ]

The array of text lines.

Splits the given text into lines.

ToLineEnding


public static method ToLineEnding → (2)

text in : string

[not-null]
The input text.

lineEnding opt : LineEnding = LineEnding.Native

The desired line ending type.

returns → string

The normalized text.

Normalizes all line ending tokens in the given text.

Public / Attributes

NativeLineEnding


public static attribute NativeLineEnding → (get)

value : LineEnding

[not-null]
The newline token.

Returns the newline token of the underlying system.