src/third_party/mozjs/extract/intl/locale/PluralForm.jsm
/**
   * Create a pair of plural form functions for the given plural rule number.
   *
   * @param aRuleNum
   *        The plural rule number to create functions
   * @return A pair: [function that gets the right plural form,
   *                  function that returns the number of plural forms]
   */
Create a pair of plural form functions for the given plural rule number.
@param aRuleNum
The plural rule number to create functions
@return A pair: [function that gets the right plural form,
function that returns the number of plural forms]
Create a pair of plural form functions for the given plural rule number . @param aRuleNum The plural rule number to create functions @return A pair : [ function that gets the right plural form function that returns the number of plural forms ]
makeGetter(aRuleNum) {
    if (aRuleNum < 0 || aRuleNum >= gFunctions.length || isNaN(aRuleNum)) {
      log(["Invalid rule number: ", aRuleNum, " -- defaulting to 0"]);
      aRuleNum = 0;
    }
    let [numForms, pluralFunc] = gFunctions[aRuleNum];
    return [
      function(aNum, aWords) {
        let index = pluralFunc(aNum ? Number(aNum) : 0);
        let words = aWords ? aWords.split(/;/) : [""];
        let ret = index < words.length ? words[index] : undefined;
        if (ret == undefined || ret == "") {
          let caller = Components.stack.caller
            ? Components.stack.caller.name
            : "top";
          log([
            "Index #",
            index,
            " of '",
            aWords,
            "' for value ",
            aNum,
            " is invalid -- plural rule #",
            aRuleNum,
            "; called by ",
            caller,
          ]);
          ret = words[0];
        }
        return ret;
      },
      () => numForms,
    ];
  }
makeGetter ( aRuleNum ) { if ( aRuleNum < 0 || aRuleNum >= gFunctions . length || isNaN ( aRuleNum ) ) { log ( [ "Invalid rule number: " , aRuleNum , " -- defaulting to 0" ] ) ; aRuleNum = 0 ; } let [ numForms , pluralFunc ] = gFunctions [ aRuleNum ] ; return [ function ( aNum , aWords ) { let index = pluralFunc ( aNum ? Number ( aNum ) : 0 ) ; let words = aWords ? aWords . split ( / ; / ) : [ "" ] ; let ret = index < words . length ? words [ index ] : undefined ; if ( ret == undefined || ret == "" ) { let caller = Components . stack . caller ? Components . stack . caller . name : "top" ; log ( [ "Index #" , index , " of '" , aWords , "' for value " , aNum , " is invalid -- plural rule #" , aRuleNum , "; called by " , caller , ] ) ; ret = words [ 0 ] ; } return ret ; } , ( ) => numForms , ] ; }
Create a pair of plural form functions for the given plural rule number.
Create a pair of plural form functions for the given plural rule number .
// Default to "all plural" if the value is out of bounds or invalid // Get the desired pluralRule function // Return functions that give 1) the number of forms and 2) gets the right // plural form // Figure out which index to use for the semi-colon separated words // Explicitly check bounds to avoid strict warnings // Check for array out of bounds or empty strings // Report the caller to help figure out who is causing badness // Display a message in the error console // Default to the first entry (which might be empty, but not undefined)