-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathPyStrIterator.h
59 lines (51 loc) · 1.47 KB
/
PyStrIterator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* File: PyStrIterator.h
* Author: Kent D. Lee
* (c) 2013
* Created on February 28, 2013, 9:55 AM
*
* License:
* Please read the LICENSE file in this distribution for details regarding
* the licensing of this code. This code is freely available for educational
* use. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
*
* Description:
* Iteration over a string is provided by this class. As with other iterators,
* calling the __iter__ magic method on an string iterator as shown below has
* no effect other than to return an alias to itself.
* Python 3.2.5 (default, Jul 22 2013, 10:45:32)
* [GCC 4.7.3] on linux2
* Type "help", "copyright", "credits" or "license" for more information.
* >>> s = "hello"
* >>> i = iter(s)
* >>> i.__next__()
* 'h'
* >>> j = iter(i)
* >>> j.__next__()
* 'e'
* >>> i.__next__()
* 'l'
* >>>
*
* When the iterator is exhausted, the __next__ magic method raises the
* PYSTOPITERATION exception. This is handled by the FOR_ITER instruction
* to end the iteration.
*/
#ifndef PYSTRITERATOR_H
#define PYSTRITERATOR_H
#include "PyObject.h"
#include "PyType.h"
#include "PyStr.h"
class PyStrIterator : public PyObject {
public:
PyStrIterator(PyStr* str);
virtual ~PyStrIterator();
PyType* getType();
string toString();
PyObject* __iter__(vector<PyObject*>* args);
PyObject* __next__(vector<PyObject*>* args);
private:
PyStr* str;
int index;
};
#endif /* PYSTRITERATOR_H */