withParameters method

RegExpDialect withParameters({
  1. bool? multiLine = false,
  2. bool? caseSensitive = true,
  3. bool throwCompilationErrors = true,
})

Returns a copy of this instance with parameters multiLine and caseSensitive. If this instance already have the same parameters returns this instance.

If this instance hasErrors and throwCompilationErrors is true, throws a StateError. Otherwise the copy keeps the compilation errors (hasErrors, errorWords, ...), and getWordPattern throws a StateError for the words with errors, like this instance.

Implementation

RegExpDialect withParameters({
  bool? multiLine = false,
  bool? caseSensitive = true,
  bool throwCompilationErrors = true,
}) {
  multiLine ??= this.multiLine;
  caseSensitive ??= this.caseSensitive;

  if (hasErrors && throwCompilationErrors) {
    throw StateError(
      "Can't use a dialect with errors. Words with errors: ${errorWords.join(', ')}",
    );
  }

  if (this.multiLine == multiLine && this.caseSensitive == caseSensitive) {
    return this;
  }

  return RegExpDialect._(_dialect, multiLine, caseSensitive, _errors);
}