-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for UTF-8 characters less 32 or above 126 codes (out of ASCII range) #6
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, just some minor stuff to fix before merging.
Thanks! 👍
@@ -178,7 +177,7 @@ public void save(String dir, String fileName, boolean includeNamespace, String o | |||
*/ | |||
public String toString(String tabs) | |||
{ | |||
StringBuffer out = new StringBuffer(); | |||
StringBuilder out = new StringBuilder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a changed indentation (with one space?). Can be reverted.
/** | ||
* Encodes strings as XML. Check for <, >, ', ", &. | ||
// /** | ||
// * Encodes strings as XML. Check for <, >, ', ", &. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about removing the commented out block? :)
Pattern gtPat = Pattern.compile( ">" ); | ||
Pattern aposPat = Pattern.compile( "\'" ); | ||
Pattern quotPat = Pattern.compile( "\"" ); | ||
static String encode(String originalUnprotectedString) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The broken indentations in this method make it really hard to follow the flow
|
||
String out = new String( in ); | ||
StringBuilder stringBuffer = new StringBuilder(originalUnprotectedString.length()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given that there are both StringBuffer
and StringBuilder
classes in java, I wouldn't call a variable of type StringBuilder
like that. :) It's really misleading.
anyCharactersProtected = true; | ||
} | ||
} | ||
if (anyCharactersProtected == false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anyCharactersProtected
is always true, as far as I can see.
I'd just get rid of this if
block (and the whole anyCharactersProtected
flag altogether) and always return stringBuffer.toString()
as this seems like a really minor optimisation to me (if at all).
but if you want to keep it, then, probably, in the default case of the switch it should be:
default:
stringBuffer.append(ch);
anyCharactersProtected = false;
}
Hi,
I added additional encoding for UTF-8 characters which are out of standard ASCII range.