1 17 18 19 20 package org.apache.fop.util; 21 22 26 public class CharUtilities { 27 28 33 public static final char CODE_EOT = 0; 34 35 38 public static final int UCWHITESPACE = 0; 39 42 public static final int LINEFEED = 1; 43 46 public static final int EOT = 2; 47 50 public static final int NONWHITESPACE = 3; 51 54 public static final int XMLWHITESPACE = 4; 55 56 57 58 public static final char SPACE = '\u0020'; 59 60 public static final char NBSPACE = '\u00A0'; 61 62 public static final char ZERO_WIDTH_SPACE = '\u200B'; 63 64 public static final char ZERO_WIDTH_NOBREAK_SPACE = '\uFEFF'; 65 66 public static final char SOFT_HYPHEN = '\u00AD'; 67 68 69 72 protected CharUtilities() { 73 throw new UnsupportedOperationException (); 74 } 75 76 82 public static int classOf(char c) { 83 if (c == CODE_EOT) { return EOT; } 84 if (c == '\n') { return LINEFEED; } 85 if (c == ' ' || c == '\r' || c == '\t') { return XMLWHITESPACE; } 86 if (isAnySpace(c)) { return UCWHITESPACE; } 87 return NONWHITESPACE; 88 } 89 90 91 98 public static boolean isBreakableSpace(char c) { 99 return (c == SPACE || isFixedWidthSpace(c)); 100 } 101 102 107 public static boolean isFixedWidthSpace(char c) { 108 return (c >= '\u2000' && c <= '\u200B') || c == '\u3000'; 109 } 123 124 130 public static boolean isNonBreakableSpace(char c) { 131 return 132 (c == NBSPACE || c == '\u202F' || c == '\u3000' || c == ZERO_WIDTH_NOBREAK_SPACE); } 137 138 144 public static boolean isAdjustableSpace(char c) { 145 return 147 (c == '\u0020' || c == NBSPACE); } 150 151 156 public static boolean isAnySpace(char c) { 157 boolean ret = (isBreakableSpace(c) || isNonBreakableSpace(c)); 158 return ret; 159 } 160 161 166 public static boolean isAlphabetic(char ch) { 167 int generalCategory = Character.getType(ch); 170 switch (generalCategory) { 171 case Character.UPPERCASE_LETTER: case Character.LOWERCASE_LETTER: case Character.TITLECASE_LETTER: case Character.MODIFIER_LETTER: case Character.OTHER_LETTER: case Character.LETTER_NUMBER: return true; 178 default: 179 return false; 182 } 183 } 184 185 } 186 187 | Popular Tags |