/[eiffelstudio]/branches/eth/eve/Src/framework/javascript_base/eiffel_base/native/eiffel_string.e
ViewVC logotype

Contents of /branches/eth/eve/Src/framework/javascript_base/eiffel_base/native/eiffel_string.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 86166 - (show annotations)
Fri Apr 8 11:40:41 2011 UTC (8 years, 6 months ago) by adima
File size: 7504 byte(s)
JavaScript compiler:
- Removed UI code from the ``circles'' example, now it represent the model
- Added ``circles_vision2'' and ``circles_javascript'', two examples which use ``circles'' to show code reuse

1 note
2 description : "JavaScript implementation of EiffelBase class STRING and variations."
3 author : "Alexandru Dima <alex.dima@gmail.com>"
4 copyright : "Copyright (C) 2011, Alexandru Dima"
5 date : "$Date$"
6 revision : "$Revision$"
7 javascript : "EiffelBaseNativeStub: STRING, STRING_8, READABLE_STRING_8, STRING_32, READABLE_STRING_32"
8 class
9 EIFFEL_STRING
10 inherit
11 ANY
12 redefine is_equal, out end
13
14 create
15 make_empty,
16 make_from_string
17
18 feature {NONE} -- Initialization
19
20 make_from_string (other: attached STRING)
21 external "C" alias "#$other" end
22
23 make_empty
24 external "C" alias "#%"%"" end
25
26 feature -- Basic Operation
27
28 append (other: attached STRING)
29 external "C" alias "$TARGET += $other" end
30
31 append_boolean (b: BOOLEAN)
32 external "C" alias "$TARGET += $b ? %"true%" : %"false%"" end
33
34 append_character (other: CHARACTER)
35 external "C" alias "$TARGET += $other" end
36
37 append_code (c: CHARACTER)
38 external "C" alias "$TARGET += String.fromCharCode($c)" end
39
40 append_double (d: DOUBLE)
41 external "C" alias "$TARGET += ($d).toString()" end
42
43 append_integer (i: INTEGER)
44 external "C" alias "$TARGET += ($i).toString()" end
45
46 append_natural (n: NATURAL)
47 external "C" alias "$TARGET += ($n).toString()" end
48
49 append_real (r: REAL)
50 external "C" alias "$TARGET += ($r).toString()" end
51
52 append_string (s: STRING)
53 external "C" alias "$TARGET += $s" end
54
55 as_lower: attached STRING
56 external "C" alias "toLowerCase()" end
57
58 as_string_8: attached STRING
59 external "C" alias "$TARGET" end
60
61 as_string_32: attached STRING
62 external "C" alias "$TARGET" end
63
64 as_upper: attached STRING
65 external "C" alias "toUpperCase()" end
66
67 at alias "@" (i: INTEGER): CHARACTER
68 external "C" alias "charAt($i-1)" end
69
70 code (i: INTEGER): INTEGER
71 external "C" alias "charCodeAt($i-1)" end
72
73 count : INTEGER
74 external "C" alias "length" end
75
76 ends_with (other: attached STRING) : BOOLEAN
77 external "C" alias "($TARGET.indexOf($other) + ($other).length === $TARGET.length)" end
78
79 extend (c: CHARACTER)
80 external "C" alias "$TARGET += $c" end
81
82 false_constant: STRING
83 external "C" alias "#%"false%"" end
84
85 has (other: CHARACTER): BOOLEAN
86 external "C" alias "($TARGET.indexOf($other)>=0)" end
87
88 has_code (c: INTEGER): BOOLEAN
89 external "C" alias "($TARGET.indexOf(String.fromCharCode($c))>=0)" end
90
91 has_substring (other: attached STRING): BOOLEAN
92 external "C" alias "($TARGET.indexOf($other)>=0)" end
93
94 index_of (other: CHARACTER; start_index: INTEGER): INTEGER
95 external "C" alias "($TARGET.indexOf($other, $start_index - 1) + 1)" end
96
97 index_of_code (c: INTEGER; start_index: INTEGER): INTEGER
98 external "C" alias "($TARGET.indexOf(String.fromCharCode($c), $start_index - 1) + 1)" end
99
100 insert_character (c: CHARACTER; i: INTEGER)
101 external "C" alias "$TARGET = $TARGET.substring(0,$i-1) + $c + $TARGET.substring($i-1)" end
102
103 insert_string (s: STRING; i: INTEGER)
104 external "C" alias "$TARGET = $TARGET.substring(0,$i-1) + $s + $TARGET.substring($i-1)" end
105
106 is_boolean: BOOLEAN
107 external "C" alias "($TARGET===%"true%" || $TARGET===%"false%")" end
108
109 is_double: BOOLEAN
110 external "C" alias "(!isNaN($TARGET))" end
111
112 is_equal (other: like Current): BOOLEAN
113 external "C" alias "$TARGET === $other" end
114
115 is_empty: BOOLEAN
116 external "C" alias "($TARGET === %"%")" end
117
118 is_integer: BOOLEAN
119 external "C" alias "(!isNaN($TARGET) && $TARGET.indexOf('.')===-1)" end
120
121 is_natural: BOOLEAN
122 external "C" alias "(!isNaN($TARGET) && $TARGET.indexOf('.')===-1)" end
123
124 is_real: BOOLEAN
125 external "C" alias "(!isNaN($TARGET))" end
126
127 item alias "[]" (i: INTEGER): CHARACTER
128 external "C" alias "charAt($i-1)" end
129
130 item_code (i: INTEGER): INTEGER
131 external "C" alias "charCodeAt($i-1)" end
132
133 keep_head (n: INTEGER)
134 external "C" alias "$TARGET = $TARGET.substring(0, $n)" end
135
136 keep_tail (n: INTEGER)
137 external "C" alias "$TARGET = $TARGET.substring($TARGET.length-$n)" end
138
139 last_index_of (other: CHARACTER; start_index_from_end: INTEGER): INTEGER
140 external "C" alias "($TARGET.lastIndexOf($other, $start_index_from_end - 1) + 1)" end
141
142 left_adjust
143 external "C" alias "$TARGET = $TARGET.replace(/^\s+/,%"%")" end
144
145 out: attached STRING
146 external "C" alias "$TARGET" end
147
148 plus alias "+" (other: attached STRING) : attached STRING
149 external "C" alias "$TARGET + $other" end
150
151 precede (c: CHARACTER)
152 external "C" alias "$TARGET = $c + $TARGET" end
153
154 prepend (other: attached STRING)
155 external "C" alias "$TARGET = $other + $TARGET" end
156
157 prepend_boolean (b: BOOLEAN)
158 external "C" alias "$TARGET = ($b ? %"true%" : %"false%") + $TARGET" end
159
160 prepend_character (other: CHARACTER)
161 external "C" alias "$TARGET = $other + $TARGET" end
162
163 prepend_code (c: CHARACTER)
164 external "C" alias "$TARGET = String.fromCharCode($c) + $TARGET" end
165
166 prepend_double (d: DOUBLE)
167 external "C" alias "$TARGET = ($d).toString() + $TARGET" end
168
169 prepend_integer (i: INTEGER)
170 external "C" alias "$TARGET = ($i).toString() + $TARGET" end
171
172 prepend_natural (n: NATURAL)
173 external "C" alias "$TARGET = ($n).toString() + $TARGET" end
174
175 prepend_real (r: REAL)
176 external "C" alias "$TARGET = ($r).toString() + $TARGET" end
177
178 prepend_string (s: STRING)
179 external "C" alias "$TARGET = $s + $TARGET" end
180
181 put (c: CHARACTER; i: INTEGER)
182 external "C" alias "$TARGET = $TARGET.substring(0,$i-1) + $c + $TARGET.substring($i)" end
183
184 put_code (c: NATURAL; i: INTEGER)
185 external "C" alias "$TARGET = $TARGET.substring(0,$i-1) + String.fromCharCode($c) + $TARGET.substring($i)" end
186
187 remove (i: INTEGER)
188 external "C" alias "$TARGET = $TARGET.substring(0,$i-1) + $TARGET.substring($i)" end
189
190 remove_head (n: INTEGER)
191 external "C" alias "$TARGET = $TARGET.substring($n)" end
192
193 remove_substring (start_index, end_index: INTEGER)
194 external "C" alias "$TARGET = $TARGET.substring(0,$start_index-1) + $TARGET.substring($end_index)" end
195
196 remove_tail (n: INTEGER)
197 external "C" alias "$TARGET = $TARGET.substring(0,$TARGET.length-$n)" end
198
199 replace_substring (str: STRING; start_index, end_index: INTEGER)
200 external "C" alias "$TARGET = $TARGET.substring(0,$start_index-1) + $str + $TARGET.substring($end_index-1)" end
201
202 right_adjust
203 external "C" alias "$TARGET = $TARGET.replace(/\s+$/,%"%")" end
204
205 set (t: STRING; n1, n2: INTEGER)
206 external "C" alias "$TARGET = $t.substring($n1-1, $n2)" end
207
208 split (separator: CHARACTER): attached LIST[attached STRING]
209 external "C" alias "new EIFFEL_LIST(%"make_from_array%", $TARGET.split($separator))" end
210
211 starts_with (other: attached STRING) : BOOLEAN
212 external "C" alias "indexOf($other) === 0" end
213
214 string: STRING
215 external "C" alias "$TARGET" end
216
217 string_representation: STRING
218 external "C" alias "$TARGET" end
219
220 substring (a_from, a_to: INTEGER): attached STRING
221 external "C" alias "substring($a_from-1, $a_to)" end
222
223 substring_index (other: attached STRING; start_index: INTEGER): INTEGER
224 external "C" alias "($TARGET.indexOf($other, $start_index - 1) + 1)" end
225
226 to_boolean: BOOLEAN
227 external "C" alias "($TARGET === %"true%" ? true : false)" end
228
229 to_double: DOUBLE
230 external "C" alias "parseFloat($TARGET)" end
231
232 to_integer: INTEGER
233 external "C" alias "parseInt($TARGET, 10)" end
234
235 to_lower
236 external "C" alias "$TARGET=$TARGET.toLowerCase()" end
237
238 to_natural: INTEGER
239 external "C" alias "parseInt($TARGET, 10)" end
240
241 to_real: DOUBLE
242 external "C" alias "parseFloat($TARGET)" end
243
244 to_upper
245 external "C" alias "$TARGET=$TARGET.toUpperCase()" end
246
247 true_constant: STRING
248 external "C" alias "#%"true%"" end
249
250 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date ID Revision

  ViewVC Help
Powered by ViewVC 1.1.23