NewStringSourceWithLimit creates a new Source from the given contents and description while enforcing a maximum code point count when needed.
(contents string, description string, limit int)
| 94 | // NewStringSourceWithLimit creates a new Source from the given contents and |
| 95 | // description while enforcing a maximum code point count when needed. |
| 96 | func NewStringSourceWithLimit(contents string, description string, limit int) (Source, error) { |
| 97 | if limit < 0 || len(contents) <= limit { |
| 98 | return NewStringSource(contents, description), nil |
| 99 | } |
| 100 | buf, offs, err := runes.NewBufferAndLineOffsetsWithLimit(contents, limit) |
| 101 | if err != nil { |
| 102 | return nil, err |
| 103 | } |
| 104 | return &sourceImpl{ |
| 105 | Buffer: buf, |
| 106 | description: description, |
| 107 | lineOffsets: offs, |
| 108 | }, nil |
| 109 | } |
| 110 | |
| 111 | // NewInfoSource creates a new Source from a SourceInfo. |
| 112 | func NewInfoSource(info *exprpb.SourceInfo) Source { |
no test coverage detected