1 18 package org.apache.batik.gvt.font; 19 20 21 29 public class UnicodeRange { 30 31 private int firstUnicodeValue; 32 private int lastUnicodeValue; 33 34 37 public UnicodeRange(String unicodeRange) { 38 39 if (unicodeRange.startsWith("U+") && unicodeRange.length() > 2) { 40 unicodeRange = unicodeRange.substring(2); 42 int dashIndex = unicodeRange.indexOf('-'); 43 String firstValue; 44 String lastValue; 45 46 if (dashIndex != -1) { firstValue = unicodeRange.substring(0, dashIndex); 48 lastValue = unicodeRange.substring(dashIndex+1); 49 50 } else { 51 firstValue = unicodeRange; 52 lastValue = unicodeRange; 53 if (unicodeRange.indexOf('?') != -1) { 54 firstValue = firstValue.replace('?', '0'); 55 lastValue = lastValue.replace('?', 'F'); 56 } 57 } 58 try { 59 firstUnicodeValue = Integer.parseInt(firstValue, 16); 60 lastUnicodeValue = Integer.parseInt(lastValue, 16); 61 } catch (NumberFormatException e) { 62 firstUnicodeValue = -1; 63 lastUnicodeValue = -1; 64 } 65 } else { 66 firstUnicodeValue = -1; 68 lastUnicodeValue = -1; 69 } 70 } 71 72 75 public boolean contains(String unicode) { 76 if (unicode.length() == 1) { 77 int unicodeVal = unicode.charAt(0); 78 return contains(unicodeVal); 79 } 80 return false; 81 } 82 83 public boolean contains(int unicodeVal) { 84 return ((unicodeVal >= firstUnicodeValue) && 85 (unicodeVal <= lastUnicodeValue)); 86 } 87 88 } 89 | Popular Tags |