function _parsePasswordRule()

in tools/PasswordRulesParser.js [403:462]


function _parsePasswordRule(input, position)
{
    console.assert(position >= 0);
    console.assert(position < input.length);
    console.assert(_isIdentifierCharacter(input[position]));

    let length = input.length;

    var mayBeIdentifierStartPosition = position;
    var [identifier, position] = _parseIdentifier(input, position);
    if (!Object.values(RuleName).includes(identifier)) {
        console.error("Unrecognized property name: " + identifier);
        return [null, mayBeIdentifierStartPosition];
    }

    if (position >= length) {
        console.error("Found end-of-line instead of start of property value");
        return [null, position];
    }

    if (input[position] !== PROPERTY_VALUE_START_SENTINEL) {
        console.error("Failed to find start of property value: " + input.substr(position));
        return [null, position];
    }

    let property = { name: identifier, value: null };

    position = _indexOfNonWhitespaceCharacter(input, position + 1);
    // Empty value
    if (position >= length || input[position] === PROPERTY_SEPARATOR) {
        return [new Rule(property.name, property.value), position];
    }

    switch (identifier) {
        case RuleName.ALLOWED:
        case RuleName.REQUIRED: {
            var [propertyValue, position] = _parsePasswordRequiredOrAllowedPropertyValue(input, position);
            if (propertyValue) {
                property.value = propertyValue;
            }
            return [new Rule(property.name, property.value), position];
        }
        case RuleName.MAX_CONSECUTIVE: {
            var [propertyValue, position] = _parseMaxConsecutivePropertyValue(input, position);
            if (propertyValue) {
                property.value = propertyValue;
            }
            return [new Rule(property.name, property.value), position];
        }
        case RuleName.MIN_LENGTH:
        case RuleName.MAX_LENGTH: {
            var [propertyValue, position] = _parseMinLengthMaxLengthPropertyValue(input, position);
            if (propertyValue) {
                property.value = propertyValue;
            }
            return [new Rule(property.name, property.value), position];
        }
    }
    console.assert(false, SHOULD_NOT_BE_REACHED);
}