]> gerrit.simantics Code Review - simantics/platform.git/blob
034682803f1ec04bdcc221551e9f4df49a910830
[simantics/platform.git] /
1 /*******************************************************************************
2  *  Copyright (c) 2010 Association for Decentralized Information Management in
3  *  Industry THTH ry.
4  *  All rights reserved. This program and the accompanying materials
5  *  are made available under the terms of the Eclipse Public License v1.0
6  *  which accompanies this distribution, and is available at
7  *  http://www.eclipse.org/legal/epl-v10.html
8  *
9  *  Contributors:
10  *      VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.spreadsheet.graph.parser;
13
14 public class SheetParserUtils {
15
16         public static String escape(String str) {
17                 StringBuilder b = new StringBuilder();
18                 for(int i = 0;i<str.length();++i) {
19                         char c = str.charAt(i);
20                         switch(c) {
21                         case '\n':
22                                 b.append("\\n");
23                                 break;
24                         case '\r':
25                                 b.append("\\r");
26                                 break;
27                         case '\t':
28                                 b.append("\\t");
29                                 break;
30                         case '\b':
31                                 b.append("\\b");
32                                 break;
33                         case '\f':
34                                 b.append("\\f");
35                                 break;
36                         case '\\':
37                                 b.append("\\\\");
38                                 break;
39                         default:
40                                 b.append(c);
41                         }
42                 }
43                 return b.toString();
44         }
45
46         public static String unescape(String str) {
47                 StringBuilder b = new StringBuilder();
48                 for(int i = 0;i<str.length();++i) {
49                         char c = str.charAt(i);
50                         if(c == '\\') {
51                                 c = str.charAt(++i);
52                                 switch(c) {
53                                 case 'n':
54                                         b.append('\n');
55                                         break;
56                                 case 'r':
57                                         b.append('\r');
58                                         break;
59                                 case 't':
60                                         b.append('\t');
61                                         break;
62                                 case 'b':
63                                         b.append('\b');
64                                         break;
65                                 case 'f':
66                                         b.append('\f');
67                                         break;
68                                 default:
69                                         b.append(c);
70                                 }
71                         }
72                         else
73                                 b.append(c);
74                 }
75                 return b.toString();
76         }
77         
78 }