FormattedStringParser

info.fingo.spata.text.FormattedStringParser
trait FormattedStringParser[+A, B] extends StringParser[A]

Parser from String to desired type with support for different formats.

This parser defines behavior to be implemented by concrete, given parser instances for various types, used by [[StringParser.parseA* parse]] function from StringParser object.

Parsing fails on an empty input if a simple type is provided. To accept empty input Option[?] should be provided as type parameter.

Type parameters

A

target type for parsing

B

type of formatter

Attributes

Graph
Supertypes
trait StringParser[A]
class Object
trait Matchable
class Any
Known subtypes
object bigDecimalParserFmt.type
object booleanParserFmt.type
object doubleParserFmt.type
object localDateParserFmt.type
object localTimeParserFmt.type
object longParserFmt.type
Show all

Members list

Value members

Abstract methods

def apply(str: String, fmt: B): A

Parses string to desired type based on provided format.

Parses string to desired type based on provided format.

If parsing fails this function should throw ParseError, possibly wrapping root exception. This is further handled by parse to allow for exception-free, functional code.

Value parameters

fmt

formatter, specific for particular result type, e.g. DateTimeFormatter for dates and times

str

the input string

Attributes

Returns

parsed value

Throws
RuntimeException

if text cannot be parsed to requested type

Inherited methods

def apply(str: String): A

Parses string to desired type.

Parses string to desired type.

If parsing fails this function should report error by throwing exception. This is further handled by parse to allow for exception-free, functional code.

Value parameters

str

the input string

Attributes

Returns

parsed value

Throws
RuntimeException

if text cannot be parsed to requested type

Note

This function assumes "standard" string formatting, e.g. point as decimal separator or ISO date and time formats, without any locale support. Use FormattedStringParser if more control over source format is required.

Inherited from:
StringParser