286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 1999-2004 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A/*
286N/A * $Id: XMLCharacterRecognizer.java,v 1.2.4.1 2005/09/15 08:16:01 suresh_emailid Exp $
286N/A */
286N/Apackage com.sun.org.apache.xml.internal.utils;
286N/A
286N/A/**
286N/A * Class used to verify whether the specified <var>ch</var>
286N/A * conforms to the XML 1.0 definition of whitespace.
286N/A * @xsl.usage internal
286N/A */
286N/Apublic class XMLCharacterRecognizer
286N/A{
286N/A
286N/A /**
286N/A * Returns whether the specified <var>ch</var> conforms to the XML 1.0 definition
286N/A * of whitespace. Refer to <A href="http://www.w3.org/TR/1998/REC-xml-19980210#NT-S">
286N/A * the definition of <CODE>S</CODE></A> for details.
286N/A * @param ch Character to check as XML whitespace.
286N/A * @return =true if <var>ch</var> is XML whitespace; otherwise =false.
286N/A */
286N/A public static boolean isWhiteSpace(char ch)
286N/A {
286N/A return (ch == 0x20) || (ch == 0x09) || (ch == 0xD) || (ch == 0xA);
286N/A }
286N/A
286N/A /**
286N/A * Tell if the string is whitespace.
286N/A *
286N/A * @param ch Character array to check as XML whitespace.
286N/A * @param start Start index of characters in the array
286N/A * @param length Number of characters in the array
286N/A * @return True if the characters in the array are
286N/A * XML whitespace; otherwise, false.
286N/A */
286N/A public static boolean isWhiteSpace(char ch[], int start, int length)
286N/A {
286N/A
286N/A int end = start + length;
286N/A
286N/A for (int s = start; s < end; s++)
286N/A {
286N/A if (!isWhiteSpace(ch[s]))
286N/A return false;
286N/A }
286N/A
286N/A return true;
286N/A }
286N/A
286N/A /**
286N/A * Tell if the string is whitespace.
286N/A *
286N/A * @param buf StringBuffer to check as XML whitespace.
286N/A * @return True if characters in buffer are XML whitespace, false otherwise
286N/A */
286N/A public static boolean isWhiteSpace(StringBuffer buf)
286N/A {
286N/A
286N/A int n = buf.length();
286N/A
286N/A for (int i = 0; i < n; i++)
286N/A {
286N/A if (!isWhiteSpace(buf.charAt(i)))
286N/A return false;
286N/A }
286N/A
286N/A return true;
286N/A }
286N/A
286N/A /**
286N/A * Tell if the string is whitespace.
286N/A *
286N/A * @param s String to check as XML whitespace.
286N/A * @return True if characters in buffer are XML whitespace, false otherwise
286N/A */
286N/A public static boolean isWhiteSpace(String s)
286N/A {
286N/A
286N/A if(null != s)
286N/A {
286N/A int n = s.length();
286N/A
286N/A for (int i = 0; i < n; i++)
286N/A {
286N/A if (!isWhiteSpace(s.charAt(i)))
286N/A return false;
286N/A }
286N/A }
286N/A
286N/A return true;
286N/A }
286N/A
286N/A}