Case insensitive strings class. Performs like str except comparisons are case insensitive.
| 1 | class iStr(str): |
| 2 | """Case insensitive strings class. |
| 3 | Performs like str except comparisons are case insensitive.""" |
| 4 | |
| 5 | def __init__(self, strMe): |
| 6 | str.__init__(self, strMe) |
| 7 | self.__lowerCaseMe = strMe.lower() |
| 8 | |
| 9 | def __repr__(self): |
| 10 | return "iStr(%s)" % str.__repr__(self) |
| 11 | |
| 12 | def __eq__(self, other): |
| 13 | return self.__lowerCaseMe == other.lower() |
| 14 | |
| 15 | def __lt__(self, other): |
| 16 | return self.__lowerCaseMe < other.lower() |
| 17 | |
| 18 | def __le__(self, other): |
| 19 | return self.__lowerCaseMe <= other.lower() |
| 20 | |
| 21 | def __gt__(self, other): |
| 22 | return self.__lowerCaseMe > other.lower() |
| 23 | |
| 24 | def __ne__(self, other): |
| 25 | return self.__lowerCaseMe != other.lower() |
| 26 | |
| 27 | def __ge__(self, other): |
| 28 | return self.__lowerCaseMe >= other.lower() |
| 29 | |
| 30 | def __cmp__(self, other): |
| 31 | return cmp(self.__lowerCaseMe, other.lower()) |
| 32 | |
| 33 | def __hash__(self): |
| 34 | return hash(self.__lowerCaseMe) |
| 35 | |
| 36 | def __contains__(self, other): |
| 37 | return other.lower() in self.__lowerCaseMe |
| 38 | |
| 39 | def count(self, other, *args): |
| 40 | return str.count(self.__lowerCaseMe, other.lower(), *args) |
| 41 | |
| 42 | def endswith(self, other, *args): |
| 43 | return str.endswith(self.__lowerCaseMe, other.lower(), *args) |
| 44 | |
| 45 | def find(self, other, *args): |
| 46 | return str.find(self.__lowerCaseMe, other.lower(), *args) |
| 47 | |
| 48 | def index(self, other, *args): |
| 49 | return str.index(self.__lowerCaseMe, other.lower(), *args) |
| 50 | |
| 51 | def lower(self): # Courtesy Duncan Booth |
| 52 | return self.__lowerCaseMe |
| 53 | |
| 54 | def rfind(self, other, *args): |
| 55 | return str.rfind(self.__lowerCaseMe, other.lower(), *args) |
| 56 | |
| 57 | def rindex(self, other, *args): |
| 58 | return str.rindex(self.__lowerCaseMe, other.lower(), *args) |
| 59 | |
| 60 | def startswith(self, other, *args): |
nothing calls this directly
no outgoing calls
no test coverage detected