@@ -169,10 +169,7 @@ def reshape(self, text):
169
169
support_zwj = self .configuration .getboolean ('support_zwj' )
170
170
positions_harakat = {}
171
171
172
- arabic_word_start = - 1
173
- zwjs = []
174
-
175
- for i , letter in enumerate (text ):
172
+ for letter in text :
176
173
if HARAKAT_RE .match (letter ):
177
174
if not delete_harakat :
178
175
position = len (output ) - 1
@@ -181,51 +178,15 @@ def reshape(self, text):
181
178
positions_harakat [position ].append (letter )
182
179
elif letter == TATWEEL and delete_tatweel :
183
180
pass
184
- elif letter == ZWJ and support_zwj :
185
- zwjs .append (i )
186
-
187
- if arabic_word_start != - 1 :
188
- # Handle three consecutive ZWJs or more
189
- if (
190
- len (zwjs ) > 2 and
191
- zwjs [- 2 ] == i - 1 and
192
- zwjs [- 3 ] == i - 2
193
- ):
194
- arabic_word_start = - 1
195
- # Handle when previous letter is not ZWJ
196
- elif (
197
- output and
198
- len (zwjs ) == 1 or (len (zwjs ) > 1 and zwjs [- 2 ] != i - 1 )
199
- ):
200
- previous_letter = output [- 1 ]
201
- if connects_with_letter_after (previous_letter [LETTER ]):
202
- if previous_letter [FORM ] == ISOLATED :
203
- output [- 1 ] = (
204
- previous_letter [LETTER ],
205
- INITIAL
206
- )
207
- else :
208
- output [- 1 ] = (
209
- previous_letter [LETTER ],
210
- MEDIAL
211
- )
181
+ elif letter == ZWJ and not support_zwj :
182
+ pass
212
183
elif letter not in LETTERS :
213
- arabic_word_start = - 1
214
184
output .append ((letter , NOT_SUPPORTED ))
215
185
elif not output : # first letter
216
- arabic_word_start = i
217
186
output .append ((letter , ISOLATED ))
218
187
else :
219
- if arabic_word_start == - 1 :
220
- arabic_word_start = i
221
188
previous_letter = output [- 1 ]
222
- if (
223
- arabic_word_start != i and
224
- zwjs and
225
- connects_with_letter_before (letter )
226
- ):
227
- output .append ((letter , FINAL ))
228
- elif previous_letter [FORM ] == NOT_SUPPORTED :
189
+ if previous_letter [FORM ] == NOT_SUPPORTED :
229
190
output .append ((letter , ISOLATED ))
230
191
elif not connects_with_letter_before (letter ):
231
192
output .append ((letter , ISOLATED ))
@@ -253,9 +214,12 @@ def reshape(self, text):
253
214
)
254
215
output .append ((letter , FINAL ))
255
216
256
- # clear ZWJs
257
- if zwjs and letter != ZWJ :
258
- zwjs = []
217
+ # Remove ZWJ if it's the second to last item as it won't be useful
218
+ if support_zwj and len (output ) > 1 and output [- 2 ][LETTER ] == ZWJ :
219
+ output .pop (len (output ) - 2 )
220
+
221
+ if support_zwj and output and output [- 1 ][LETTER ] == ZWJ :
222
+ output .pop ()
259
223
260
224
if self .configuration .getboolean ('support_ligatures' ):
261
225
# Clean text from Harakat to be able to find ligatures
0 commit comments