<commit_before>/**
@module ember
@submodule ember-runtime
*/
import { deprecate } from 'ember-metal/debug';
import {
  inspect as emberInspect
} from 'ember-metal/utils';
import { isArray } from 'ember-runtime/utils';
import {
  get as getString
} from 'ember-runtime/string_registry';

import Cache from 'ember-metal/cache';

var STRING_DASHERIZE_REGEXP = (/[ _]/g);

var STRING_DASHERIZE_CACHE = new Cache(1000, function(key) {
  return decamelize(key).replace(STRING_DASHERIZE_REGEXP, '-');
});

var STRING_CAMELIZE_REGEXP_1 = (/(\-|\_|\.|\s)+(.)?/g);
var STRING_CAMELIZE_REGEXP_2 = (/(^|\/)([A-Z])/g);

var CAMELIZE_CACHE = new Cache(1000, function(key) {
  return key.replace(STRING_CAMELIZE_REGEXP_1, function(match, separator, chr) {
    return chr ? chr.toUpperCase() : '';
  }).replace(STRING_CAMELIZE_REGEXP_2, function(match, separator, chr) {
    return match.toLowerCase();
  });
});

var STRING_CLASSIFY_REGEXP_1 = (/^(\-|_)+(.)?/);
var STRING_CLASSIFY_REGEXP_2 = (/(.)(\-|\_|\.|\s)+(.)?/g);
var STRING_CLASSIFY_REGEXP_3 = (/(^|\/|\.)([a-z])/g);

var CLASSIFY_CACHE = new Cache(1000, function(str) {
  var replace1 = function(match, separator, chr) {
    return chr ? ('_' + chr.toUpperCase()) : '';
  };
  var replace2 = function(match, initialChar, separator, chr) {
    return initialChar + (chr ? chr.toUpperCase() : '');
  };
  var parts = str.split('/');
  for (var i = 0, len = parts.length; i < len; i++) {
    parts[i] = parts[i]
      .replace(STRING_CLASSIFY_REGEXP_1, replace1)
      .replace(STRING_CLASSIFY_REGEXP_2, replace2);
  }
  return parts.join('/')
  .replace(STRING_CLASSIFY_REGEXP_3, function(match, separator, chr) {
    return match.toUpperCase();
  });
});

var STRING_UNDERSCORE_REGEXP_1 = (/([a-z\d])([A-Z]+)/g);
var STRING_UNDERSCORE_REGEXP_2 = (/\-|\s+/g);

var UNDERSCORE_CACHE = new Cache(1000, function(str) {
  return str.replace(STRING_UNDERSCORE_REGEXP_1, '$1_$2').
    replace(STRING_UNDERSCORE_REGEXP_2, '_').toLowerCase();
});

var STRING_CAPITALIZE_REGEXP = (/(^|\/)([a-z])/g);

var CAPITALIZE_CACHE = new Cache(1000, function(str) {
  return str.replace(STRING_CAPITALIZE_REGEXP, function(match, separator, chr) {
    return match.toUpperCase();
  });
});

var STRING_DECAMELIZE_REGEXP = (/([a-z\d])([A-Z])/g);

var DECAMELIZE_CACHE = new Cache(1000, function(str) {
  return str.replace(STRING_DECAMELIZE_REGEXP, '$1_$2').toLowerCase();
});

function _fmt(str, formats) {
  var cachedFormats = formats;

  if (!isArray(cachedFormats) || arguments.length > 2) {
    cachedFormats = new Array(arguments.length - 1);

    for (var i = 1, l = arguments.length; i < l; i++) {
      cachedFormats[i - 1] = arguments[i];
    }
  }

  // first, replace any ORDERED replacements.
  var idx  = 0; // the current index for non-numerical replacements
  return str.replace(/%@([0-9]+)?/g, function(s, argIndex) {
    argIndex = (argIndex) ? parseInt(argIndex, 10) - 1 : idx++;
    s = cachedFormats[argIndex];
    return (s === null) ? '(null)' : (s === undefined) ? '' : emberInspect(s);
  });
}

function fmt(str, formats) {
  deprecate(
    'Ember.String.fmt is deprecated, use ES6 template strings instead.',
    false,
    { id: 'ember-string-utils.fmt', until: '3.0.0', url: 'https://babeljs.io/docs/learn-es6/#template-strings' }
  );
  return _fmt(...arguments);
}

function loc(str, formats) {
  if (!isArray(formats) || arguments.length > 2) {
    formats = Array.prototype.slice.call(arguments, 1);
  }

  str = getString(str) || str;
  return _fmt(str, formats);
}

function w(str) {
  return str.split(/\s+/);
}

function decamelize(str) {
  return DECAMELIZE_CACHE.get(str);
}

function dasherize(str) {
  return STRING_DASHERIZE_CACHE.get(str);
}

function camelize(str) {
  return CAMELIZE_CACHE.get(str);
}

function classify(str) {
  return CLASSIFY_CACHE.get(str);
}

function underscore(str) {
  return UNDERSCORE_CACHE.get(str);
}

function capitalize(str) {
  return CAPITALIZE_CACHE.get(str);
}

/**
  Defines string helper methods including string formatting and localization.
  Unless `Ember.EXTEND_PROTOTYPES.String` is `false` these methods will also be
  added to the `String.prototype` as well.

  @class String
  @namespace Ember
  @static
  @public
*/
export default {
  /**
    Apply formatting options to the string. This will look for occurrences
    of "%@" in your string and substitute them with the arguments you pass into
    this method. If you want to control the specific order of replacement,
    you can add a number after the key as well to indicate which argument
    you want to insert.

    Ordered insertions are most useful when building loc strings where values
    you need to insert may appear in different orders.

    ```javascript
    "Hello %@ %@".fmt('John', 'Doe');     // "Hello <NAME>"
    "Hello %@2, %@1".fmt('John', 'Doe');  // "Hello Doe, John"
    ```

    @method fmt
    @param {String} str The string to format
    @param {Array} formats An array of parameters to interpolate into string.
    @return {String} formatted string
    @public
    @deprecated Use ES6 template strings instead: https://babeljs.io/docs/learn-es6/#template-strings');
  */
  fmt,<commit_msg>Fix deprecation link for Ember.String.fmt<commit_after>/**
@module ember
@submodule ember-runtime
*/
import { deprecate } from 'ember-metal/debug';
import {
  inspect as emberInspect
} from 'ember-metal/utils';
import { isArray } from 'ember-runtime/utils';
import {
  get as getString
} from 'ember-runtime/string_registry';

import Cache from 'ember-metal/cache';

var STRING_DASHERIZE_REGEXP = (/[ _]/g);

var STRING_DASHERIZE_CACHE = new Cache(1000, function(key) {
  return decamelize(key).replace(STRING_DASHERIZE_REGEXP, '-');
});

var STRING_CAMELIZE_REGEXP_1 = (/(\-|\_|\.|\s)+(.)?/g);
var STRING_CAMELIZE_REGEXP_2 = (/(^|\/)([A-Z])/g);

var CAMELIZE_CACHE = new Cache(1000, function(key) {
  return key.replace(STRING_CAMELIZE_REGEXP_1, function(match, separator, chr) {
    return chr ? chr.toUpperCase() : '';
  }).replace(STRING_CAMELIZE_REGEXP_2, function(match, separator, chr) {
    return match.toLowerCase();
  });
});

var STRING_CLASSIFY_REGEXP_1 = (/^(\-|_)+(.)?/);
var STRING_CLASSIFY_REGEXP_2 = (/(.)(\-|\_|\.|\s)+(.)?/g);
var STRING_CLASSIFY_REGEXP_3 = (/(^|\/|\.)([a-z])/g);

var CLASSIFY_CACHE = new Cache(1000, function(str) {
  var replace1 = function(match, separator, chr) {
    return chr ? ('_' + chr.toUpperCase()) : '';
  };
  var replace2 = function(match, initialChar, separator, chr) {
    return initialChar + (chr ? chr.toUpperCase() : '');
  };
  var parts = str.split('/');
  for (var i = 0, len = parts.length; i < len; i++) {
    parts[i] = parts[i]
      .replace(STRING_CLASSIFY_REGEXP_1, replace1)
      .replace(STRING_CLASSIFY_REGEXP_2, replace2);
  }
  return parts.join('/')
  .replace(STRING_CLASSIFY_REGEXP_3, function(match, separator, chr) {
    return match.toUpperCase();
  });
});

var STRING_UNDERSCORE_REGEXP_1 = (/([a-z\d])([A-Z]+)/g);
var STRING_UNDERSCORE_REGEXP_2 = (/\-|\s+/g);

var UNDERSCORE_CACHE = new Cache(1000, function(str) {
  return str.replace(STRING_UNDERSCORE_REGEXP_1, '$1_$2').
    replace(STRING_UNDERSCORE_REGEXP_2, '_').toLowerCase();
});

var STRING_CAPITALIZE_REGEXP = (/(^|\/)([a-z])/g);

var CAPITALIZE_CACHE = new Cache(1000, function(str) {
  return str.replace(STRING_CAPITALIZE_REGEXP, function(match, separator, chr) {
    return match.toUpperCase();
  });
});

var STRING_DECAMELIZE_REGEXP = (/([a-z\d])([A-Z])/g);

var DECAMELIZE_CACHE = new Cache(1000, function(str) {
  return str.replace(STRING_DECAMELIZE_REGEXP, '$1_$2').toLowerCase();
});

function _fmt(str, formats) {
  var cachedFormats = formats;

  if (!isArray(cachedFormats) || arguments.length > 2) {
    cachedFormats = new Array(arguments.length - 1);

    for (var i = 1, l = arguments.length; i < l; i++) {
      cachedFormats[i - 1] = arguments[i];
    }
  }

  // first, replace any ORDERED replacements.
  var idx  = 0; // the current index for non-numerical replacements
  return str.replace(/%@([0-9]+)?/g, function(s, argIndex) {
    argIndex = (argIndex) ? parseInt(argIndex, 10) - 1 : idx++;
    s = cachedFormats[argIndex];
    return (s === null) ? '(null)' : (s === undefined) ? '' : emberInspect(s);
  });
}

function fmt(str, formats) {
  deprecate(
    'Ember.String.fmt is deprecated, use ES6 template strings instead.',
    false,
    { id: 'ember-string-utils.fmt', until: '3.0.0', url: 'http://babeljs.io/docs/learn-es2015/#template-strings' }
  );
  return _fmt(...arguments);
}

function loc(str, formats) {
  if (!isArray(formats) || arguments.length > 2) {
    formats = Array.prototype.slice.call(arguments, 1);
  }

  str = getString(str) || str;
  return _fmt(str, formats);
}

function w(str) {
  return str.split(/\s+/);
}

function decamelize(str) {
  return DECAMELIZE_CACHE.get(str);
}

function dasherize(str) {
  return STRING_DASHERIZE_CACHE.get(str);
}

function camelize(str) {
  return CAMELIZE_CACHE.get(str);
}

function classify(str) {
  return CLASSIFY_CACHE.get(str);
}

function underscore(str) {
  return UNDERSCORE_CACHE.get(str);
}

function capitalize(str) {
  return CAPITALIZE_CACHE.get(str);
}

/**
  Defines string helper methods including string formatting and localization.
  Unless `Ember.EXTEND_PROTOTYPES.String` is `false` these methods will also be
  added to the `String.prototype` as well.

  @class String
  @namespace Ember
  @static
  @public
*/
export default {
  /**
    Apply formatting options to the string. This will look for occurrences
    of "%@" in your string and substitute them with the arguments you pass into
    this method. If you want to control the specific order of replacement,
    you can add a number after the key as well to indicate which argument
    you want to insert.

    Ordered insertions are most useful when building loc strings where values
    you need to insert may appear in different orders.

    ```javascript
    "Hello %@ %@".fmt('John', 'Doe');     // "Hello <NAME>"
    "Hello %@2, %@1".fmt('John', 'Doe');  // "Hello <NAME>"
    ```

    @method fmt
    @param {String} str The string to format
    @param {Array} formats An array of parameters to interpolate into string.
    @return {String} formatted string
    @public
    @deprecated Use ES6 template strings instead: http://babeljs.io/docs/learn-es2015/#template-strings
  */
  fmt,
{'fraction_non_alphanumeric': 0.15848257269401117, 'fraction_numerical': 0.013672251107259772, 'mean_word_length': 3.9274193548387095, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 2, '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': '1679894', 'n_tokens_mistral': 3807, 'n_tokens_neox': 3626, 'n_words': 880}