List of usage examples for org.eclipse.jgit.util IntList IntList
public IntList()
From source file:de.fau.osr.util.FlatSource.java
License:Open Source License
public static FlatSource flatten(byte[] input) { // file is binary, ignore all contents if (RawText.isBinary(input)) return new FlatSource(new byte[0], new IntList()); IntList realLines = new IntList(); ByteBuffer to = ByteBuffer.allocate(input.length * 2), from = ByteBuffer.wrap(input); boolean atLineStart = true, lastWord = false, lastSpace = false; while (from.hasRemaining()) { if (atLineStart) { realLines.add(to.position()); }//from w w w .j a va2s. c o m byte cur = from.get(); if (cur == '\n') { atLineStart = true; to.put(cur); } else if (cur == ' ' || cur == '\t') { if (!atLineStart && !lastSpace) to.put((byte) '\n'); to.put(cur); lastSpace = true; lastWord = false; atLineStart = false; } else { if (!atLineStart && !lastWord) to.put((byte) '\n'); to.put(cur); lastSpace = false; lastWord = true; atLineStart = false; } } byte[] out = new byte[to.position()]; to.position(0); to.get(out); return new FlatSource(out, realLines);//new FlatSource(new byte[]) }
From source file:org.eclipse.egit.ui.internal.dialogs.SpellcheckableMessageArea.java
License:Open Source License
/** * Calculates wrap offsets for the given line, so that resulting lines are * no longer than <code>maxLineLength</code> if possible. * * @param line//from w w w . ja va2 s .c om * the line to wrap (can contain '\n', but no other line delimiters) * @param maxLineLength * the maximum line length * @return an array of offsets where hard-wraps should be inserted, or * <code>null</code> if the line does not need to be wrapped */ public static int[] calculateWrapOffsets(final String line, final int maxLineLength) { if (line.length() == 0) return null; IntList wrapOffsets = new IntList(); int wordStart = 0; int lineStart = 0; boolean lastWasSpace = true; boolean onlySpaces = true; for (int i = 0; i < line.length(); i++) { char ch = line.charAt(i); if (ch == ' ') { lastWasSpace = true; } else if (ch == '\n') { lineStart = i + 1; wordStart = i + 1; lastWasSpace = true; onlySpaces = true; } else { // a word character if (lastWasSpace) { lastWasSpace = false; if (!onlySpaces) { // don't break line with <spaces><veryLongWord> wordStart = i; } } else { onlySpaces = false; } if (i >= lineStart + maxLineLength) { if (wordStart != lineStart) { // don't break before a single long word wrapOffsets.add(wordStart); lineStart = wordStart; onlySpaces = true; } } } } int size = wrapOffsets.size(); if (size == 0) { return null; } else { int[] result = new int[size]; for (int i = 0; i < size; i++) { result[i] = wrapOffsets.get(i); } return result; } }
From source file:svnserver.repository.git.GitRepository.java
License:GNU General Public License
private void loadRevisionInfo(@NotNull RevCommit commit) throws IOException, SVNException { final ObjectReader reader = repository.newObjectReader(); final CacheRevision cacheRevision = loadCacheRevision(reader, commit, revisions.size()); final int revisionId = revisions.size(); final Map<String, VcsCopyFrom> copyFroms = new HashMap<>(); for (Map.Entry<String, String> entry : cacheRevision.getRenames().entrySet()) { copyFroms.put(entry.getKey(), new VcsCopyFrom(revisionId - 1, entry.getValue())); }/* w w w. j ava 2s. c om*/ final RevCommit oldCommit = revisions.isEmpty() ? null : revisions.get(revisions.size() - 1).getGitNewCommit(); final RevCommit svnCommit = cacheRevision.getGitCommitId() != null ? new RevWalk(reader).parseCommit(cacheRevision.getGitCommitId()) : null; for (Map.Entry<String, CacheChange> entry : cacheRevision.getFileChange().entrySet()) { lastUpdates.compute(entry.getKey(), (key, list) -> { final IntList result = list == null ? new IntList() : list; result.add(revisionId); if (entry.getValue().getNewFile() == null) { result.add(MARK_NO_FILE); } return result; }); } final GitRevision revision = new GitRevision(this, commit.getId(), revisionId, copyFroms, oldCommit, svnCommit, commit.getCommitTime()); if (revision.getId() > 0) { if (revisionByDate.isEmpty() || revisionByDate.lastKey() <= revision.getDate()) { revisionByDate.put(revision.getDate(), revision); } } if (svnCommit != null) { revisionByHash.put(svnCommit.getId(), revision); } revisions.add(revision); }