/src/wrappers/glib/partially-implemented/iterator_on_utf8_string.e

http://github.com/tybor/Liberty · Specman e · 84 lines · 49 code · 15 blank · 20 comment · 1 complexity · 982617f1ed9e6f7887e9c3755fe30721 MD5 · raw file

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