rmeta • Lines: 661rust
�t #rustc 1.92.0 (ded5c06cf 2025-12-08)��� ⷄ�ۆ��p�� -225863f279df55c4� �١� �T�6a��D�
-5080178c80bf7a93� �uӰ]����d��!� -06039bcfba61f665� �**�٭T��HО�9� -3e2e950d4bac10b5�� �t�#3Ҵη��Ǣ -d25e598578fbf080� rustc_std_workspace_core������Nm��gmY��� -327ea4f353b4eb8c� ��y.:i���gy"1�r -94fdfaf0af91a65d� miniz_oxide�M�^�yTLm�L�d=B -5312b588e5cfab93� adler2��;~�7�ɴ,P?��� -1e0b0d62df36c85c� hashbrown�L�ϫ 2݆y��q -2ed6a8f06fc51a9d� rustc_std_workspace_alloc�a���p��H����6Z� -05b02707a5b2a256�
std_detect� c�LN����=1�ʶӐ -5978f0713dd5442d� rustc_demangle�X�Fq��UՃ�>7z
�� -43b2ff22c18e1125� cfg_if�֦<����ɐ¬� -6a40188dd7d989d2� addr2line���,2�!xb�"6�!� -11d54e777384a9e5� gimli��2��I.�ġ����� -35018e994bad7042� object��T �f��Y�
hQec -2dc10b344e05b569� memchr��xZT9�C��I�Mg� -09f2ab7e0d97e07a��~ݤ ����h��� -932f22f820d1e5ec�
quickcheck�T� �$� tests�,�o �$�o � MAX_UTF8_BYTES� char_utf8� TAG_CONT� TAG_TWO_B� TAG_THREE_B�
TAG_FOUR_B� MAX_ONE_B� MAX_TWO_B� MAX_THREE_B� encode_utf8� from_encoded_range� as_slice� � matches� 'a� IntoIter� � � � �
�
"�
Utf8Sequences� $ range_stack� &�
& reset� & push� ScalarRange� *� *� -� /� /� 1 1 4 split� 4 is_valid� 4 as_ascii� 4 is_ascii� 4� max_scalar_value� Utf8Sequence� ; One� <
<� ; Two� ?
?� A ; Three� C
C� E ; Four� G
G� I
L� M MM Q� R RR
W� Utf8Range� Y� Y� \� `� b� 8 8 88 8 8 88 88!8 #8 #8#8(8 )8 .8 .8.818 58 68 78 88 98 9898M8 R8 X8 X8]8 a8 a8c8 � ; < =� >� ? @� A� C D�
E� G H�
I� X3X�NA �� �� ��� ��� �H �
� �_� � Y Y � Z� [� ~��6�% �� ��� ��� �� �_� �_ * * � +� ,� ��uz$h�� �J $ $ �
%�
�L���Y{ K ;^ YL ;\ YQ ;b YV ;_ YW ;` Y
;" Y- */ $�J�
�
��
�
�H
�_�J�
�� � ,� $ 4� \�
� �o$ � " 0b1000_0000� \�
�� ��$
� � $ 0b1100_0000� \�
�� ��$ � � $ 0b1110_0000� \�
�� ��$ � � $ 0b1111_0000� $�
� ��"
� � $ 0x80� ,�
� ��" � � $ 0x800� <�
� ��" � � $ 0x10000� �
� B + � 6 = 2� �
� F + � 6 = 3� �
� J + � 6 = 4� � � � N � ) 1 2� � � � O � + 3 3� � � � P ! � - 5 4� � � �
S � $ , 2� � � � T � ( 0 3� � � � U � , 4 4� t�^
� 2 $ � / 6: � MAX_UTF8_BYTES� t�^
� 3 $ � / 6: � MAX_UTF8_BYTES� �
; = # � . � 5 < �
; @ # � . �� C J ,�
; D # � . �� C J $�
; H # � . �� C J $*:;Y� �$� �- �� �* �,� �/ � \� � �� � � �
Crate `utf8-ranges` converts ranges of Unicode scalar values to equivalent
ranges of UTF-8 bytes. This is useful for constructing byte based automatons
that need to embed UTF-8 decoding.
See the documentation on the `Utf8Sequences` iterator for more details and
an example.
# Wait, what is this?
This is simplest to explain with an example. Let's say you wanted to test
whether a particular byte sequence was a Cyrillic character. One possible
scalar value range is `[0400-04FF]`. The set of allowed bytes for this
range can be expressed as a sequence of byte ranges:
```ignore
[D0-D3][80-BF]
```
This is simple enough: simply encode the boundaries, `0400` encodes to
`D0 80` and `04FF` encodes to `D3 BF`, and create ranges from each
corresponding pair of bytes: `D0` to `D3` and `80` to `BF`.
However, what if you wanted to add the Cyrillic Supplementary characters to
your range? Your range might then become `[0400-052F]`. The same procedure
as above doesn't quite work because `052F` encodes to `D4 AF`. The byte ranges
you'd get from the previous transformation would be `[D0-D4][80-AF]`. However,
this isn't quite correct because this range doesn't capture many characters,
for example, `04FF` (because its last byte, `BF` isn't in the range `80-AF`).
Instead, you need multiple sequences of byte ranges:
```ignore
[D0-D3][80-BF] # matches codepoints 0400-04FF
[D4][80-AF] # matches codepoints 0500-052F
```
This gets even more complicated if you want bigger ranges, particularly if
they naively contain surrogate codepoints. For example, the sequence of byte
ranges for the basic multilingual plane (`[0000-FFFF]`) look like this:
```ignore
[0-7F]
[C2-DF][80-BF]
[E0][A0-BF][80-BF]
[E1-EC][80-BF][80-BF]
[ED][80-9F][80-BF]
[EE-EF][80-BF][80-BF]
```
Note that the byte ranges above will *not* match any erroneous encoding of
UTF-8, including encodings of surrogate codepoints.
And, of course, for all of Unicode (`[000000-10FFFF]`):
```ignore
[0-7F]
[C2-DF][80-BF]
[E0][A0-BF][80-BF]
[E1-EC][80-BF][80-BF]
[ED][80-9F][80-BF]
[EE-EF][80-BF][80-BF]
[F0][90-BF][80-BF][80-BF]
[F1-F3][80-BF][80-BF][80-BF]
[F4][80-8F][80-BF][80-BF]
```
This crate automates the process of creating these byte ranges from ranges of
Unicode scalar values.
# Why would I ever use this?
You probably won't ever need this. In 99% of cases, you just decode the byte
sequence into a Unicode scalar value and compare scalar values directly.
However, this explicit decoding step isn't always possible. For example, the
construction of some finite state machines may benefit from converting ranges
of scalar values into UTF-8 decoder automata (e.g., for character classes in
regular expressions).
# Lineage
I got the idea and general implementation strategy from Russ Cox in his
[article on regexps](https://swtch.com/~rsc/regexp/regexp3.html) and RE2.
Russ Cox got it from Ken Thompson's `grep` (no source, folk lore?).
I also got the idea from
[Lucene](https://github.com/apache/lucene-solr/blob/trunk/lucene/core/src/java/org/apache/lucene/util/automaton/UTF32ToUTF8.java),
which uses it for executing automata on their term index.
� $*:;Y�� �� �- �� �* �� �/ � � L�
D� �T� ��� ��� t� �l� L�
�oDu ���L� ���\� ���T� ���L� ���L� ���\� ���D\� d d
�������� �� ������ �;t���� �
character�L� dst���� � �� 7 �� e f e�@ f�@ � �
�,� �� ��'&