build static method

Parser build(
  1. String text
)

Builds a dynamic Parser on the fly and throws a NameException when unable to do so. The built parser only knows how to operate birth names.

Implementation

static Parser build(String text) {
  var parts = text.trim().split(Separator.space.token);
  var length = parts.length;
  if (parts.isEmpty || length == 1) {
    throw NameException.input(
      source: text,
      message: 'cannot build from invalid input',
    );
  } else if (length == 2 || length == 3) {
    return StringParser(text);
  } else {
    return ListStringParser([
      parts.first,
      parts.getRange(1, length - 1).join(' '),
      parts.last,
    ]);
  }
}