internal CaseWordVocabularySource(ApplicationModel model, WordVocabularySource source, HeadWordItem target)
            : base(model)
        {
            _source = source;
            _target = target;

            var substitutes = new List <string>();

            var tile       = TileData.FromTokenString(target.Content);
            var content    = tile.Content;
            var isPrefix   = tile.IsPrefix;
            var isSuffix   = tile.IsSuffix;
            var attributes = tile.Attributes;
            var included   = new HashSet <string> {
                target.Content
            };

            var map = WordCaseMap.Create(content);

            if (map.LetterCount != 0)
            {
                var position0 = map.Positions[0];

                CheckedAdd(model.HeadItems[0].Culture.TextInfo.ToTitleCase(content));
                CheckedAdd(content.ToLower());
                CheckedAdd(content.ToUpper());
                CheckedAdd(content.Substring(0, position0) + char.ToUpper(content[position0]) + content.Substring(position0 + 1));

                for (var i = 0; i < map.Positions.Length; i++)
                {
                    var position = map.Positions[i];
                    var ch       = map.Uppers[i] ? char.ToLower(content[position]) : char.ToUpper(content[position]);
                    var cased    = content.Substring(0, position) + ch + content.Substring(position + 1);
                    CheckedAdd(cased);
                }

                void CheckedAdd(string newContent)
                {
                    var newTile = TileData.Create(content: newContent, isSuffix: isPrefix, isPrefix: isSuffix, attributes: attributes);
                    var version = newTile.ToTokenString();

                    if (included.Add(version))
                    {
                        substitutes.Add(version);
                    }
                }
            }

            for (var i = 0; i < 4; i++)
            {
                var spacedTile    = TileData.Create(content: content, isSuffix: (i & 1) != 0, isPrefix: (i & 2) != 0, attributes: attributes);
                var spacedContent = spacedTile.ToTokenString();
                if (included.Add(spacedContent))
                {
                    substitutes.Add(spacedContent);
                }
            }

            _substitutes = substitutes.ToArray();
        }
示例#2
0
        internal void ShowTestCard()
        {
            // Truncate head items.
            for (var i = _headItems.Count - 1; 0 < i; i--)
            {
                _headItems.RemoveAt(i);
            }

            var headWordItem = new HeadWordItem(_headItems[0], this, "Word");

            _headItems.Add(headWordItem);

            var ghostWordItem = new GhostWordItem(_headItems[1], this, "Ghost");

            _headItems.Add(ghostWordItem);

            var ghostStopItem = new GhostStopItem(_headItems[2], this);

            _headItems.Add(ghostStopItem);
        }
示例#3
0
        private HeadWordItem CreateHeadWordItem(string word)
        {
            var item = new HeadWordItem(LastTile, this, word);

            return(item);
        }