Class: ICU::CharDet::Detector
- Inherits:
-
Object
- Object
- ICU::CharDet::Detector
- Defined in:
- lib/ffi-icu/chardet.rb
Defined Under Namespace
Classes: Match
Instance Method Summary collapse
- #declared_encoding=(str) ⇒ Object
- #detect(str) ⇒ Object
- #detect_all(str) ⇒ Object
- #detectable_charsets ⇒ Object
-
#initialize ⇒ Detector
constructor
A new instance of Detector.
- #input_filter_enabled=(bool) ⇒ Object
- #input_filter_enabled? ⇒ Boolean
Constructor Details
#initialize ⇒ Detector
Returns a new instance of Detector.
12 13 14 15 |
# File 'lib/ffi-icu/chardet.rb', line 12 def initialize ptr = Lib.check_error { |err| Lib.ucsdet_open(err) } @detector = FFI::AutoPointer.new(ptr, Lib.method(:ucsdet_close)) end |
Instance Method Details
#declared_encoding=(str) ⇒ Object
25 26 27 28 29 |
# File 'lib/ffi-icu/chardet.rb', line 25 def declared_encoding=(str) Lib.check_error do |ptr| Lib.ucsdet_setDeclaredEncoding(@detector, str, str.size, ptr) end end |
#detect(str) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/ffi-icu/chardet.rb', line 31 def detect(str) set_text(str) match_ptr = Lib.check_error { |ptr| Lib.ucsdet_detect(@detector, ptr) } match_ptr_to_ruby(match_ptr) unless match_ptr.null? end |
#detect_all(str) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ffi-icu/chardet.rb', line 38 def detect_all(str) set_text(str) matches_found_ptr = FFI::MemoryPointer.new(:int32_t) array_ptr = Lib.check_error do |status| Lib.ucsdet_detectAll(@detector, matches_found_ptr, status) end length = matches_found_ptr.read_int array_ptr.read_array_of_pointer(length).map do |match| match_ptr_to_ruby(match) end end |
#detectable_charsets ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ffi-icu/chardet.rb', line 52 def detectable_charsets enum_ptr = Lib.check_error do |ptr| Lib.ucsdet_getAllDetectableCharsets(@detector, ptr) end result = Lib.enum_ptr_to_array(enum_ptr) Lib.uenum_close(enum_ptr) result end |
#input_filter_enabled=(bool) ⇒ Object
21 22 23 |
# File 'lib/ffi-icu/chardet.rb', line 21 def input_filter_enabled=(bool) Lib.ucsdet_enableInputFilter(@detector, !!bool) end |
#input_filter_enabled? ⇒ Boolean
17 18 19 |
# File 'lib/ffi-icu/chardet.rb', line 17 def input_filter_enabled? Lib.ucsdet_isInputFilterEnabled(@detector) end |