1 19 20 25 26 27 28 29 package soot.util.dot; 30 import soot.*; 31 32 import java.util.*; 33 import java.io.*; 34 35 public class DotGraphUtility { 36 37 38 public static String replaceQuotes(String original){ 39 byte[] ord = original.getBytes(); 40 int quotes = 0; 41 for (int i=0, n=ord.length; i<n; i++) { 42 if (ord[i] == '\"') quotes++; 43 } 44 45 if (quotes == 0) return original; 46 47 byte[] newsrc = new byte[ord.length+quotes]; 48 for (int i=0, j=0, n=ord.length; i<n; i++, j++){ 49 if (ord[i] == '\"') { 50 newsrc[j++] = (byte) '\\'; 51 } 52 newsrc[j] = ord[i]; 53 } 54 55 59 60 return new String (newsrc); 61 } 62 63 64 public static String replaceReturns(String original){ 65 byte[] ord = original.getBytes(); 66 int quotes = 0; 67 for (int i=0, n=ord.length; i<n; i++) { 68 if (ord[i] == '\n') quotes++; 69 } 70 71 if (quotes == 0) return original; 72 73 byte[] newsrc = new byte[ord.length+quotes]; 74 for (int i=0, j=0, n=ord.length; i<n; i++, j++){ 75 if (ord[i] == '\n') { 76 newsrc[j++] = (byte) '\\'; 77 newsrc[j] = (byte) 'n'; 78 } else { 79 newsrc[j] = ord[i]; 80 } 81 } 82 83 87 88 return new String (newsrc); 89 } 90 91 public static void renderLine(OutputStream out, 92 String content, 93 int indent) throws IOException { 94 for (int i=0; i<indent; i++) { 95 out.write(' '); 96 } 97 98 content = content + "\n"; 99 100 out.write(content.getBytes()); 101 } 102 } 103 | Popular Tags |