<commit_before>/* ====================================================================
   Licensed to the Apache Software Foundation (ASF) Under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for Additional information regarding copyright ownership.
   The ASF licenses this file to You Under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed Under the License is distributed on an "AS Is" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations Under the License.
==================================================================== */



namespace NPOI.SS.Util
{
    using System;
    using System.Text;
    using System.Text.RegularExpressions;
    using NPOI.SS.Formula;
    using NPOI.SS.UserModel;
    using System.Globalization;

    public enum NameType:int
    {
        /// <summary>
        /// Allow accessing the Initial value.
        /// </summary>
        None = 0,
        Cell = 1,
        NamedRange = 2,
        Column = 3,
        Row = 4,
        BadCellOrNamedRange = -1
    }

    /**
     * <p>Common conversion functions between Excel style A1, C27 style
     *  cell references, and POI usermodel style row=0, column=0
     *  style references. Handles sheet-based and sheet-free references
     *  as well, eg "Sheet1!A1" and "$B$72"</p>
     *  
     *  <p>Use <tt>CellReference</tt> when the concept of
     * relative/absolute does apply (such as a cell reference in a formula).
     * Use {@link CellAddress} when you want to refer to the location of a cell in a sheet
     * when the concept of relative/absolute does not apply (such as the anchor location 
     * of a cell comment).
     * <tt>CellReference</tt>s have a concept of "sheet", while <tt>CellAddress</tt>es do not.</p>
     */

    public class CellReference
    {
        /** The character ($) that signifies a row or column value is absolute instead of relative */
        private const char ABSOLUTE_REFERENCE_MARKER = '$';
        /** The character (!) that Separates sheet names from cell references */
        private const char SHEET_NAME_DELIMITER = '!';
        /** The character (') used to quote sheet names when they contain special characters */
        private const char SPECIAL_NAME_DELIMITER = '\'';

        /**
         * Matches a run of one or more letters followed by a run of one or more digits.
         * Both the letter and number groups are optional.
         * The run of letters is group 1 and the run of digits is group 2.
         * Each group may optionally be prefixed with a single '$'.
         */
        //private const string CELL_REF_PATTERN = @"^\$?([A-Za-z]+)\$?([0-9]+)";
        //private static final Pattern CELL_REF_PATTERN = Pattern.compile("(\\$?[A-Z]+)?" + "(\\$?[0-9]+)?", Pattern.CASE_INSENSITIVE);
        private static Regex CELL_REF_PATTERN = new Regex("(\\$?[A-Z]+)?" + "(\\$?[0-9]+)?");

        /**
         * Matches references only where row and column are included.
         * Matches a run of one or more letters followed by a run of one or more digits.
         * If a reference does not match this pattern, it might match COLUMN_REF_PATTERN or ROW_REF_PATTERN
         * References may optionally include a single '$' before each group, but these are excluded from the Matcher.group(int).
         */
        //private static final Pattern STRICTLY_CELL_REF_PATTERN = Pattern.compile("\\$?([A-Z]+)" + "\\$?([0-9]+)", Pattern.CASE_INSENSITIVE);
        private static Regex STRICTLY_CELL_REF_PATTERN = new Regex("\\$?([A-Z]+)" + "\\$?([0-9]+)");
        /**
         * Matches a run of one or more letters.  The run of letters is group 1.  
         * References may optionally include a single '$' before the group, but these are excluded from the Matcher.group(int).
         */
        private static Regex COLUMN_REF_PATTERN = new Regex(@"^\$?([A-Za-z]+)$");
        /**
         * Matches a run of one or more letters.  The run of numbers is group 1.
         * References may optionally include a single '$' before the group, but these are excluded from the Matcher.group(int).
         */
        private static Regex ROW_REF_PATTERN = new Regex(@"^\$?([0-9]+)$");
        /**
         * Named range names must start with a letter or underscore.  Subsequent characters may include
         * digits or dot.  (They can even end in dot).
         */
        //private static final Pattern NAMED_RANGE_NAME_PATTERN = Pattern.compile("[_A-Z][_.A-Z0-9]*", Pattern.CASE_INSENSITIVE);
        private static Regex NAMED_RANGE_NAME_PATTERN = new Regex("^[_A-Za-z][_.A-Za-z0-9]*$");
        //private static string BIFF8_LAST_COLUMN = "IV";
        //private static int BIFF8_LAST_COLUMN_TEXT_LEN = BIFF8_LAST_COLUMN.Length;
        //private static string BIFF8_LAST_ROW = (0x10000).ToString();<commit_msg>Fix bugs of CellReference<commit_after>/* ====================================================================
   Licensed to the Apache Software Foundation (ASF) Under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for Additional information regarding copyright ownership.
   The ASF licenses this file to You Under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed Under the License is distributed on an "AS Is" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations Under the License.
==================================================================== */



namespace NPOI.SS.Util
{
    using System;
    using System.Text;
    using System.Text.RegularExpressions;
    using NPOI.SS.Formula;
    using NPOI.SS.UserModel;
    using System.Globalization;

    public enum NameType:int
    {
        /// <summary>
        /// Allow accessing the Initial value.
        /// </summary>
        None = 0,
        Cell = 1,
        NamedRange = 2,
        Column = 3,
        Row = 4,
        BadCellOrNamedRange = -1
    }

    /**
     * <p>Common conversion functions between Excel style A1, C27 style
     *  cell references, and POI usermodel style row=0, column=0
     *  style references. Handles sheet-based and sheet-free references
     *  as well, eg "Sheet1!A1" and "$B$72"</p>
     *  
     *  <p>Use <tt>CellReference</tt> when the concept of
     * relative/absolute does apply (such as a cell reference in a formula).
     * Use {@link CellAddress} when you want to refer to the location of a cell in a sheet
     * when the concept of relative/absolute does not apply (such as the anchor location 
     * of a cell comment).
     * <tt>CellReference</tt>s have a concept of "sheet", while <tt>CellAddress</tt>es do not.</p>
     */

    public class CellReference
    {
        /** The character ($) that signifies a row or column value is absolute instead of relative */
        private const char ABSOLUTE_REFERENCE_MARKER = '$';
        /** The character (!) that Separates sheet names from cell references */
        private const char SHEET_NAME_DELIMITER = '!';
        /** The character (') used to quote sheet names when they contain special characters */
        private const char SPECIAL_NAME_DELIMITER = '\'';

        /**
         * Matches a run of one or more letters followed by a run of one or more digits.
         * Both the letter and number groups are optional.
         * The run of letters is group 1 and the run of digits is group 2.
         * Each group may optionally be prefixed with a single '$'.
         */
        //private const string CELL_REF_PATTERN = @"^\$?([A-Za-z]+)\$?([0-9]+)";
        //private static final Pattern CELL_REF_PATTERN = Pattern.compile("(\\$?[A-Z]+)?" + "(\\$?[0-9]+)?", Pattern.CASE_INSENSITIVE);
        private static Regex CELL_REF_PATTERN = new Regex("(\\$?[A-Z]+)?" + "(\\$?[0-9]+)?", RegexOptions.IgnoreCase);

        /**
         * Matches references only where row and column are included.
         * Matches a run of one or more letters followed by a run of one or more digits.
         * If a reference does not match this pattern, it might match COLUMN_REF_PATTERN or ROW_REF_PATTERN
         * References may optionally include a single '$' before each group, but these are excluded from the Matcher.group(int).
         */
        //private static final Pattern STRICTLY_CELL_REF_PATTERN = Pattern.compile("\\$?([A-Z]+)" + "\\$?([0-9]+)", Pattern.CASE_INSENSITIVE);
        private static Regex STRICTLY_CELL_REF_PATTERN = new Regex("^\\$?([A-Z]+)" + "\\$?([0-9]+)$", RegexOptions.IgnoreCase);
        /**
         * Matches a run of one or more letters.  The run of letters is group 1.  
         * References may optionally include a single '$' before the group, but these are excluded from the Matcher.group(int).
         */
        private static Regex COLUMN_REF_PATTERN = new Regex(@"^\$?([A-Za-z]+)$", RegexOptions.IgnoreCase);
        /**
         * Matches a run of one or more letters.  The run of numbers is group 1.
         * References may optionally include a single '$' before the group, but these are excluded from the Matcher.group(int).
         */
        private static Regex ROW_REF_PATTERN = new Regex(@"^\$?([0-9]+)$");
        /**
         * Named range names must start with a letter or underscore.  Subsequent characters may include
         * digits or dot.  (They can even end in dot).
         */
        //private static final Pattern NAMED_RANGE_NAME_PATTERN = Pattern.compile("[_A-Z][_.A-Z0-9]*", Pattern.CASE_INSENSITIVE);
        private static Regex NAMED_RANGE_NAME_PATTERN = new Regex("^[_A-Za-z][_.A-Za-z0-9]*$", RegexOptions.IgnoreCase);
        //private static string BIFF8_LAST_COLUMN = "IV";
        //private static int BIFF8_LAST_COLUMN_TEXT_LEN = BIFF8_LAST_COLUMN.Length;
        //private static string BIFF8_LAST_ROW = (0x10000).ToString();
{'fraction_non_alphanumeric': 0.12815126050420167, 'fraction_numerical': 0.009358288770053475, 'mean_word_length': 2.732359230220955, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '790999', 'n_tokens_mistral': 3031, 'n_tokens_neox': 2891, 'n_words': 1116}