192 """ |
192 """ |
193 Public method to get the character at a position in the text observing |
193 Public method to get the character at a position in the text observing |
194 multibyte characters. |
194 multibyte characters. |
195 |
195 |
196 @param pos position in the text (integer) |
196 @param pos position in the text (integer) |
197 @return raw character at the requested position or empty string, if the position |
197 @return character at the requested position or empty string, if the position |
198 is negative or past the end of the document (string) |
198 is negative or past the end of the document (string) |
199 """ |
199 """ |
200 ch = self.rawCharAt(pos) |
200 ch = self.byteAt(pos) |
201 if ch and ord(ch) > 127 and self.isUtf8(): |
201 if ch and ord(ch) > 127 and self.isUtf8(): |
202 if (ord(ch[0]) & 0xF0) == 0xF0: |
202 if (ch[0] & 0xF0) == 0xF0: |
203 utf8Len = 4 |
203 utf8Len = 4 |
204 elif (ord(ch[0]) & 0xE0) == 0xE0: |
204 elif (ch[0] & 0xE0) == 0xE0: |
205 utf8Len = 3 |
205 utf8Len = 3 |
206 elif (ord(ch[0]) & 0xC0) == 0xC0: |
206 elif (ch[0] & 0xC0) == 0xC0: |
207 utf8Len = 2 |
207 utf8Len = 2 |
208 while len(ch) < utf8Len: |
208 while len(ch) < utf8Len: |
209 pos += 1 |
209 pos += 1 |
210 ch += self.rawCharAt(pos) |
210 ch += self.byteAt(pos) |
211 return ch.decode('utf8') |
211 return ch.decode('utf8') |
212 else: |
212 else: |
213 return ch |
213 return ch.decode() |
214 |
214 |
215 def rawCharAt(self, pos): |
215 def byteAt(self, pos): |
216 """ |
216 """ |
217 Public method to get the raw character at a position in the text. |
217 Public method to get the raw character (bytes) at a position in the text. |
218 |
218 |
219 @param pos position in the text (integer) |
219 @param pos position in the text (integer) |
220 @return raw character at the requested position or empty string, if the position |
220 @return raw character at the requested position or empty bytes, if the position |
221 is negative or past the end of the document (string) |
221 is negative or past the end of the document (bytes) |
222 """ |
222 """ |
223 char = self.SendScintilla(QsciScintilla.SCI_GETCHARAT, pos) |
223 char = self.SendScintilla(QsciScintilla.SCI_GETCHARAT, pos) |
224 if char == 0: |
224 if char == 0: |
225 return "" |
225 return b"" |
226 elif char < 0: |
226 if char < 0: |
227 return chr(char + 256) |
227 char += 256 |
228 else: |
228 return bytes.fromhex("{0:02x}".format(char)) |
229 return chr(char) |
|
230 |
229 |
231 def foldLevelAt(self, line): |
230 def foldLevelAt(self, line): |
232 """ |
231 """ |
233 Public method to get the fold level of a line of the document. |
232 Public method to get the fold level of a line of the document. |
234 |
233 |