character_range.interval#
Implementation of Interval,
CharacterInterval and ByteInterval.
- class CharacterInterval(start: _Char, end: _Char)[source]#
Class variables
- _max_value: ClassVar[int] = 1114111#
The maximum integral value of a Unicode codepoint:
0x10FFFF.
- class ByteInterval(start: _Char, end: _Char)[source]#
Class variables
- _max_value: ClassVar[int] = 255#
The maximum integral value of a byte (16 bits):
0xFF.
- class Interval(start: _Char, end: _Char)[source]#
An interval (both ends inclusive) of characters, represented using either
strorbytes.Class variables
- _max_value: ClassVar[int]#
The maximum integral value that can be converted to a character.
Magic methods
- __getitem__(item: slice) Self[source]#
- __getitem__(item: SupportsIndex) _Char
O(1)indexing of character or byte.sliceobjects are also supported.
- __len__() int[source]#
The length of the interval, equivalent to
codepoint(end) - codepoint(start) + 1.
- __contains__(item: Any) bool[source]#
Assert that
itemis a valid element and that it is lexicographically greater than or equals to that ofstartand less than or equals to that ofend.
- __str__() str[source]#
Return an ASCII representation of the range, typically looks like
\x00-a,\--\uFFFDor\U00100000.
- __eq__(other: object) bool[source]#
Two intervals are equal if one is an instance of the other’s class and their endpoints have the same integral values.
- __and__(other: Self) bool[source]#
See
intersects().
Properties
- property start: _Char#
The starting endpoint of the interval.
- property end: _Char#
The ending endpoint of the interval.
- abstract property element_type: type[_Char]#
A class-based property that returns the type of the interval’s elements.
Methods
- to_codepoint_range() range[source]#
Convert the interval to a native
rangethat would yield the codepoints of the elements of the interval.
Class methods
- classmethod from_codepoint_range(codepoint_range: range, /) Self[source]#
Construct an interval from a
rangeof codepoints.As a technical limit, for a
CharacterInterval, the codepoint of an endpoint must not be negative or greater than0x10FFFF. Similarly, for aByteInterval, the integral value of an endpoint must be in the interval[0, 255].
- exception InvalidIntervalDirection(start: _Char, stop: _Char)[source]#
Bases:
ValueErrorRaised when an interval constructor is passed a
startwhose value is greater than that ofend.
- exception NotACharacter(actual: object)[source]#
Bases:
ValueErrorRaised when an object is expected to be a character (a
strof length 1) but it is not one.