1 | /* Generated by: ParserGeneratorCC: Do not edit this line. StringProvider.java Version 1.1 */ |
---|---|
2 | /* ParserGeneratorCCOptions:KEEP_LINE_COLUMN=true */ |
3 | /* |
4 | * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. |
5 | * Copyright (C) 2011, 2013-2020 The JavaParser Team. |
6 | * |
7 | * This file is part of JavaParser. |
8 | * |
9 | * JavaParser can be used either under the terms of |
10 | * a) the GNU Lesser General Public License as published by |
11 | * the Free Software Foundation, either version 3 of the License, or |
12 | * (at your option) any later version. |
13 | * b) the terms of the Apache License |
14 | * |
15 | * You should have received a copy of both licenses in LICENCE.LGPL and |
16 | * LICENCE.APACHE. Please refer to those files for details. |
17 | * |
18 | * JavaParser is distributed in the hope that it will be useful, |
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 | * GNU Lesser General Public License for more details. |
22 | */ |
23 | package com.github.javaparser; |
24 | |
25 | |
26 | import java.io.IOException; |
27 | |
28 | public class StringProvider implements Provider |
29 | { |
30 | private String m_sStr; |
31 | private int m_nPos = 0; |
32 | private final int m_nLen; |
33 | |
34 | public StringProvider(final String sStr) |
35 | { |
36 | m_sStr = sStr; |
37 | m_nLen = sStr.length(); |
38 | } |
39 | |
40 | public int read (final char[] aDest, final int nOfs, final int nLen) throws IOException |
41 | { |
42 | final int nLeft = m_nLen - m_nPos; |
43 | if (nLeft <= 0) |
44 | return -1; |
45 | |
46 | int nCharsRead = aDest.length - nOfs; |
47 | if (nLen < nCharsRead) |
48 | nCharsRead = nLen; |
49 | if (nLeft < nCharsRead) |
50 | nCharsRead = nLeft; |
51 | |
52 | m_sStr.getChars(m_nPos, m_nPos + nCharsRead, aDest, nOfs); |
53 | m_nPos += nCharsRead; |
54 | |
55 | return nCharsRead; |
56 | } |
57 | |
58 | public void close() |
59 | { |
60 | m_sStr = null; |
61 | } |
62 | } |
63 | /* ParserGeneratorCC - OriginalChecksum=d08f934ee2183c4d42cb2b70cc985549 (do not edit this line) */ |
64 |
Members