<commit_before>/*
 * The Apache Software License, Version 1.1
 *
 *
 * Copyright (c) 1999 The Apache Software Foundation.  All rights 
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer. 
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:  
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xerces" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written 
 *    permission, please contact <EMAIL>.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation and was
 * originally based on software copyright (c) 1999, International
 * Business Machines, Inc., http://www.apache.org.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

package org.apache.xerces.utils;

/** 
 * A class representing properties of characters according to various
 * W3C recommendations
 *
 * XMLCharacterProperties provides convenience methods for commonly used
 * character tests.
 *
 * For performance reasons, the tables used by the convenience methods are
 * also public, and are directly accessed by performance critical routines.
 *
 */

public final class XMLCharacterProperties {
    /*
     * [26] VersionNum ::= ([a-zA-Z0-9_.:] | '-')+
     *
     * Note: This is the same as the ascii portion of the
     *       NameChar definition.
     */
    /** 
     * Check to see if a string is a valid version string according to
     * [26] in the XML 1.0 Recommendation
     *
     * @param version string to check
     * @return true if version is a valid version string
     */
    public static boolean validVersionNum(String version) {
        if (version.length() == 0)
            return false;
        for (int i = 0; i < version.length(); i++) {
            char ch = version.charAt(i);
            if (ch > 'z' || fgAsciiNameChar[ch] == 0)
                return false;
        }
        return true;
    }
    /*
     * [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
     */
    /**
     * Check to see if a string is a valid encoding name according to [81]
     * in the XML 1.0 Recommendation
     * 
     * @param encoding string to check
     * @return true if encoding is a valid encoding name
     */
    public static boolean validEncName(String encoding) {
        if (encoding.length() == 0)
            return false;
        char ch = encoding.charAt(0);
        if (ch > 'z' || fgAsciiAlphaChar[ch] == 0)
            return false;
        for (int i = 1; i < encoding.length(); i++) {
            ch = encoding.charAt(i);
            if (ch > 'z' || fgAsciiEncNameChar[ch] == 0)
                return false;
        }
        return true;
    }
    /*
     * [13] PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
     */
    /** 
     * Check to see if a string is a valid public identifier according to [13]
     * in the XML 1.0 Recommendation
     *
     * @param publicId string to check
     * @return true if publicId is a valid public identifier
     */
    public static int validPublicId(String publicId) {
        if (publicId.length() == 0)
            return -1;
        for (int i = 0; i < publicId.length(); i++) {
            char ch = publicId.charAt(i);
            if (ch > 'z' || fgAsciiPubidChar[ch] == 0)
                return i;
        }
        return -1;
    }
    /*
     * [5] Name ::= (Letter | '_' | ':') (NameChar)*
     */
    /**
     * Check to see if a string is a valid Name according to [5]
     * in the XML 1.0 Recommendation
     *
     * @param name string to check
     * @return true if name is a valid Name
     */
    public static boolean validName(String name) {
        if (name.length() == 0)
            return false;
        char ch = name.charAt(0);
        if (ch > 'z') {
            if ((fgCharFlags[ch] & E_InitialNameCharFlag) == 0)
                return false;
        } else if (fgAsciiInitialNameChar[ch] == 0)
            return false;
        for (int i = 1; i < name.length(); i++) {
            ch = name.charAt(i);
            if (ch > 'z') {
                if ((fgCharFlags[ch] & E_NameCharFlag) == 0)
                    return false;
            } else if (fgAsciiNameChar[ch] == 0)
                return false;
        }
        return true;
    }
    
    /*
     * from the namespace rec
     * [5] NCName ::= (Letter | '_' | ':') (NameNCChar)*
     */
    /**
     * Check to see if a string is a valid NCName according to [5]
     * from the XML Namespaces 1.0 Recommendation
     *
     * @param name string to check
     * @return true if name is a valid NCName
     */
    public static boolean validNCName(String name) {
        if (name.length() == 0)
            return false;
        char ch = name.charAt(0);
        if (ch > 'z') {
            if ((fgCharFlags[ch] & E_InitialNameCharFlag) == 0)
                return false;
        } else if (fgAsciiInitialNCNameChar[ch] == 0)
            return false;
        for (int i = 1; i < name.length(); i++) {
            ch = name.charAt(i);
            if (ch > 'z') {
                if ((fgCharFlags[ch] & E_NameCharFlag) == 0)
                    return false;
            } else if (fgAsciiNCNameChar[ch] == 0)
                return false;
        }
        return true;
    }
    
    
    /*
     * [7] Nmtoken ::= (NameChar)+
     */
    /** 
     * Check to see if a string is a valid Nmtoken according to [7]
     * in the XML 1.0 Recommendation
     *
     * @param nmtoken string to checj
     * @return true if nmtoken is a valid Nmtoken
     */
    public static boolean validNmtoken(String nmtoken) {
        if (nmtoken.length() == 0)
            return false;
        for (int i = 0; i < nmtoken.length(); i++) {
            char ch = nmtoken.charAt(i);
            if (ch > 'z') {
                if ((fgCharFlags[ch] & E_NameCharFlag) == 0)
                    return false;
            } else if (fgAsciiNameChar[ch] == 0) {
                return false;
            }<commit_msg>Removed redundant method invocations to .length() from if condition and for loop termination condition - patch from <NAME>ne<commit_after>/*
 * The Apache Software License, Version 1.1
 *
 *
 * Copyright (c) 1999 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xerces" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact <EMAIL>.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation and was
 * originally based on software copyright (c) 1999, International
 * Business Machines, Inc., http://www.apache.org.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

package org.apache.xerces.utils;

/**
 * A class representing properties of characters according to various
 * W3C recommendations
 *
 * XMLCharacterProperties provides convenience methods for commonly used
 * character tests.
 *
 * For performance reasons, the tables used by the convenience methods are
 * also public, and are directly accessed by performance critical routines.
 *
 */

public final class XMLCharacterProperties {
    /*
     * [26] VersionNum ::= ([a-zA-Z0-9_.:] | '-')+
     *
     * Note: This is the same as the ascii portion of the
     *       NameChar definition.
     */
    /**
     * Check to see if a string is a valid version string according to
     * [26] in the XML 1.0 Recommendation
     *
     * @param version string to check
     * @return true if version is a valid version string
     */
    public static boolean validVersionNum(String version) {
        int len = version.length();
        if (len == 0)
            return false;
        for (int i = 0; i < len; i++) {
            char ch = version.charAt(i);
            if (ch > 'z' || fgAsciiNameChar[ch] == 0)
                return false;
        }
        return true;
    }
    /*
     * [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
     */
    /**
     * Check to see if a string is a valid encoding name according to [81]
     * in the XML 1.0 Recommendation
     *
     * @param encoding string to check
     * @return true if encoding is a valid encoding name
     */
    public static boolean validEncName(String encoding) {
        int len = encoding.length();
        if (len == 0)
            return false;
        char ch = encoding.charAt(0);
        if (ch > 'z' || fgAsciiAlphaChar[ch] == 0)
            return false;
        for (int i = 1; i < len; i++) {
            ch = encoding.charAt(i);
            if (ch > 'z' || fgAsciiEncNameChar[ch] == 0)
                return false;
        }
        return true;
    }
    /*
     * [13] PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
     */
    /**
     * Check to see if a string is a valid public identifier according to [13]
     * in the XML 1.0 Recommendation
     *
     * @param publicId string to check
     * @return true if publicId is a valid public identifier
     */
    public static int validPublicId(String publicId) {
        int len = publicId.length();
        if (len == 0)
            return -1;
        for (int i = 0; i < len; i++) {
            char ch = publicId.charAt(i);
            if (ch > 'z' || fgAsciiPubidChar[ch] == 0)
                return i;
        }
        return -1;
    }
    /*
     * [5] Name ::= (Letter | '_' | ':') (NameChar)*
     */
    /**
     * Check to see if a string is a valid Name according to [5]
     * in the XML 1.0 Recommendation
     *
     * @param name string to check
     * @return true if name is a valid Name
     */
    public static boolean validName(String name) {
        int len = name.length();
        if (len == 0)
            return false;
        char ch = name.charAt(0);
        if (ch > 'z') {
            if ((fgCharFlags[ch] & E_InitialNameCharFlag) == 0)
                return false;
        } else if (fgAsciiInitialNameChar[ch] == 0)
            return false;
        for (int i = 1; i < len; i++) {
            ch = name.charAt(i);
            if (ch > 'z') {
                if ((fgCharFlags[ch] & E_NameCharFlag) == 0)
                    return false;
            } else if (fgAsciiNameChar[ch] == 0)
                return false;
        }
        return true;
    }

    /*
     * from the namespace rec
     * [5] NCName ::= (Letter | '_' | ':') (NameNCChar)*
     */
    /**
     * Check to see if a string is a valid NCName according to [5]
     * from the XML Namespaces 1.0 Recommendation
     *
     * @param name string to check
     * @return true if name is a valid NCName
     */
    public static boolean validNCName(String name) {
        int len = name.length();
        if (len == 0)
            return false;
        char ch = name.charAt(0);
        if (ch > 'z') {
            if ((fgCharFlags[ch] & E_InitialNameCharFlag) == 0)
                return false;
        } else if (fgAsciiInitialNCNameChar[ch] == 0)
            return false;
        for (int i = 1; i < len; i++) {
            ch = name.charAt(i);
            if (ch > 'z') {
                if ((fgCharFlags[ch] & E_NameCharFlag) == 0)
                    return false;
            } else if (fgAsciiNCNameChar[ch] == 0)
                return false;
        }
        return true;
    }


    /*
     * [7] Nmtoken ::= (NameChar)+
     */
    /**
     * Check to see if a string is a valid Nmtoken according to [7]
     * in the XML 1.0 Recommendation
     *
     * @param nmtoken string to checj
     * @return true if nmtoken is a valid Nmtoken
     */
    public static boolean validNmtoken(String nmtoken) {
        int len = nmtoken.length();
        if (len == 0)
            return false;
        for (int i = 0; i < len; i++) {
            char ch = nmtoken.charAt(i);
            if (ch > 'z') {
                if ((fgCharFlags[ch] & E_NameCharFlag) == 0)
                    return false;
            } else if (fgAsciiNameChar[ch] == 0) {
                return false;
            }
{'fraction_non_alphanumeric': 0.10891150939861363, 'fraction_numerical': 0.010616374195965778, 'mean_word_length': 2.1265130808278014, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6268347', 'n_tokens_mistral': 4730, 'n_tokens_neox': 4393, 'n_words': 1756}