protected List<Slice> cutSourceContentInSlices(String sourceContent, PrintStream originalOut) { StringBuffer currentEmptyLines = new StringBuffer(); StringBuffer currentBuffer = new StringBuffer(); boolean sliceGotContent = false; String[] lines = sourceContent.split("\n"); int iLine = 0, nLines = lines.length, lastStart = 0; String lastFile = null; // int lastPercent = 0; Pattern fileInLinePattern = Pattern.compile("\"([^\"]+)\""); List<Slice> slices = new ArrayList<Slice>(nLines / 10); for (String line : lines) { /*int percent = (iLine + 1) * 100 / nLines; if (lastPercent != percent) { //originalOut.print("\b\b\b\b\b"); originalOut.println(percent + "%"); lastPercent = percent; }*/ if (line.startsWith("#line")) { lastStart = iLine; lastFile = RegexUtils.findFirst(line, fileInLinePattern, 1); if (sliceGotContent) { // originalOut.println("Split: " + line.substring("#line".length()).trim()); String content = currentBuffer.toString(); slices.add(new Slice(lastFile, lastStart, content)); } currentBuffer.setLength(0); // currentBuffer.append(currentEmptyLines); sliceGotContent = false; } if (!sliceGotContent) { sliceGotContent = line.trim().length() > 0; } currentBuffer.append(line); currentBuffer.append('\n'); currentEmptyLines.append('\n'); // deltaLines++; iLine++; } if (sliceGotContent) { String content = currentBuffer.toString(); slices.add(new Slice(lastFile, lastStart, content)); } return slices; }
private void resolveInclusions(String source, Map<String, URL> ret) throws IOException { Collection<String> includedPaths = RegexUtils.find(source, includePattern, 1); // System.out.println("Included paths = " + includedPaths); for (String includedPath : includedPaths) { if (ret.containsKey(includedPath)) continue; URL url = getIncludedSourceURL(includedPath); if (url == null) { assert log(Level.SEVERE, "Failed to resolve include '" + includedPath + "'"); } else { String s = ReadText.readText(url); ret.put(includedPath, url); resolveInclusions(s, ret); } } }
protected String removeInlineAsm(String source) { // Hack to replace __asm blocks : String replaced = RegexUtils.regexReplace( asmPattern, source, new RegexUtils.Replacer() { public String replace(String[] groups) { int i = -1; StringBuilder b = new StringBuilder(); for (char c : groups[0].toCharArray()) { if (c == '\n') { b.append(c); } } return b.toString(); } }); return replaced; }