1 package net.sf.saxon.value; 2 3 import net.sf.saxon.functions.NormalizeSpace; 4 import net.sf.saxon.om.FastStringBuffer; 5 6 9 public class Whitespace { 10 11 private Whitespace() {} 12 13 14 19 20 public static final int PRESERVE = 0; 21 public static final int REPLACE = 1; 22 public static final int COLLAPSE = 2; 23 24 30 31 public static CharSequence applyWhitespaceNormalization(int action, CharSequence value) { 32 switch (action) { 33 case PRESERVE: 34 return value; 35 case REPLACE: 36 FastStringBuffer sb = new FastStringBuffer(value.length()); 37 for (int i=0; i<value.length(); i++) { 38 char c = value.charAt(i); 39 switch (c) { 40 case '\n': 41 case '\r': 42 case '\t': 43 sb.append(' '); 44 default: 45 sb.append(c); 46 } 47 } 48 return sb; 49 case COLLAPSE: 50 return NormalizeSpace.normalize(value.toString()); 51 default: 52 throw new IllegalArgumentException ("Unknown whitespace facet value"); 53 } 54 } 55 56 63 64 public static final boolean isWhite(CharSequence content) { 65 int len = content.length(); 66 for (int i=0; i<len;) { 67 char c = content.charAt(i++); 70 if (c > 32 || !C0WHITE[c]) { 71 return false; 72 } 73 } 74 return true; 75 } 76 77 private static boolean[] C0WHITE = { 78 false, false, false, false, false, false, false, false, false, true, true, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true }; 84 } 85 101 | Popular Tags |