Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Minor garbage reductions
  • Loading branch information
krosenvold committed Aug 6, 2013
1 parent 8b79a66 commit 8779fbd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
Expand Up @@ -206,30 +206,49 @@ private void writeText( String text, boolean escapeXml )
write( StringUtils.unifyLineSeparators( text, lineSeparator ) );
}

private static final Pattern amp = Pattern.compile( "&" );
private static final Pattern lt = Pattern.compile( "<" );
private static final Pattern gt = Pattern.compile( ">" );
private static final Pattern dqoute = Pattern.compile( "\"" );
private static final Pattern sqoute = Pattern.compile( "\'" );

private static String escapeXml( String text )
{
text = text.replaceAll( "&", "&amp;" );

text = text.replaceAll( "<", "&lt;" );

text = text.replaceAll( ">", "&gt;" );

text = text.replaceAll( "\"", "&quot;" );

text = text.replaceAll( "\'", "&apos;" );
if (text.indexOf('&') >= 0){
text = amp.matcher( text ).replaceAll( "&amp;" );
}
if (text.indexOf('<') >= 0){
text = lt.matcher( text ).replaceAll( "&lt;" );
}
if (text.indexOf('>') >= 0){
text = gt.matcher( text ).replaceAll( "&gt;" );
}
if (text.indexOf('"') >= 0){
text = dqoute.matcher( text ).replaceAll( "\"" );
}
if (text.indexOf('\'') >= 0){
text = sqoute.matcher( text ).replaceAll( "\'" );
}

return text;
}

private static final Pattern crlf = Pattern.compile( "\r\n" );
private static final Pattern lowers = Pattern.compile( "([\000-\037])" );


private static String escapeXmlAttribute( String text )
{
text = escapeXml( text );

// Windows
text = text.replaceAll( "\r\n", "&#10;" );
Matcher matcher = crlf.matcher( text );
if (matcher.matches())
{
text = matcher.replaceAll( "&#10;" );
}

Pattern pattern = Pattern.compile( "([\000-\037])" );
Matcher m = pattern.matcher( text );
Matcher m = lowers.matcher( text );
StringBuffer b = new StringBuffer();
while ( m.find() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/codehaus/plexus/util/xml/XmlReader.java
Expand Up @@ -732,7 +732,7 @@ private static String getXmlProlog( BufferedInputStream is, String guessedEnc )
{
is.reset();
BufferedReader bReader = new BufferedReader( new StringReader( xmlProlog.substring( 0, firstGT + 1 ) ) );
StringBuffer prolog = new StringBuffer();
StringBuilder prolog = new StringBuilder();
String line = bReader.readLine();
while ( line != null )
{
Expand Down

0 comments on commit 8779fbd

Please sign in to comment.