summaryrefslogtreecommitdiffstats
path: root/appc-config
diff options
context:
space:
mode:
Diffstat (limited to 'appc-config')
-rw-r--r--appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/EscapeUtils.java59
-rw-r--r--appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestDataTool.java10
2 files changed, 29 insertions, 40 deletions
diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/EscapeUtils.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/EscapeUtils.java
index bd8b2f56b..177716187 100644
--- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/EscapeUtils.java
+++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/EscapeUtils.java
@@ -36,8 +36,8 @@ public class EscapeUtils {
if (str == null) {
return null;
}
- String searchList[] = new String[] {"'", "\\"};
- String replacementList[] = new String[] {"''", "\\\\"};
+ String[] searchList = new String[]{"'", "\\"};
+ String[] replacementList = new String[]{"''", "\\\\"};
return StringUtils.replaceEach(str, searchList, replacementList);
}
@@ -46,33 +46,28 @@ public class EscapeUtils {
if (str == null) {
return null;
}
- /*
- * String searchList[] = new String[]{"''", "\\\\"}; String replacementList[] = new
- * String[]{ "'", "\\"};
- */
- String searchList[] = new String[] {"''"};
- String replacementList[] = new String[] {"'"};
+ String[] searchList = new String[]{"''"};
+ String[] replacementList = new String[]{"'"};
return StringUtils.replaceEach(str, searchList, replacementList);
}
// For Generic Purpose
- public static String escapeSQL(String s) {
+ public static String escapeString(String s) {
if (s == null) {
return null;
}
-
int length = s.length();
int newLength = length;
- for (int i = 0; i < length; i++) {
- char c = s.charAt(i);
- switch (c) {
+ for (char ch : s.toCharArray()) {
+ switch (ch) {
case '\\':
case '\"':
case '\'':
- case '\0': {
+ case '\0':
newLength += 1;
- }
+ break;
+ default:
break;
}
}
@@ -80,31 +75,25 @@ public class EscapeUtils {
// nothing to escape in the string
return s;
}
- StringBuffer sb = new StringBuffer(newLength);
- for (int i = 0; i < length; i++) {
- char c = s.charAt(i);
- switch (c) {
- case '\\': {
- sb.append("\\\\");
- }
+ StringBuilder builder = new StringBuilder(newLength);
+ for (char ch : s.toCharArray()) {
+ switch (ch) {
+ case '\\':
+ builder.append("\\\\");
break;
- case '\"': {
- sb.append("\\\"");
- }
+ case '\"':
+ builder.append("\\\"");
break;
- case '\'': {
- sb.append("\\\'");
- }
+ case '\'':
+ builder.append("\\\'");
break;
- case '\0': {
- sb.append("\\0");
- }
+ case '\0':
+ builder.append("\\0");
break;
- default: {
- sb.append(c);
- }
+ default:
+ builder.append(ch);
}
}
- return sb.toString();
+ return builder.toString();
}
}
diff --git a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestDataTool.java b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestDataTool.java
index 6e1d525c2..2a416f7b2 100644
--- a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestDataTool.java
+++ b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestDataTool.java
@@ -85,12 +85,12 @@ public class TestDataTool {
String st = "test\"test";
String str = "test\'" + "test";
String strng = "test\0";
- EscapeUtils.escapeSQL(s);
+ EscapeUtils.escapeString(s);
EscapeUtils.escapeSql(s);
- EscapeUtils.escapeSQL(st);
- EscapeUtils.escapeSQL(str);
- EscapeUtils.escapeSQL(strng);
- EscapeUtils.escapeSQL(null);
+ EscapeUtils.escapeString(st);
+ EscapeUtils.escapeString(str);
+ EscapeUtils.escapeString(strng);
+ EscapeUtils.escapeString(null);
}
// @Test(expected = Exception.class)