Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
ARTEMIS-565 Replace json.org with javax.json
Javax.json is a newer JSR, but has an ASF compliant version, is pretty close to the original JSON.org API and will support a standard annotation based JSON-B solution at some point soon. Updated integration tests and removed JSON.org from license.
- Loading branch information
1 parent
e664780
commit d0ecf0f3a51ec82dd33b596ea948aa2994716b1b
Showing
50 changed files
with
1,039 additions
and
3,706 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.activemq.artemis.utils; | ||
|
||
public abstract class StringEscapeUtils { | ||
/** | ||
* Adapted from commons lang StringEscapeUtils, escapes a string | ||
* | ||
* @param str | ||
* @return an escaped version of the input string. | ||
*/ | ||
public static String escapeString(String str) { | ||
if (str == null) { | ||
return str; | ||
} | ||
int sz = str.length(); | ||
StringBuilder stringBuilder = new StringBuilder(str.length()); | ||
for (int i = 0; i < sz; i++) { | ||
char ch = str.charAt(i); | ||
|
||
// handle unicode | ||
if (ch > 0xfff) { | ||
stringBuilder.append("\\u").append(hex(ch)); | ||
} | ||
else if (ch > 0xff) { | ||
stringBuilder.append("\\u0").append(hex(ch)); | ||
} | ||
else if (ch > 0x7f) { | ||
stringBuilder.append("\\u00").append(hex(ch)); | ||
} | ||
else if (ch < 32) { | ||
switch (ch) { | ||
case '\b': | ||
stringBuilder.append('\\').append('b'); | ||
break; | ||
case '\n': | ||
stringBuilder.append('\\').append('n'); | ||
break; | ||
case '\t': | ||
stringBuilder.append('\\').append('t'); | ||
break; | ||
case '\f': | ||
stringBuilder.append('\\').append('f'); | ||
break; | ||
case '\r': | ||
stringBuilder.append('\\').append('r'); | ||
break; | ||
default : | ||
if (ch > 0xf) { | ||
stringBuilder.append("\\u00").append(hex(ch)); | ||
} | ||
else { | ||
stringBuilder.append("\\u000").append(hex(ch)); | ||
} | ||
break; | ||
} | ||
} | ||
else { | ||
switch (ch) { | ||
case '\'': | ||
stringBuilder.append('\\').append('\''); | ||
break; | ||
case '"': | ||
stringBuilder.append('\\').append('"'); | ||
break; | ||
case '\\': | ||
stringBuilder.append('\\').append('\\'); | ||
break; | ||
case '/': | ||
stringBuilder.append('\\').append('/'); | ||
break; | ||
default : | ||
stringBuilder.append(ch); | ||
break; | ||
} | ||
} | ||
} | ||
return stringBuilder.toString(); | ||
} | ||
|
||
/** | ||
* <p>Returns an upper case hexadecimal <code>String</code> for the given | ||
* character.</p> | ||
* | ||
* @param ch The character to convert. | ||
* @return An upper case hexadecimal <code>String</code> | ||
*/ | ||
private static String hex(char ch) { | ||
return Integer.toHexString(ch).toUpperCase(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.