@@ -1392,7 +1392,7 @@ public static char ConvertToChar(string s) {
13921392 [ SpecialName , ImplicitConversionMethod ]
13931393 public static IEnumerable ConvertToIEnumerable ( string s ) {
13941394 // make an enumerator that produces strings instead of chars
1395- return new PythonStringEnumerable ( s ) ;
1395+ return new PythonStrIterator ( s ) ;
13961396 }
13971397
13981398 internal static int Compare ( string self , string obj ) {
@@ -2145,92 +2145,12 @@ private static bool startswith(string self, PythonTuple prefix, int start, int e
21452145 return false ;
21462146 }
21472147
2148- // note: any changes in how this iterator works should also be applied in the
2149- // optimized overloads of Builtins.map()
2150- [ PythonType ( "str_iterator" ) ]
2151- public class PythonStringEnumerable : IEnumerable , IEnumerator < string > {
2152- private readonly string /*!*/ _s ;
2153- private int _index ;
2154-
2155- public PythonStringEnumerable ( string s ) {
2156- Assert . NotNull ( s ) ;
2157-
2158- _index = - 1 ;
2159- _s = s ;
2160- }
2161-
2162- public PythonTuple __reduce__ ( CodeContext /*!*/ context ) {
2163- object iter ;
2164- context . TryLookupBuiltin ( "iter" , out iter ) ;
2165- return PythonTuple . MakeTuple (
2166- iter ,
2167- PythonTuple . MakeTuple ( _s ) ,
2168- _index + 1
2169- ) ;
2170- }
2171-
2172- public void __setstate__ ( int index ) {
2173- _index = index - 1 ;
2174- }
2175-
2176- #region IEnumerable Members
2177-
2178- public IEnumerator GetEnumerator ( ) {
2179- return this ;
2180- }
2181-
2182- #endregion
2183-
2184- #region IEnumerator<string> Members
2185-
2186- public string Current {
2187- get {
2188- if ( _index < 0 ) {
2189- throw PythonOps . SystemError ( "Enumeration has not started. Call MoveNext." ) ;
2190- } else if ( _index >= _s . Length ) {
2191- throw PythonOps . SystemError ( "Enumeration already finished." ) ;
2192- }
2193- return ScriptingRuntimeHelpers . CharToString ( _s [ _index ] ) ;
2194- }
2195- }
2196-
2197- #endregion
2198-
2199- #region IDisposable Members
2200-
2201- public void Dispose ( ) { }
2202-
2203- #endregion
2204-
2205- #region IEnumerator Members
2206-
2207- object IEnumerator . Current {
2208- get {
2209- return ( ( IEnumerator < string > ) this ) . Current ;
2210- }
2211- }
2212-
2213- public bool MoveNext ( ) {
2214- if ( _index >= _s . Length ) {
2215- return false ;
2216- }
2217- _index ++ ;
2218- return _index != _s . Length ;
2219- }
2220-
2221- public void Reset ( ) {
2222- _index = - 1 ;
2223- }
2224-
2225- #endregion
2226- }
2227-
22282148 internal static IEnumerable StringEnumerable ( string str ) {
2229- return new PythonStringEnumerable ( str ) ;
2149+ return new PythonStrIterator ( str ) ;
22302150 }
22312151
22322152 internal static IEnumerator < string > StringEnumerator ( string str ) {
2233- return new PythonStringEnumerable ( str ) ;
2153+ return new PythonStrIterator ( str ) ;
22342154 }
22352155
22362156 #endregion
0 commit comments