Ejemplo n.º 1
0
        /// <summary>
        /// Build string from automaton.
        /// </summary>
        /// <param name="root">Root state</param>
        /// <param name="current">Current State</param>
        /// <param name="inputCustom">Input custom (do not modify)</param>
        /// <param name="pos">Return current position</param>
        /// <param name="nextCharacter">Return next valid character.</param>
        /// <returns>If nextCharacter is -1, Return only next character, otherwise, return all the string.</returns>
        public virtual string FromAutomaton(InputAutomaton root, InputAutomaton current, IInputCustom custom, ref int pos, ref int nextCharacter)
        {
            var result = new StringBuilder();

            pos = 0;

            InputAutomaton automaton = root;

            while (!(automaton.IsAccept()))
            {
                // Select first connection
                var select = automaton.GetConnect().First();

                int    c2        = select.Key;
                string addstring = select.Value.Character;

                // In CPU mode, use only first key
                if (nextCharacter != -1)
                {
                    nextCharacter = c2;
                    break;
                }

                // Go to next automaton
                bool valid2 = false;
                result.Append(addstring);
                automaton = automaton.Input(c2, ref valid2, null);
                if (current == automaton)
                {
                    pos = result.Length;
                }
            }

            return(result.ToString());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Build automaton from word string
        /// </summary>
        /// <param name="word">Word string</param>
        /// <param name="keyboard">Keyboard</param>
        /// <returns>Automaton</returns>
        public virtual InputAutomaton ToAutomaton(string s, InputKeyboard keyboard)
        {
            InputAutomaton start   = new InputAutomaton();
            InputAutomaton current = start;

            // You can input any character with "a" key!
            for (int i = 0; i < s.Length; i++)
            {
                var newAutomaton = new InputAutomaton();
                current.SetConnect((int)WTKeyCode.A, new InputAutomaton.Connect()
                {
                    Automaton = newAutomaton,
                    Character = "a",
                    Flags     = Ope_NO_XN,
                });
                current = newAutomaton;
            }

            return(start);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Dump InputAutomaton in Plugin domain
 /// </summary>
 public string DumpAutomaton()
 {
     return(InputAutomaton.Dump());
 }