in src/main/software/amazon/event/ruler/ByteMachine.java [751:779]
private NameState addMatchValue(Patterns pattern, String value, NameState nameStateToBeReturned) {
final InputCharacter[] characters = getParser().parse(pattern.type(), value);
ByteState byteState = startState;
ByteState prevByteState = null;
int i = 0;
for (; i < characters.length - 1; i++) {
ByteTransition trans = getTransition(byteState, characters[i]);
if (trans.isEmpty()) {
break;
}
ByteState stateToReuse = null;
for (SingleByteTransition single : trans.expand()) {
ByteState nextByteState = single.getNextByteState();
if (canReuseNextByteState(byteState, nextByteState, characters, i)) {
stateToReuse = nextByteState;
break;
}
}
if (stateToReuse == null) {
break;
}
prevByteState = byteState;
byteState = stateToReuse;
}
// we found our way through the machine with all characters except the last having matches or shortcut.
return addEndOfMatch(byteState, prevByteState, characters, i, pattern, nameStateToBeReturned);
}