object StringParser
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 implicit values 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.
- Alphabetic
- By Inheritance
- StringParser
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- class Pattern[A] extends AnyRef
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: A, format: B)(implicit 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)
- A
target type for parsing
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- implicit val bigDecimalParser: FormattedStringParser[BigDecimal, DecimalFormat]
Parser for decimal values with support for formats.
- implicit val booleanParser: FormattedStringParser[Boolean, BooleanFormatter]
Parser for boolean values with support for formats.
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- implicit val doubleParser: FormattedStringParser[Double, DecimalFormat]
Parser for double values with support for formats.
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- implicit def fmtOptionParser[A, B](implicit parser: FormattedStringParser[A, B]): FormattedStringParser[Option[A], B]
Parser for optional values with support for different formats.
Parser for optional values with support for different formats. Allows conversion of any simple parser to return
Option[A]
instead ofA
, avoiding error for empty string.- A
the simple type wrapped by scala.Option
- B
type of formatter
- parser
the parser for underlying simple type
- returns
parser which support formatted input and accepts empty one
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- implicit val intParser: StringParser[Int]
Parser for integer values.
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- implicit val localDateParser: FormattedStringParser[LocalDate, DateTimeFormatter]
Parser for date values with support for formats.
- implicit val localDateTimeParser: FormattedStringParser[LocalDateTime, DateTimeFormatter]
Parser for date with time values with support for formats.
- implicit val localTimeParser: FormattedStringParser[LocalTime, DateTimeFormatter]
Parser for time values with support for formats.
- implicit val longParser: FormattedStringParser[Long, NumberFormat]
Parser for long values with support for formats.
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- implicit def optionParser[A](implicit parser: StringParser[A]): StringParser[Option[A]]
Parser for optional values.
Parser for optional values. Allows conversion of any simple parser to return
Option[A]
instead ofA
, avoiding error for empty string.- A
the simple type wrapped by scala.Option
- parser
the parser for underlying simple type
- returns
parser which accepts empty input
- def parse[A]: Pattern[A]
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.
- A
target type for parsing
- returns
intermediary to retrieve value according to custom format
- See also
parse for sample usage.
- def parse[A](str: String)(implicit parser: StringParser[A]): ParseResult[A]
Safely parses string to desired type.
Safely parses string to desired type.
- A
target type for parsing
- str
the input string
- parser
the parser for specific target type
- returns
either parsed value or an ParseError
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)
Example: - implicit val stringParser: StringParser[String]
No-op parser for strings.
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])