...

Source file src/github.com/chai2010/gettext-go/po/line_reader.go

Documentation: github.com/chai2010/gettext-go/po

     1  // Copyright 2013 ChaiShushan <chaishushan{AT}gmail.com>. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package po
     6  
     7  import (
     8  	"io"
     9  	"strings"
    10  )
    11  
    12  type lineReader struct {
    13  	lines []string
    14  	pos   int
    15  }
    16  
    17  func newLineReader(data string) *lineReader {
    18  	data = strings.Replace(data, "\r", "", -1)
    19  	lines := strings.Split(data, "\n")
    20  	return &lineReader{lines: lines}
    21  }
    22  
    23  func (r *lineReader) skipBlankLine() error {
    24  	for ; r.pos < len(r.lines); r.pos++ {
    25  		if strings.TrimSpace(r.lines[r.pos]) != "" {
    26  			break
    27  		}
    28  	}
    29  	if r.pos >= len(r.lines) {
    30  		return io.EOF
    31  	}
    32  	return nil
    33  }
    34  
    35  func (r *lineReader) currentPos() int {
    36  	return r.pos
    37  }
    38  
    39  func (r *lineReader) currentLine() (s string, pos int, err error) {
    40  	if r.pos >= len(r.lines) {
    41  		err = io.EOF
    42  		return
    43  	}
    44  	s, pos = r.lines[r.pos], r.pos
    45  	return
    46  }
    47  
    48  func (r *lineReader) readLine() (s string, pos int, err error) {
    49  	if r.pos >= len(r.lines) {
    50  		err = io.EOF
    51  		return
    52  	}
    53  	s, pos = r.lines[r.pos], r.pos
    54  	r.pos++
    55  	return
    56  }
    57  
    58  func (r *lineReader) unreadLine() {
    59  	if r.pos >= 0 {
    60  		r.pos--
    61  	}
    62  }
    63  

View as plain text