/[eiffelstudio]/FreeELKS/tags/EiffelSoftware/Eiffel_72/library/kernel/immutable_string_8.e
ViewVC logotype

Contents of /FreeELKS/tags/EiffelSoftware/Eiffel_72/library/kernel/immutable_string_8.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 92171 - (show annotations)
Thu Feb 7 20:27:54 2013 UTC (6 years, 9 months ago) by manus_eiffel
File size: 5637 byte(s)
Merged from rev#747:
Added `item' to READABLE_STRING_GENERAL and proper definition in READABLE_STRING_8 descendans. So that it is easier to migrate from compatible to regular mode.

1 note
2 description: "[
3 Sequences of immutable 8-bit characters, accessible through integer indices
4 in a contiguous range.
5 ]"
6 library: "Free implementation of ELKS library"
7 copyright: "Copyright (c) 1986-2008, Eiffel Software and others"
8 license: "Eiffel Forum License v2 (see forum.txt)"
9 date: "$Date$"
10 revision: "$Revision$"
11
12 class
13 IMMUTABLE_STRING_8
14
15 inherit
16 READABLE_STRING_8
17 undefine
18 is_immutable
19 redefine
20 copy, area_lower
21 end
22
23 IMMUTABLE_STRING_GENERAL
24 rename
25 same_string as same_string_general,
26 plus as plus_string_general,
27 item as character_32_item
28 undefine
29 is_equal, out, copy
30 end
31
32 create
33 make,
34 make_empty,
35 make_filled,
36 make_from_string,
37 make_from_c,
38 make_from_cil
39
40 create {IMMUTABLE_STRING_8}
41 make_from_area_and_bounds
42
43 convert
44 make_from_string ({READABLE_STRING_8, STRING_8}),
45 make_from_cil ({SYSTEM_STRING}),
46 to_cil: {SYSTEM_STRING},
47 as_string_32: {STRING_32},
48 as_string_8: {STRING_8}
49
50 feature {NONE} -- Initialization
51
52 make_from_area_and_bounds (a: like area; low, n: like count)
53 -- Initialize current with area `a' with lower bounds `low' and count `n'.
54 require
55 a_not_void: a /= Void
56 a_valid_count: (a.count - low) >= count + 1
57 low_non_negative: low >= 0
58 n_non_negative: n >= 0
59 do
60 area := a
61 area_lower := low
62 count := n
63 ensure
64 area_set: area = a
65 area_lower_set: area_lower = low
66 count_set: count = n
67 end
68
69 make_from_cil (a_system_string: SYSTEM_STRING)
70 -- <Precursor>
71 local
72 l_count: INTEGER
73 do
74 if a_system_string /= Void then
75 l_count := a_system_string.length
76 end
77 make (l_count)
78 if l_count > 0 then
79 dotnet_convertor.read_system_string_into_area_8 (a_system_string, area)
80 end
81 end
82
83 feature {IMMUTABLE_STRING_8} -- Duplication
84
85 copy (other: like Current)
86 -- <Precursor>
87 do
88 -- Because it is immutable we can simply share the `area' from `other'.
89 standard_copy (other)
90 ensure then
91 new_result_count: count = other.count
92 -- same_characters: For every `i' in 1..`count', `item' (`i') = `other'.`item' (`i')
93 end
94
95 feature -- Element change
96
97 plus alias "+" (s: READABLE_STRING_8): like Current
98 -- <Precursor>
99 local
100 a: like area
101 do
102 create a.make (count + s.count + 1)
103 a.copy_data (area, area_lower, 0, count)
104 a.copy_data (s.area, s.area_lower, count, s.count)
105 create Result.make_from_area_and_bounds (a, 0, count + s.count)
106 end
107
108 plus_string_general (s: READABLE_STRING_GENERAL): like Current
109 -- <Precursor>
110 local
111 a, a_8: like area
112 i, j, nb: INTEGER
113 l_s32_area: SPECIAL [CHARACTER_32]
114 do
115 create a.make (count + s.count + 1)
116 a.copy_data (area, area_lower, 0, count)
117 if attached {READABLE_STRING_8} s as l_s8 then
118 a.copy_data (l_s8.area, l_s8.area_lower, count, l_s8.count + 1)
119 elseif attached {READABLE_STRING_32} s as l_s32 then
120 create a_8.make (l_s32.count + 1)
121 from
122 i := 0
123 j := l_s32.area_lower
124 l_s32_area := l_s32.area
125 nb := l_s32.count - 1
126 until
127 i > nb
128 loop
129 a_8.put (l_s32_area [j].to_character_8, i)
130 i := i + 1
131 j := j + 1
132 end
133 a_8.put ('%/000/', i)
134 a.copy_data (a_8, 0, count, nb + 2)
135 end
136 create Result.make_from_area_and_bounds (a, 0, count + s.count)
137 end
138
139 mirrored: like Current
140 -- <Precursor>
141 local
142 a: like area
143 do
144 create a.make (count + 1)
145 a.copy_data (area, area_lower, 0, count)
146 mirror_area (a, 0, count - 1)
147 create Result.make_from_area_and_bounds (a, 0, count)
148 end
149
150 as_lower: like Current
151 -- <Precursor>
152 local
153 a: like area
154 do
155 create a.make (count + 1)
156 a.copy_data (area, area_lower, 0, count)
157 to_lower_area (a, 0, count - 1)
158 create Result.make_from_area_and_bounds (a, 0, count)
159 end
160
161 as_upper: like Current
162 -- <Precursor>
163 local
164 a: like area
165 do
166 create a.make (count + 1)
167 a.copy_data (area, area_lower, 0, count)
168 to_upper_area (a, 0, count - 1)
169 create Result.make_from_area_and_bounds (a, 0, count)
170 end
171
172 substring (start_index, end_index: INTEGER_32): like Current
173 -- <Precursor>
174 local
175 a: like area
176 do
177 if (1 <= start_index) and (start_index <= end_index) and (end_index <= count) then
178 create a.make (end_index - start_index + 2)
179 a.copy_data (area, area_lower + start_index - 1, 0, end_index - start_index + 1)
180 create Result.make_from_area_and_bounds (a, 0, end_index - start_index + 1)
181 else
182 Result := empty_string
183 end
184 end
185
186 shared_substring (start_index, end_index: INTEGER_32): like Current
187 -- <Precursor>
188 do
189 if (1 <= start_index) and (start_index <= end_index) and (end_index <= count) then
190 create Result.make_from_area_and_bounds (area, area_lower + start_index - 1, end_index - start_index + 1)
191 else
192 Result := empty_string
193 end
194 end
195
196 is_empty: BOOLEAN
197 -- Is structure empty?
198 do
199 Result := count = 0
200 end
201
202 linear_representation: LINEAR [CHARACTER_8]
203 -- Representation as a linear structure
204 local
205 temp: ARRAYED_LIST [CHARACTER_8]
206 i: INTEGER
207 do
208 create temp.make (capacity)
209 from
210 i := 1
211 until
212 i > count
213 loop
214 temp.extend (item (i))
215 i := i + 1
216 end
217 Result := temp
218 end
219
220 feature {NONE} -- Implementation
221
222 new_string (n: INTEGER_32): IMMUTABLE_STRING_8
223 -- <Precursor>
224 do
225 create Result.make (n)
226 end
227
228 empty_string: IMMUTABLE_STRING_8
229 -- Shared empty immutable string
230 once
231 create Result.make (0)
232 ensure
233 empty_string_not_void: Result /= Void
234 empty_string_empty: Result.is_empty
235 end
236
237 feature {READABLE_STRING_8, READABLE_STRING_32} -- Implementation
238
239 area_lower: INTEGER
240 -- Index where current string starts in `area'
241
242 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23