@@ -27,7 +27,7 @@ use crate::cformat::{
2727 CNumberType ,
2828} ;
2929use crate :: format:: { FormatParseError , FormatPart , FormatPreconversor , FormatSpec , FormatString } ;
30- use crate :: function:: { OptionalArg , PyFuncArgs } ;
30+ use crate :: function:: { OptionalArg , OptionalOption , PyFuncArgs } ;
3131use crate :: pyhash;
3232use crate :: pyobject:: {
3333 Either , IdProtocol , IntoPyObject , ItemProtocol , PyClassImpl , PyContext , PyIterable ,
@@ -474,36 +474,35 @@ impl PyString {
474474 }
475475
476476 #[ pymethod]
477- fn strip ( & self , chars : OptionalArg < Option < PyStringRef > > ) -> String {
478- let chars = chars. flat_option ( ) ;
479- let chars = match chars {
480- Some ( ref chars) => & chars. value ,
481- None => return self . value . trim ( ) . to_owned ( ) ,
482- } ;
483- self . value . trim_matches ( |c| chars. contains ( c) ) . to_owned ( )
477+ fn strip ( & self , chars : OptionalOption < PyStringRef > ) -> String {
478+ self . value
479+ . py_strip (
480+ chars,
481+ |s, chars| s. trim_matches ( |c| chars. contains ( c) ) ,
482+ |s| s. trim ( ) ,
483+ )
484+ . to_owned ( )
484485 }
485486
486487 #[ pymethod]
487- fn lstrip ( & self , chars : OptionalArg < Option < PyStringRef > > ) -> String {
488- let chars = chars. flat_option ( ) ;
489- let chars = match chars {
490- Some ( ref chars) => & chars. value ,
491- None => return self . value . trim_start ( ) . to_owned ( ) ,
492- } ;
488+ fn lstrip ( & self , chars : OptionalOption < PyStringRef > ) -> String {
493489 self . value
494- . trim_start_matches ( |c| chars. contains ( c) )
490+ . py_strip (
491+ chars,
492+ |s, chars| s. trim_start_matches ( |c| chars. contains ( c) ) ,
493+ |s| s. trim_start ( ) ,
494+ )
495495 . to_owned ( )
496496 }
497497
498498 #[ pymethod]
499- fn rstrip ( & self , chars : OptionalArg < Option < PyStringRef > > ) -> String {
500- let chars = chars. flat_option ( ) ;
501- let chars = match chars {
502- Some ( ref chars) => & chars. value ,
503- None => return self . value . trim_end ( ) . to_owned ( ) ,
504- } ;
499+ fn rstrip ( & self , chars : OptionalOption < PyStringRef > ) -> String {
505500 self . value
506- . trim_end_matches ( |c| chars. contains ( c) )
501+ . py_strip (
502+ chars,
503+ |s, chars| s. trim_end_matches ( |c| chars. contains ( c) ) ,
504+ |s| s. trim_end ( ) ,
505+ )
507506 . to_owned ( )
508507 }
509508
0 commit comments