static RegExpDfa Power0Unlimited(RegExpDfa operand) { if (operand.CanReturnFromFinalState()) { operand = HardAnd(operand, EmptyTransitionDfa); } if (operand.CanReturnToInitialState()) { operand = HardAnd(EmptyTransitionDfa, operand); } return(HardOr(Empty, operand)); }
static RegExpDfa PowerOptional(RegExpDfa operand, int count) { if (count == 0) { return(null); } RegExpDfa head = new RegExpDfa(operand); if (head.CanReturnFromFinalState()) { head = HardAnd(head, EmptyTransitionDfa); } if (head.CanReturnToInitialState()) { head = HardAnd(EmptyTransitionDfa, head); } RegExpDfa dfa2 = new RegExpDfa(operand) | EmptyTransitionDfa; for (int i = 1; i < count; i++) { Dictionary <RegExpState, RegExpState> dictionary = new Dictionary <RegExpState, RegExpState>(); foreach (RegExpState state in head.GetAllStates()) { RegExpState initialState; if (object.ReferenceEquals(state, head._finalState)) { initialState = dfa2._initialState; } else { initialState = new RegExpState(); } dictionary.Add(state, initialState); } dfa2._initialState = dictionary[head._initialState]; foreach (RegExpState state3 in dictionary.Keys) { foreach (Transition transition in state3.Transitions) { RegExpState state4 = dictionary[state3]; RegExpState target = dictionary[transition.Target]; state4.AddTransition(transition.Copy(target)); } } dfa2._initialState.AddTransition(new EmptyTransition(dfa2._finalState)); } return(dfa2); }