| 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2 | // Copyright (c) 2018 Saxonica Limited. |
| 3 | // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. |
| 4 | // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. |
| 6 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 7 | |
| 8 | |
| 9 | package net.sf.saxon.regex.charclass; |
| 10 | |
| 11 | import net.sf.saxon.z.IntSet; |
| 12 | import net.sf.saxon.z.IntSingletonSet; |
| 13 | |
| 14 | /** |
| 15 | * A character class represents a set of characters for regex matching purposes. A singleton |
| 16 | * character class matches exactly one character |
| 17 | */ |
| 18 | |
| 19 | public class SingletonCharacterClass implements CharacterClass { |
| 20 | |
| 21 | private int codepoint; |
| 22 | |
| 23 | public SingletonCharacterClass(int codepoint) { |
| 24 | this.codepoint = codepoint; |
| 25 | } |
| 26 | |
| 27 | public boolean test(int value) { |
| 28 | return value == codepoint; |
| 29 | } |
| 30 | |
| 31 | public boolean isDisjoint(CharacterClass other) { |
| 32 | return !other.test(codepoint); |
| 33 | } |
| 34 | |
| 35 | public int getCodepoint() { |
| 36 | return codepoint; |
| 37 | } |
| 38 | |
| 39 | public IntSet getIntSet() { |
| 40 | return new IntSingletonSet(codepoint); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | } |