1 """
2 String object attributes.
3
4 """
5
6 from fabmetheus_utilities import euclidean
7
8
9 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
10 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
11 __date__ = '$Date: 2008/02/05 $'
12 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
13
14
23
24
26 'Class to handle a string.'
28 'Initialize.'
29 self.stringObject = stringObject
30
32 "Get the string representation of this StringAttribute."
33 return self.stringObject
34
35 - def add(self, nextString):
36 'Get the add string, same as append.'
37 return self.stringObject + nextString
38
40 'Get the append string.'
41 return self.stringObject + nextString
42
44 'Get the copy.'
45 return self.stringObject[:]
46
48 'Get the delete string.'
49 deleteString = ''
50 enumeratorSet = set(euclidean.getEnumeratorKeysAlwaysList(self.stringObject, arguments))
51 for characterIndex, character in enumerate(self.stringObject):
52 if characterIndex not in enumeratorSet:
53 deleteString += character
54 return deleteString
55
56 - def get(self, itemIndex):
57 'Get value by characterIndex'
58 return self.stringObject[itemIndex]
59
61 'Get the concatenated copies.'
62 expansion = ''
63 for itemIndex in xrange(items):
64 expansion += self.stringObject
65 return expansion
66
68 'Determine if the value is in.'
69 return value in self.stringObject
70
72 'Determine if the value is in.'
73 return not(value in self.stringObject)
74
76 'Get the length.'
77 return len(self.stringObject)
78
80 'Get the max.'
81 return max(self.stringObject)
82
84 'Get the min.'
85 return min(self.stringObject)
86
87 - def insert(self, insertIndex, value):
88 'Get the insert string.'
89 if insertIndex < 0:
90 insertIndex += len(self.stringObject)
91 insertIndex = max(0, insertIndex)
92 return self.stringObject[: insertIndex] + value + self.stringObject[insertIndex :]
93
95 'Get the keys.'
96 return range(len(self.stringObject))
97
99 'Get the length.'
100 return len(self.stringObject)
101
103 'Get the remove string.'
104 removeIndex = self.stringObject.find(value)
105 if removeIndex > -1:
106 return self.stringObject[: removeIndex] + self.stringObject[removeIndex + len(value) :]
107 return self.stringObject
108
110 'Get the reverse string.'
111 return self.stringObject[: : -1]
112
113 - def set(self, itemIndex, value):
114 'Set value.'
115 self.stringObject[itemIndex] = value
116 return self.stringObject
117
119 'Get the values.'
120 values = []
121 for character in self.stringObject:
122 values.append(character)
123 return values
124
125
126 globalAccessibleAttributes = 'add append copy delete get getExpansion getIsIn getIsNotIn getLength getMax getMin'.split()
127 globalAccessibleAttributes += 'insert keys length remove reverse set values'.split()
128 globalGetAccessibleAttributeSet = set(globalAccessibleAttributes)
129 globalNativeFunctions = 'capitalize center count decode encode endswith expandtabs find format index isalnum join'.split()
130 globalNativeFunctions += 'isalpha isdigit islower isspace istitle isupper ljust lower lstrip partition replace rfind rindex'.split()
131 globalNativeFunctions += 'rjust rpartition rsplit rstrip split splitlines startswith strip swapcase title translate upper zfill'.split()
132 globalNativeFunctionSet = set(globalNativeFunctions)
133