Class: ActiveLdap::Ldif::Scanner

Inherits:
Object
  • Object
show all
Defined in:
lib/active_ldap/ldif.rb

Constant Summary collapse

SEPARATOR =
/(?:\r\n|\n)/u

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Scanner

Returns a new instance of Scanner.



480
481
482
483
484
# File 'lib/active_ldap/ldif.rb', line 480

def initialize(source)
  @source = source
  @scanner = StringScanner.new(@source)
  @sub_scanner = next_segment || StringScanner.new("")
end

Instance Method Details

#[](*args) ⇒ Object



521
522
523
# File 'lib/active_ldap/ldif.rb', line 521

def [](*args)
  @sub_scanner[*args]
end

#check(regexp) ⇒ Object



491
492
493
494
# File 'lib/active_ldap/ldif.rb', line 491

def check(regexp)
  @sub_scanner = next_segment if @sub_scanner.eos?
  @sub_scanner.check(regexp)
end

#check_separatorObject



502
503
504
505
506
# File 'lib/active_ldap/ldif.rb', line 502

def check_separator
  return @scanner.check(SEPARATOR) if @sub_scanner.eos?

  check(SEPARATOR)
end

#columnObject



539
540
541
542
543
544
# File 'lib/active_ldap/ldif.rb', line 539

def column
  _consumed_source = consumed_source
  return 1 if _consumed_source.empty?

  position - (_consumed_source.rindex("\n") || -1)
end

#eos?Boolean

Returns:

  • (Boolean)


525
526
527
528
# File 'lib/active_ldap/ldif.rb', line 525

def eos?
  @sub_scanner = next_segment if @sub_scanner.eos?
  @sub_scanner.eos? and @scanner.eos?
end

#lineObject



530
531
532
533
534
535
536
537
# File 'lib/active_ldap/ldif.rb', line 530

def line
  _consumed_source = consumed_source
  return 1 if _consumed_source.empty?

  n = _consumed_source.to_a.size
  n += 1 if _consumed_source[-1, 1] == "\n"
  n
end

#positionObject



546
547
548
# File 'lib/active_ldap/ldif.rb', line 546

def position
  @scanner.pos - (@sub_scanner.string.length - @sub_scanner.pos)
end

#scan(regexp) ⇒ Object



486
487
488
489
# File 'lib/active_ldap/ldif.rb', line 486

def scan(regexp)
  @sub_scanner = next_segment if @sub_scanner.eos?
  @sub_scanner.scan(regexp)
end

#scan_separatorObject



496
497
498
499
500
# File 'lib/active_ldap/ldif.rb', line 496

def scan_separator
  return @scanner.scan(SEPARATOR) if @sub_scanner.eos?

  scan(SEPARATOR)
end

#scan_separatorsObject



508
509
510
511
512
513
514
515
516
517
518
519
# File 'lib/active_ldap/ldif.rb', line 508

def scan_separators
  return @scanner.scan(/#{SEPARATOR}+/u) if @sub_scanner.eos?

  sub_result = scan(/#{SEPARATOR}+/u)
  return nil if sub_result.nil?
  return sub_result unless @sub_scanner.eos?

  result = @scanner.scan(/#{SEPARATOR}+/u)
  return sub_result if result.nil?

  sub_result + result
end