11// good luck to those that follow; here be dragons
22
3- use super :: _sre:: MAXREPEAT ;
43use super :: constants:: { SreAtCode , SreCatCode , SreFlag , SreOpcode } ;
5- use crate :: builtins:: PyBytes ;
6- use crate :: bytesinner:: is_py_ascii_whitespace;
7- use crate :: pyobject:: { IntoPyObject , PyObjectRef } ;
8- use crate :: VirtualMachine ;
4+ use super :: MAXREPEAT ;
95use std:: collections:: HashMap ;
106use std:: convert:: TryFrom ;
11- use std:: unreachable;
7+
8+ const fn is_py_ascii_whitespace ( b : u8 ) -> bool {
9+ matches ! ( b, b'\t' | b'\n' | b'\x0C' | b'\r' | b' ' | b'\x0B' )
10+ }
1211
1312#[ derive( Debug ) ]
14- pub ( crate ) struct State < ' a > {
13+ pub struct State < ' a > {
1514 pub string : StrDrive < ' a > ,
1615 pub start : usize ,
1716 pub end : usize ,
@@ -29,7 +28,7 @@ pub(crate) struct State<'a> {
2928}
3029
3130impl < ' a > State < ' a > {
32- pub ( crate ) fn new (
31+ pub fn new (
3332 string : StrDrive < ' a > ,
3433 start : usize ,
3534 end : usize ,
@@ -150,7 +149,7 @@ impl<'a> State<'a> {
150149}
151150
152151#[ derive( Debug , Clone , Copy ) ]
153- pub ( crate ) enum StrDrive < ' a > {
152+ pub enum StrDrive < ' a > {
154153 Str ( & ' a str ) ,
155154 Bytes ( & ' a [ u8 ] ) ,
156155}
@@ -219,21 +218,6 @@ impl<'a> StrDrive<'a> {
219218 StrDrive :: Bytes ( _) => offset - skip,
220219 }
221220 }
222-
223- pub fn slice_to_pyobject ( & self , start : usize , end : usize , vm : & VirtualMachine ) -> PyObjectRef {
224- match * self {
225- StrDrive :: Str ( s) => s
226- . chars ( )
227- . take ( end)
228- . skip ( start)
229- . collect :: < String > ( )
230- . into_pyobject ( vm) ,
231- StrDrive :: Bytes ( b) => {
232- PyBytes :: from ( b. iter ( ) . take ( end) . skip ( start) . cloned ( ) . collect :: < Vec < u8 > > ( ) )
233- . into_pyobject ( vm)
234- }
235- }
236- }
237221}
238222
239223#[ derive( Debug , Clone , Copy ) ]
@@ -972,7 +956,7 @@ fn is_loc_word(ch: u32) -> bool {
972956fn is_linebreak ( ch : u32 ) -> bool {
973957 ch == '\n' as u32
974958}
975- pub ( crate ) fn lower_ascii ( ch : u32 ) -> u32 {
959+ pub fn lower_ascii ( ch : u32 ) -> u32 {
976960 u8:: try_from ( ch)
977961 . map ( |x| x. to_ascii_lowercase ( ) as u32 )
978962 . unwrap_or ( ch)
@@ -1044,13 +1028,13 @@ fn is_uni_alnum(ch: u32) -> bool {
10441028fn is_uni_word ( ch : u32 ) -> bool {
10451029 ch == '_' as u32 || is_uni_alnum ( ch)
10461030}
1047- pub ( crate ) fn lower_unicode ( ch : u32 ) -> u32 {
1031+ pub fn lower_unicode ( ch : u32 ) -> u32 {
10481032 // TODO: check with cpython
10491033 char:: try_from ( ch)
10501034 . map ( |x| x. to_lowercase ( ) . next ( ) . unwrap ( ) as u32 )
10511035 . unwrap_or ( ch)
10521036}
1053- pub ( crate ) fn upper_unicode ( ch : u32 ) -> u32 {
1037+ pub fn upper_unicode ( ch : u32 ) -> u32 {
10541038 // TODO: check with cpython
10551039 char:: try_from ( ch)
10561040 . map ( |x| x. to_uppercase ( ) . next ( ) . unwrap ( ) as u32 )
0 commit comments