001 package com.thaiopensource.datatype.xsd; 002 003 import org.relaxng.datatype.ValidationContext; 004 import com.thaiopensource.util.Utf16; 005 006 class TokenDatatype extends DatatypeBase implements Measure { 007 008 TokenDatatype() { } 009 TokenDatatype(int whiteSpace) { 010 super(whiteSpace); 011 } 012 013 public boolean lexicallyAllows(String str) { 014 return true; 015 } 016 017 public boolean alwaysValid() { 018 return true; 019 } 020 021 Object getValue(String str, ValidationContext vc) { 022 return str; 023 } 024 025 Measure getMeasure() { 026 return this; 027 } 028 029 public int getLength(Object obj) { 030 String str = (String)obj; 031 int len = str.length(); 032 int nSurrogatePairs = 0; 033 for (int i = 0; i < len; i++) 034 if (Utf16.isSurrogate1(str.charAt(i))) 035 nSurrogatePairs++; 036 return len - nSurrogatePairs; 037 } 038 }