Class: ActiveLdap::Ldif::Scanner
- Inherits:
-
Object
- Object
- ActiveLdap::Ldif::Scanner
- Defined in:
- lib/active_ldap/ldif.rb
Constant Summary
- SEPARATOR =
/(?:\r\n|\n)/
- SEPARATORS =
/(?:(?:^#.*)?#{SEPARATOR})+/
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #check(regexp) ⇒ Object
- #check_separator ⇒ Object
- #column ⇒ Object
- #eos? ⇒ Boolean
-
#initialize(source) ⇒ Scanner
constructor
A new instance of Scanner.
- #line ⇒ Object
- #position ⇒ Object
- #scan(regexp) ⇒ Object
- #scan_separator ⇒ Object
- #scan_separators ⇒ Object
Constructor Details
#initialize(source) ⇒ Scanner
Returns a new instance of Scanner
507 508 509 510 511 512 |
# File 'lib/active_ldap/ldif.rb', line 507 def initialize(source) @source = source @scanner = StringScanner.new(@source) @sub_scanner = nil @sub_scanner = next_segment || StringScanner.new("") end |
Instance Method Details
#[](*args) ⇒ Object
549 550 551 |
# File 'lib/active_ldap/ldif.rb', line 549 def [](*args) @sub_scanner[*args] end |
#check(regexp) ⇒ Object
519 520 521 522 |
# File 'lib/active_ldap/ldif.rb', line 519 def check(regexp) @sub_scanner = next_segment if @sub_scanner.eos? @sub_scanner.check(regexp) end |
#check_separator ⇒ Object
530 531 532 533 534 |
# File 'lib/active_ldap/ldif.rb', line 530 def check_separator return @scanner.check(SEPARATOR) if @sub_scanner.eos? check(SEPARATOR) end |
#column ⇒ Object
567 568 569 570 571 572 |
# File 'lib/active_ldap/ldif.rb', line 567 def column _consumed_source = consumed_source return 1 if _consumed_source.empty? position - (_consumed_source.rindex("\n") || -1) end |
#eos? ⇒ Boolean
553 554 555 556 |
# File 'lib/active_ldap/ldif.rb', line 553 def eos? @sub_scanner = next_segment if @sub_scanner.eos? @sub_scanner.eos? and @scanner.eos? end |
#line ⇒ Object
558 559 560 561 562 563 564 565 |
# File 'lib/active_ldap/ldif.rb', line 558 def line _consumed_source = consumed_source return 1 if _consumed_source.empty? n = Compatible.string_to_lines(_consumed_source).size n += 1 if _consumed_source[-1, 1] == "\n" n end |
#position ⇒ Object
574 575 576 577 578 579 580 581 582 |
# File 'lib/active_ldap/ldif.rb', line 574 def position sub_scanner_string = @sub_scanner.string if sub_scanner_string.respond_to?(:bytesize) sub_scanner_string_size = sub_scanner_string.bytesize else sub_scanner_string_size = sub_scanner_string.size end @scanner.pos - (sub_scanner_string_size - @sub_scanner.pos) end |
#scan(regexp) ⇒ Object
514 515 516 517 |
# File 'lib/active_ldap/ldif.rb', line 514 def scan(regexp) @sub_scanner = next_segment if @sub_scanner.eos? @sub_scanner.scan(regexp) end |
#scan_separator ⇒ Object
524 525 526 527 528 |
# File 'lib/active_ldap/ldif.rb', line 524 def scan_separator return @scanner.scan(SEPARATOR) if @sub_scanner.eos? scan(SEPARATOR) end |
#scan_separators ⇒ Object
536 537 538 539 540 541 542 543 544 545 546 547 |
# File 'lib/active_ldap/ldif.rb', line 536 def scan_separators return @scanner.scan(SEPARATORS) if @sub_scanner.eos? sub_result = scan(SEPARATORS) return nil if sub_result.nil? return sub_result unless @sub_scanner.eos? result = @scanner.scan(SEPARATORS) return sub_result if result.nil? sub_result + result end |