File: LoadableInt.java

package info (click to toggle)
pdftk-java 3.3.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,992 kB
  • sloc: java: 48,283; xml: 202; sh: 55; perl: 19; makefile: 10
file content (71 lines) | stat: -rw-r--r-- 2,094 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 *   This file is part of the pdftk port to java
 *
 *   Copyright (c) Marc Vinyals 2017-2018
 *
 *   The program is a java port of PDFtk, the PDF Toolkit
 *   Copyright (c) 2003-2013 Steward and Lee, LLC
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   The program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.gitlab.pdftk_java;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

class LoadableInt {
  int ii = -1;

  static int BufferInt(String buff, int buff_ii) {
    // while( buff[buff_ii] && isspace(buff[buff_ii]) ) { ++buff_ii; }
    Pattern p = Pattern.compile("\\s?(\\d+).*"); // one or no spaces before data
    Matcher m = p.matcher(buff.substring(buff_ii));
    if (m.matches()) {
      return Integer.parseInt(m.group(1));
    } else {
      return 0;
    }
  }

  boolean LoadInt(String buff, String label) {
    int label_len = label.length();
    if (buff.startsWith(label)) {
      if (ii < 0) { // uninitialized ints are -1
        ii = BufferInt(buff, label_len);
      } else { // warning
        System.err.println(
            "pdftk Warning: "
                + label
                + " ("
                + ii
                + ") not empty when reading new "
                + label
                + " ("
                + BufferInt(buff, label_len)
                + ") -- skipping newer item");
      }
      return true;
    }
    return false;
  }

  LoadableInt(int ii) {
    this.ii = ii;
  }

  public String toString() {
    return Integer.toString(ii);
  }
}