Changeset 6896


Ignore:
Timestamp:
09/07/10 13:51:25 (9 years ago)
Author:
curtis
Message:

More efficient XML sanitation algorithm.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/common/src/loci/common/xml/XMLTools.java

    r6888 r6896  
    149149  /** Remove invalid characters from an XML string. */ 
    150150  public static String sanitizeXML(String s) { 
     151    final char[] c = s.toCharArray(); 
    151152    for (int i=0; i<s.length(); i++) { 
    152       char c = s.charAt(i); 
    153       if (Character.isISOControl(c) || !Character.isDefined(c) || c > '~') { 
    154         s = s.replace(c, ' '); 
    155       } 
    156     } 
    157     return s.replaceAll("&#", ""); 
     153      if (Character.isISOControl(c[i]) || 
     154        !Character.isDefined(c[i]) || c[i] > '~') 
     155      { 
     156        c[i] = ' '; 
     157      } 
     158      // eliminate invalid &# sequences 
     159      if (i > 0 && c[i - 1] == '&' && c[i] == '#') c[i - 1] = ' '; 
     160    } 
     161    return new String(c); 
    158162  } 
    159163 
Note: See TracChangeset for help on using the changeset viewer.