~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/chai2010/gettext-go/gettext/po/line_reader.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
}