Пример #1
0
        private void CheckInit()
        {
            if (initDone)
            {
                return;
            }

            initDone        = true;
            internalKeyname = savedKeyname;
        }
Пример #2
0
 public KeynameSerializable(string savedKeyname)
 {
     initDone          = false;
     this.savedKeyname = savedKeyname;
     internalKeyname   = string.Empty;
 }
Пример #3
0
        internal Keyname Convert(string source, KeynameSettingsData settings = null)
        {
            settings = settings == null ? KeynameSettings.Default.Data : settings;

            var keyname = new Keyname(false);

            keyname.settings = settings;
            if (string.IsNullOrEmpty(source))
            {
                return(keyname);
            }

            var keywordMatch = settings.KeywordRegex.Match(source);

            if (!keywordMatch.Success)
            {
                return(keyname);
            }

            var firstLoop   = true;
            var keyword     = new Keyword();
            var numberMatch = settings.NumberRegex.Match(source);

            while (true)
            {
                var keywordIndex = keywordMatch.Success ? keywordMatch.Index : int.MaxValue;
                var numberIndex  = numberMatch.Success ? numberMatch.Index : int.MaxValue;

                if (numberIndex < keywordIndex)
                {
                    if (firstLoop)
                    {
                        throw new ArithmeticException("Keyname cannot start with a numerical value");
                    }

                    keyname.Add(new Keyword(keyword, int.Parse(numberMatch.Value)));
                    keyword     = new Keyword();
                    numberMatch = numberMatch.NextMatch();
                }
                else
                {
                    var keywordType = GetKeywordType(keywordMatch.Value);
                    if (keywordType != null)
                    {
                        if (keyword.Status != KeywordStatus.None)
                        {
                            keyname.Add(keyword);
                        }

                        keyword = keywordType;
                    }
                    else
                    {
                        if (keyword.Status == KeywordStatus.Name)
                        {
                            keyword = keyword.Name + keywordMatch.Value;
                        }
                        else
                        {
                            if (keyword.Status == KeywordStatus.Type)
                            {
                                keyname.Add(keyword);
                            }

                            keyword = keywordMatch.Value;
                        }
                    }

                    keywordMatch = keywordMatch.NextMatch();
                }

                firstLoop = false;

                if (!keywordMatch.Success && !numberMatch.Success)
                {
                    break;
                }
            }

            if (keyword.Status != KeywordStatus.None)
            {
                keyname.Add(keyword);
            }

            return(keyname);
        }