Пример #1
0
        public bool FMatch(ATM atm)
        {
            if (m_atmt != atm.m_atmt)
            return false;

            if (m_atmt == ATMT.Separator)
            return true;	// separators match, even if they're not the same

            return String.Compare(m_sWord, atm.m_sWord, true) == 0;
        }
Пример #2
0
        /* P L A T M  B U I L D  F R O M  S T R I N G */
        /*----------------------------------------------------------------------------
        %%Function: PlatmBuildFromString
        %%Qualified: SList.MainForm:ATMC.PlatmBuildFromString
        %%Contact: rlittle

        Build platm from the given sName
        ----------------------------------------------------------------------------*/
        ArrayList PlatmBuildFromString(string sName)
        {
            ArrayList platm = new ArrayList();
            int ich = 0;
            int ichFirst = -1;
            int ichMax;
            ATMT atmtCur = ATMT.TitleWord;
            bool fCollecting = false;
            bool fEndWord = false;

            if ((ich = sName.LastIndexOf('.')) != -1)
            sName = sName.Substring(0, ich);

            ich = 0;
            ichMax = sName.Length;

            while (ich < ichMax)
            {
            if (fEndWord)
                {
                // end the word and add it as atmtCur
                ATM atm = new ATM(atmtCur, sName.Substring(ichFirst, ich - ichFirst));
                platm.Add(atm);
                fEndWord = false;
                fCollecting = false;
                ichFirst = -1;
                }

            // ok, classify the character
            char ch = sName[ich];

            if (Char.IsWhiteSpace(ch) && fCollecting)
                {
                fEndWord = true;
                continue;	// this effectively pushes the token back on the stack
                }

            while(ich < ichMax && Char.IsWhiteSpace(sName[ich]))
                ich++;

            if (ich >= ichMax)
                break;

            ch = sName[ich];

            switch (ch)
                {
                case '(':
                case '[':
                case '{':
                    if (fCollecting)
                        {
                        fEndWord = true;
                        continue;
                        }
                    atmtCur = ATMT.OtherWord;
                    break;
                case ')':
                case ']':
                case '}':
                    if (fCollecting)
                        {
                        fEndWord = true;
                        continue;
                        }
                    atmtCur = ATMT.TitleWord;	// we don't handle nested parens, we always go back to the title
                    break;
                case '-':
                case '=':
                case ':':
                    if (fCollecting)
                        {
                        fEndWord = true;
                        continue;
                        }
                    // all collected words before this now become OtherWord
                    foreach (ATM atm in platm)
                        {
                        if (atm.Atmt == ATMT.TitleWord)
                            atm.Atmt = ATMT.OtherWord;
                        }
                    {
                    ATM atm = new ATM(ATMT.Separator, ch);
                    platm.Add(atm);
                    }
                    break;
                case '\'':
                case '"':
                default:
                    if (!fCollecting && (ch == '\'' || ch == '"' ))
                        break;	// skip if we're not collecting

                    // the rest start collecting
                    if (!fCollecting)
                        {
                        ichFirst = ich;
                        fCollecting = true;
                        }
                    break;
                }
            ich++;
            }
            if (fCollecting)
            {
            ATM atm = new ATM(atmtCur, sName.Substring(ichFirst, ich - ichFirst));
            platm.Add(atm);
            }

            // before we're done, make sure there are *some* title words
            if (CTitleWordsInPlatm(platm) == 0)
            {
            // work backwards and make title words until we hit a separator
            int i = platm.Count - 1;

            while (i >= 0)
                {
                // skip trailing seps
                while (i >= 0 && ((ATM)platm[i]).Atmt == ATMT.Separator)
                    i--;

                if (i < 0)
                    break;

                while (i >= 0 && ((ATM)platm[i]).Atmt != ATMT.Separator)
                    ((ATM)platm[i--]).Atmt = ATMT.TitleWord;

                break;
                }
            }
            return platm;
        }