lost+found/src/pattern.js
function (item, state) {
                var
                    nextItem = this._getItem(state, state.index + 1),
                    optional;
                if (this._choice && -1 < state.choice) {
                    optional = this._optionals[state.choice];
                } else {
                    optional = this._optionals[0];
                }
                ++state.count;
                if (0 === item.max()) {
                    // Unlimited
                    this._reset(item, state);
                    if (null !== nextItem && optional > state.index) {
                        return PatternItem.WRITE_NEED_DATA;
                    } else {
                        // Last (or equivalent) so...
                        return PatternItem.WRITE_MATCH;
                    }
                } else if (state.count === item.max()) {
                    if (null === nextItem) {
                        return PatternItem.WRITE_FINAL_MATCH;
                    }
                    ++state.index;
                    this._reset(nextItem, state);
                    if (optional <= state.index) {
                        return PatternItem.WRITE_MATCH;
                    }
                }
                return PatternItem.WRITE_NEED_DATA;
            }
function (item, state) {
                var
                    nextItem = this._getItem(state, state.index + 1),
                    optional;
                if (this._choice && -1 < state.choice) {
                    optional = this._optionals[state.choice];
                } else {
                    optional = this._optionals[0];
                }
                ++state.count;
                if (0 === item.max()) {
                    // Unlimited
                    this._reset(item, state);
                    if (null !== nextItem && optional > state.index) {
                        return PatternItem.WRITE_NEED_DATA;
                    } else {
                        // Last (or equivalent) so...
                        return PatternItem.WRITE_MATCH;
                    }
                } else if (state.count === item.max()) {
                    if (null === nextItem) {
                        return PatternItem.WRITE_FINAL_MATCH;
                    }
                    ++state.index;
                    this._reset(nextItem, state);
                    if (optional <= state.index) {
                        return PatternItem.WRITE_MATCH;
                    }
                }
                return PatternItem.WRITE_NEED_DATA;
            }
function ( item , state ) { var nextItem = this . _getItem ( state , state . index + 1 ) , optional ; if ( this . _choice && - 1 < state . choice ) { optional = this . _optionals [ state . choice ] ; } else { optional = this . _optionals [ 0 ] ; } ++ state . count ; if ( 0 === item . max ( ) ) { // Unlimited this . _reset ( item , state ) ; if ( null !== nextItem && optional > state . index ) { return PatternItem . WRITE_NEED_DATA ; } else { // Last (or equivalent) so... return PatternItem . WRITE_MATCH ; } } else if ( state . count === item . max ( ) ) { if ( null === nextItem ) { return PatternItem . WRITE_FINAL_MATCH ; } ++ state . index ; this . _reset ( nextItem , state ) ; if ( optional <= state . index ) { return PatternItem . WRITE_MATCH ; } } return PatternItem . WRITE_NEED_DATA ; }
Handles situation when current item matches on char

@param {PatternItem} item
@return {Number} write result
@private
Handles situation when current item matches on char