MCPcopy Create free account
hub / github.com/BaseXdb/basex / packInt

Method packInt

basex-core/src/main/java/org/basex/util/Inline.java:76–93  ·  view source on GitHub ↗

Converts the specified token into a positive integer value. @param token token to be converted @return inlined value, or -1 if value cannot be inlined

(final byte[] token)

Source from the content-addressed store, hash-verified

74 * @return inlined value, or {@code -1} if value cannot be inlined
75 */
76 public static long packInt(final byte[] token) {
77 final int tl = token.length;
78 // skip empty tokens
79 if(tl == 0) return -1;
80 // skip tokens starting with no digit or '0'
81 if(tl > 1) {
82 final byte b = token[0];
83 if(b < '1' || b > '9') return -1;
84 }
85
86 long value = 0;
87 for(final byte b : token) {
88 value = value * 10 + b - '0';
89 // skip conversion if byte is no digit, or if number is too large
90 if(b < '0' || b > '9' || value > Integer.MAX_VALUE) return -1;
91 }
92 return INLINE | value;
93 }
94
95 /**
96 * Converts an inlined value to a token.

Callers 2

updateTextMethod · 0.95
packMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected