| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.kuali.student.contract.writer; |
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
@author |
| 21 |
|
|
|
|
|
| 0% |
Uncovered Elements: 40 (40) |
Complexity: 9 |
Complexity Density: 0.29 |
|
| 22 |
|
public class StringQuoter { |
| 23 |
|
|
|
|
|
| 0% |
Uncovered Elements: 39 (39) |
Complexity: 9 |
Complexity Density: 0.29 |
|
| 24 |
0
|
public static String quote(String value) {... |
| 25 |
0
|
if (value == null) { |
| 26 |
0
|
return null; |
| 27 |
|
} |
| 28 |
0
|
StringBuffer buf = new StringBuffer(value.length() + 3); |
| 29 |
0
|
buf.append('"'); |
| 30 |
0
|
boolean lastCharWasEscape = false; |
| 31 |
0
|
for (int i = 0; i < value.length(); i++) { |
| 32 |
0
|
char c = value.charAt(i); |
| 33 |
0
|
switch (c) { |
| 34 |
0
|
case '"': |
| 35 |
0
|
if (!lastCharWasEscape) { |
| 36 |
0
|
buf.append('\\'); |
| 37 |
|
} |
| 38 |
0
|
lastCharWasEscape = false; |
| 39 |
0
|
break; |
| 40 |
0
|
case '\\': |
| 41 |
0
|
if (!lastCharWasEscape) { |
| 42 |
0
|
buf.append('\\'); |
| 43 |
|
} |
| 44 |
0
|
lastCharWasEscape = true; |
| 45 |
0
|
break; |
| 46 |
0
|
case '\n': |
| 47 |
0
|
case '\r': |
| 48 |
0
|
buf.append('"'); |
| 49 |
0
|
buf.append("\n"); |
| 50 |
0
|
buf.append("\t + "); |
| 51 |
0
|
buf.append('"'); |
| 52 |
0
|
lastCharWasEscape = false; |
| 53 |
0
|
continue; |
| 54 |
0
|
default: |
| 55 |
0
|
lastCharWasEscape = false; |
| 56 |
|
} |
| 57 |
0
|
buf.append(c); |
| 58 |
|
} |
| 59 |
0
|
buf.append('"'); |
| 60 |
0
|
return buf.toString(); |
| 61 |
|
} |
| 62 |
|
} |