<commit_before>/**
 * R1C1 pattern
 *
 * @type {RegExp}
 */

var R1C1 = /^R(\d+)C(\d+)$/;

/**
 * A1 pattern
 *
 * @type {RegExp}
 */

var A1 = /^([A-Z]+)(\d+)$/;

/**
 * Convert A1 notation to R1C1 notation
 *
 * @param {string} ref
 * @returns {string}
 * @throws {Error}
 */

function A1toR1C1(ref) {
  if (!A1.test(ref)) {
    throw new Error(ref + ' is not a valid A1 cell reference');
  }

  var refParts = ref
    .replace(A1, '$1,$2')
    .split(',');

  var columnStr = refParts[0];
  var row = refParts[1];
  var column = 0;

  for (var i = 0; i < columnStr.length; i++) {
    column = 26 * column + columnStr.charCodeAt(i) - 64;
  }

  return 'R' + row + 'C' + column;
}

/**
 * Convert R1C1 notation to A1 notation
 *
 * @param {string} ref
 * @returns {string}
 * @throws {Error}
 */

function R1C1toA1(ref) {
  if (!R1C1.test(ref)) {
    throw new Error(ref + ' is not a valid R1C1 cell reference');
  }

  var refParts = ref
    .replace(R1C1, '$1,$2')
    .split(',');

  var row = refParts[0];
  var column = refParts[1];
  var columnStr = '';

  for (; column; column = Math.floor(column / 26)) {
    columnStr = String.fromCharCode((column % 26) + 64) + columnStr;
  }

  return columnStr + row;
}

/**
 * Auto detects notation used and converts to the opposite notation
 *
 * @param {string} ref
 * @returns {string}
 * @throws {Error}
 */

function cellref(ref) {
  if (R1C1.test(ref)) {
    return R1C1toA1(ref);
  }

  if (A1.test(ref)) {
    return A1toR1C1(ref);
  }

  throw new Error('could not detect cell reference notation for ' + ref);
}

/**
 * Exports
 */

module.exports = cellref;
module.exports.toA1 = R1C1toA1;
module.exports.toR1C1 = A1toR1C1;<commit_msg>rename internal methods for clarity<commit_after>/**
 * R1C1 pattern
 *
 * @type {RegExp}
 */

var R1C1 = /^R(\d+)C(\d+)$/;

/**
 * A1 pattern
 *
 * @type {RegExp}
 */

var A1 = /^([A-Z]+)(\d+)$/;

/**
 * Convert A1 notation to R1C1 notation
 *
 * @param {string} ref
 * @returns {string}
 * @throws {Error}
 */

function convertA1toR1C1(ref) {
  if (!A1.test(ref)) {
    throw new Error(ref + ' is not a valid A1 cell reference');
  }

  var refParts = ref
    .replace(A1, '$1,$2')
    .split(',');

  var columnStr = refParts[0];
  var row = refParts[1];
  var column = 0;

  for (var i = 0; i < columnStr.length; i++) {
    column = 26 * column + columnStr.charCodeAt(i) - 64;
  }

  return 'R' + row + 'C' + column;
}

/**
 * Convert R1C1 notation to A1 notation
 *
 * @param {string} ref
 * @returns {string}
 * @throws {Error}
 */

function convertR1C1toA1(ref) {
  if (!R1C1.test(ref)) {
    throw new Error(ref + ' is not a valid R1C1 cell reference');
  }

  var refParts = ref
    .replace(R1C1, '$1,$2')
    .split(',');

  var row = refParts[0];
  var column = refParts[1];
  var columnStr = '';

  for (; column; column = Math.floor(column / 26)) {
    columnStr = String.fromCharCode((column % 26) + 64) + columnStr;
  }

  return columnStr + row;
}

/**
 * Auto detects notation used and converts to the opposite notation
 *
 * @param {string} ref
 * @returns {string}
 * @throws {Error}
 */

function cellref(ref) {
  if (R1C1.test(ref)) {
    return convertR1C1toA1(ref);
  }

  if (A1.test(ref)) {
    return convertA1toR1C1(ref);
  }

  throw new Error('could not detect cell reference notation for ' + ref);
}

/**
 * Exports
 */

module.exports = cellref;
module.exports.toA1 = convertR1C1toA1;
module.exports.toR1C1 = convertA1toR1C1;
{'fraction_non_alphanumeric': 0.17449275362318842, 'fraction_numerical': 0.03768115942028986, 'mean_word_length': 2.9621125143513205, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1383116', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1354, 'n_words': 347}