KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > util > dot > DotGraphUtility


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2002 Sable Research Group
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26
27 /* @author Feng Qian */
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   /* replace any " to \" in the string */
38   public static String JavaDoc replaceQuotes(String JavaDoc 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     /*
56     G.v().out.println("before "+original);
57     G.v().out.println("after "+(new String(newsrc)));
58     */

59
60     return new String JavaDoc(newsrc);
61   }
62
63   /* replace any return by to "\n" */
64   public static String JavaDoc replaceReturns(String JavaDoc 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     /*
84     G.v().out.println("before "+original);
85     G.v().out.println("after "+(new String(newsrc)));
86     */

87
88     return new String JavaDoc(newsrc);
89   }
90
91   public static void renderLine(OutputStream out,
92               String JavaDoc 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