/src/wrappers/glib/partially-implemented/iterator_on_utf8_string.e
Specman e | 84 lines | 49 code | 15 blank | 20 comment | 1 complexity | 982617f1ed9e6f7887e9c3755fe30721 MD5 | raw file
1class ITERATOR_ON_UTF8_STRING 2 -- Iterator on UTF8 string. 3 4 -- 5inherit 6 ITERATOR[UNICODE_CHARACTER] 7 8insert 9 GUNICODE_EXTERNALS 10 -- GUNICODE_MACROS 11 12creation {UTF8_STRING} 13 make 14 15feature {} 16 string: UTF8_STRING 17 -- The string to be traversed 18 19 pointer: POINTER 20 -- Current position 21feature {ANY} 22 make (s: UTF8_STRING) is 23 require 24 s /= Void 25 do 26 string := s 27 pointer := string.handle 28 ensure 29 string = s 30 end 31 32 start is 33 do 34 pointer := string.handle 35 end 36 37 is_off: BOOLEAN is 38 do 39 Result := pointer > string.handle + string.bytes_count 40 end 41 42 is_before: BOOLEAN is 43 -- Is Current off, before the beginning of the string? 44 do 45 Result := pointer < string.handle 46 end 47 48 item: UNICODE_CHARACTER is 49 do 50 Result.set(g_utf8_get_char(pointer)) 51 end 52 53 next is 54 do 55 pointer := g_utf8_next_char (pointer) 56 end 57 58 prev is 59 -- Go backward. 60 local prev_ptr: POINTER 61 do 62 prev_ptr := g_utf8_prev_char(string.handle,pointer) 63 if prev_ptr.is_null then 64 -- no UTF-8 characters are presents before pointer in string. Set pointer to a something meaningful 65 pointer := pointer + (-1) 66 end 67 -- g_utf8_find_prev_char () 68 69 -- gchar* g_utf8_find_prev_char (const gchar *str, 70 -- const gchar *p); 71 72 -- Given a position p with a UTF-8 encoded string str, find the start of the 73 -- previous UTF-8 character starting before p. Returns NULL if no UTF-8 characters 74 -- are present in str before p. 75 76 -- p does not have to be at the beginning of a UTF-8 character. No check is made to 77 -- see if the character found is actually valid other than it starts with an 78 -- appropriate byte. 79 80 -- str : pointer to the beginning of a UTF-8 encoded string 81 -- p : pointer to some position within str 82 -- Returns : a pointer to the found character or NULL. 83 end 84end -- class ITERATOR_ON_UTF8_STRING