Class: HikiDoc::LineInput
- Inherits:
-
Object
- Object
- HikiDoc::LineInput
- Defined in:
- lib/vendor/hikidoc.rb
Instance Method Summary collapse
- #each ⇒ Object
- #eof? ⇒ Boolean
- #getblock(term_re) ⇒ Object
- #getlines_until(re) ⇒ Object (also: #break)
- #getlines_while(re) ⇒ Object (also: #span)
- #gets ⇒ Object
- #gets_if(re) ⇒ Object
- #gets_unless(re) ⇒ Object
-
#initialize(f) ⇒ LineInput
constructor
A new instance of LineInput.
- #inspect ⇒ Object
- #lineno ⇒ Object
- #next? ⇒ Boolean
- #peek ⇒ Object
- #skip_blank_lines ⇒ Object
- #ungets(line) ⇒ Object
- #until_match(re) ⇒ Object
- #until_terminator(re) ⇒ Object
- #while_match(re) ⇒ Object
Constructor Details
#initialize(f) ⇒ LineInput
Returns a new instance of LineInput.
755 756 757 758 759 760 |
# File 'lib/vendor/hikidoc.rb', line 755 def initialize(f) @input = f @buf = [] @lineno = 0 @eof_p = false end |
Instance Method Details
#each ⇒ Object
834 835 836 837 838 |
# File 'lib/vendor/hikidoc.rb', line 834 def each while line = gets() yield line end end |
#eof? ⇒ Boolean
766 767 768 |
# File 'lib/vendor/hikidoc.rb', line 766 def eof? @eof_p end |
#getblock(term_re) ⇒ Object
890 891 892 893 894 895 896 |
# File 'lib/vendor/hikidoc.rb', line 890 def getblock(term_re) buf = [] until_terminator(term_re) do |line| buf.push line end buf end |
#getlines_until(re) ⇒ Object Also known as: break
872 873 874 875 876 877 878 |
# File 'lib/vendor/hikidoc.rb', line 872 def getlines_until(re) buf = [] until_match(re) do |line| buf.push line end buf end |
#getlines_while(re) ⇒ Object Also known as: span
851 852 853 854 855 856 857 |
# File 'lib/vendor/hikidoc.rb', line 851 def getlines_while(re) buf = [] while_match(re) do |line| buf.push line end buf end |
#gets ⇒ Object
774 775 776 777 778 779 780 781 782 783 784 785 |
# File 'lib/vendor/hikidoc.rb', line 774 def gets unless @buf.empty? @lineno += 1 return @buf.pop end return nil if @eof_p # to avoid ARGF blocking. line = @input.gets line = line.sub(/\r\n/, "\n") if line @eof_p = line.nil? @lineno += 1 line end |
#gets_if(re) ⇒ Object
816 817 818 819 820 821 822 823 |
# File 'lib/vendor/hikidoc.rb', line 816 def gets_if(re) line = gets() if not line or not (re =~ line) ungets line return nil end line end |
#gets_unless(re) ⇒ Object
825 826 827 828 829 830 831 832 |
# File 'lib/vendor/hikidoc.rb', line 825 def gets_unless(re) line = gets() if not line or re =~ line ungets line return nil end line end |
#inspect ⇒ Object
762 763 764 |
# File 'lib/vendor/hikidoc.rb', line 762 def inspect "\#<#{self.class} file=#{@input.inspect} line=#{lineno()}>" end |
#lineno ⇒ Object
770 771 772 |
# File 'lib/vendor/hikidoc.rb', line 770 def lineno @lineno end |
#next? ⇒ Boolean
800 801 802 |
# File 'lib/vendor/hikidoc.rb', line 800 def next? peek() ? true : false end |
#peek ⇒ Object
794 795 796 797 798 |
# File 'lib/vendor/hikidoc.rb', line 794 def peek line = gets() ungets line if line line end |
#skip_blank_lines ⇒ Object
804 805 806 807 808 809 810 811 812 813 814 |
# File 'lib/vendor/hikidoc.rb', line 804 def skip_blank_lines n = 0 while line = gets() unless line.strip.empty? ungets line return n end n += 1 end n end |
#ungets(line) ⇒ Object
787 788 789 790 791 792 |
# File 'lib/vendor/hikidoc.rb', line 787 def ungets(line) return unless line @lineno -= 1 @buf.push line line end |
#until_match(re) ⇒ Object
861 862 863 864 865 866 867 868 869 870 |
# File 'lib/vendor/hikidoc.rb', line 861 def until_match(re) while line = gets() if re =~ line ungets line return end yield line end nil end |
#until_terminator(re) ⇒ Object
882 883 884 885 886 887 888 |
# File 'lib/vendor/hikidoc.rb', line 882 def until_terminator(re) while line = gets() return if re =~ line # discard terminal line yield line end nil end |
#while_match(re) ⇒ Object
840 841 842 843 844 845 846 847 848 849 |
# File 'lib/vendor/hikidoc.rb', line 840 def while_match(re) while line = gets() unless re =~ line ungets line return end yield line end nil end |