1/* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5/* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22package com.sun.org.apache.xml.internal.utils; 23 24/** 25 * Class used to verify whether the specified <var>ch</var> 26 * conforms to the XML 1.0 definition of whitespace. 27 * @xsl.usage internal 28 */ 29public class XMLCharacterRecognizer 30{ 31 32 /** 33 * Returns whether the specified <var>ch</var> conforms to the XML 1.0 definition 34 * of whitespace. Refer to <A href="http://www.w3.org/TR/1998/REC-xml-19980210#NT-S"> 35 * the definition of <CODE>S</CODE></A> for details. 36 * @param ch Character to check as XML whitespace. 37 * @return =true if <var>ch</var> is XML whitespace; otherwise =false. 38 */ 39 public static boolean isWhiteSpace(char ch) 40 { 41 return (ch == 0x20) || (ch == 0x09) || (ch == 0xD) || (ch == 0xA); 42 } 43 44 /** 45 * Tell if the string is whitespace. 46 * 47 * @param ch Character array to check as XML whitespace. 48 * @param start Start index of characters in the array 49 * @param length Number of characters in the array 50 * @return True if the characters in the array are 51 * XML whitespace; otherwise, false. 52 */ 53 public static boolean isWhiteSpace(char ch[], int start, int length) 54 { 55 56 int end = start + length; 57 58 for (int s = start; s < end; s++) 59 { 60 if (!isWhiteSpace(ch[s])) 61 return false; 62 } 63 64 return true; 65 } 66 67 /** 68 * Tell if the string is whitespace. 69 * 70 * @param buf StringBuffer to check as XML whitespace. 71 * @return True if characters in buffer are XML whitespace, false otherwise 72 */ 73 public static boolean isWhiteSpace(StringBuffer buf) 74 { 75 76 int n = buf.length(); 77 78 for (int i = 0; i < n; i++) 79 { 80 if (!isWhiteSpace(buf.charAt(i))) 81 return false; 82 } 83 84 return true; 85 } 86 87 /** 88 * Tell if the string is whitespace. 89 * 90 * @param s String to check as XML whitespace. 91 * @return True if characters in buffer are XML whitespace, false otherwise 92 */ 93 public static boolean isWhiteSpace(String s) 94 { 95 96 if(null != s) 97 { 98 int n = s.length(); 99 100 for (int i = 0; i < n; i++) 101 { 102 if (!isWhiteSpace(s.charAt(i))) 103 return false; 104 } 105 } 106 107 return true; 108 } 109 110} 111