Skip to content

Section

xtay2 edited this page Feb 15, 2023 · 5 revisions

Introduction

The Section class is a terminal that matches any section enclosed in two symbols. This can get used for comments or strings.

Constructors

  • Section(char open, char close): Initializes a new instance of the Section class with the specified open and close characters but without an escape-symbol.
  • Section(char open, char close, char escape): Initializes a new instance of the Section class with the specified open and close characters, and the escape character.

Methods

  • matches(String input): boolean: Returns true if the input string is completely surrounded by an unescaped open- and close-symbol.
  • maxMatchLength(String input): int: Returns the length of the longest substring of the input string that matches the section.
  • firstMatch(String input): int: Returns the first index of the first match of the section in the input string.

Examples

new Section('[', ']', '/');

Matches

"[]"
"[some content]"
"[other /]content]"

Fails

"[]]"
"]["
"/[]"

Clone this wiki locally