Parsing methods from String
to various simple types.
Contains parsers for common types, like numbers, dates and times.
Additional parsers may be provided by implementing StringParser or FormattedStringParser traits and putting given instances in scope. StringParser
may be implemented if there are no different formatting options for given type, e.g. for integers (although one may argue if this is a good example). For all cases when different formatting options exist, FormattedStringParser
should be implemented.
Attributes
- Companion
- trait
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
StringParser.type
Members list
Type members
Classlikes
Intermediary to delegate parsing to in order to infer type of formatter used by parser.
Intermediary to delegate parsing to in order to infer type of formatter used by parser.
When adding parsing function to an entity, instead of providing
def parse[A, B](input: String, format: B)(using parser: FormattedStringParser[A, B]): ParseResult[A]
which requires then to use it as
entity.parse[Double, NumberFormat]("123,45", numberFormat)
one can provide function to get this Pattern
def parse[A]: Pattern[A]
and use it with nicer syntax
entity.parse[Double]("123,45", numberFormat)
Type parameters
- A
-
target type for parsing
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
Parser for decimal values with support for formats.
Parser for decimal values with support for formats.
Attributes
- Supertypes
- Self type
-
bigDecimalParserFmt.type
Parser for boolean values with support for formats.
Parser for boolean values with support for formats.
Attributes
- Supertypes
- Self type
-
booleanParserFmt.type
Parser for double values with support for formats.
Parser for double values with support for formats.
Attributes
- Supertypes
- Self type
-
doubleParserFmt.type
Parser for integer values.
Parser for date values with support for formats.
Parser for date values with support for formats.
Attributes
- Supertypes
- Self type
-
localDateParserFmt.type
Parser for date with time values with support for formats.
Parser for date with time values with support for formats.
Attributes
- Supertypes
- Self type
Parser for time values with support for formats.
Parser for time values with support for formats.
Attributes
- Supertypes
- Self type
-
localTimeParserFmt.type
Parser for long values with support for formats.
Parser for long values with support for formats.
Attributes
- Supertypes
- Self type
-
longParserFmt.type
No-op parser for strings.
Value members
Concrete methods
Safely parses string to desired type.
Safely parses string to desired type.
Type parameters
- A
-
target type for parsing
Value parameters
- parser
-
the parser for specific target type
- str
-
the input string
Attributes
- Returns
-
either parsed value or an ParseError
- Example
-
import info.fingo.spata.text.StringParser.* val x = parse[Double]("123.45").getOrElse(Double.NaN) val y = parse[Option[Double]]("123.45").map(_.getOrElse(0.0)).getOrElse(Double.NaN)
Parses string to desired type based on provided format.
Parses string to desired type based on provided format.
Delegates actual parsing to Pattern#apply method.
Type parameters
- A
-
target type for parsing
Attributes
- Returns
-
intermediary to retrieve value according to custom format
- See also
-
parse without
Pattern
for sample usage.
Givens
Givens
Parser for decimal values with support for formats.
Parser for decimal values with support for formats.
Attributes
Parser for boolean values with support for formats.
Parser for boolean values with support for formats.
Attributes
Parser for double values with support for formats.
Parser for double values with support for formats.
Attributes
Parser for date values with support for formats.
Parser for date values with support for formats.
Attributes
Parser for date with time values with support for formats.
Parser for date with time values with support for formats.
Attributes
Parser for time values with support for formats.
Parser for time values with support for formats.
Attributes
Parser for long values with support for formats.
Parser for long values with support for formats.
Attributes
Parser for optional values. Allows conversion of any simple parser to return Option[A]
instead of A
, avoiding error for empty string.
Parser for optional values. Allows conversion of any simple parser to return Option[A]
instead of A
, avoiding error for empty string.
Type parameters
- A
-
the simple type wrapped by scala.Option
Value parameters
- parser
-
the parser for underlying simple type
Attributes
- Returns
-
parser which accepts empty input
Parser for optional values with support for different formats. Allows conversion of any simple parser to return Option[A]
instead of A
, avoiding error for empty string.
Parser for optional values with support for different formats. Allows conversion of any simple parser to return Option[A]
instead of A
, avoiding error for empty string.
Type parameters
- A
-
the simple type wrapped by scala.Option
- B
-
type of formatter
Value parameters
- parser
-
the parser for underlying simple type
Attributes
- Returns
-
parser which support formatted input and accepts empty one
No-op parser for strings.
No-op parser for strings.