Exemplo n.º 1
0
        /// <summary>
        /// Detects keywords in the specified string and returns a list of them.  Stops
        /// scanning when the first non-keyword is read.
        /// </summary>
        /// <param name="text">The text to scan.</param>
        /// <returns>A list of keywords.</returns>
        internal static KeywordResult GetKeywords(string text)
        {
            string        buf = "";
            KeywordResult ret = new KeywordResult();

            for (int i = 0; i < text.Length; i++)
            {
                if ((text[i] == ' ' || text[i] == '\t' || text[i] == '\n' || text[i] == '\r') && buf.Trim().Length > 0)
                {
                    buf = buf.Trim();
                    // End of building up the buffer.
                    if (Keywords.GetKeyword(buf) != "")
                    {
                        ret.Keywords.Add(buf);
                        ret.DeclIndex = i;
                        buf           = "";
                    }
                    else
                    {
                        // No more keywords.  It's not possible
                        // to have a partial keyword here since
                        // the last character was whitespace.
                        ret.PossibleKeyword = false;
                        return(ret);
                    }
                }
                else
                {
                    buf += text[i];
                }
            }
            if (buf.Length > 0)
            {
                if (Keywords.GetKeyword(buf) != "")
                {
                    ret.Keywords.Add(buf);
                    ret.DeclIndex       = text.Length;
                    ret.PossibleKeyword = false;
                    buf = "";
                    return(ret);
                }
                else
                {
                    // Check to see whether it's a partial keyword.
                    ret.PossibleKeyword = Keywords.IsPartialKeyword(buf);
                    return(ret);
                }
            }
            else
            {
                ret.PossibleKeyword = false;
                return(ret);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Detects keywords in the specified string and returns a list of them.  Stops
 /// scanning when the first non-keyword is read.
 /// </summary>
 /// <param name="text">The text to scan.</param>
 /// <returns>A list of keywords.</returns>
 internal static KeywordResult GetKeywords(string text)
 {
     string buf = "";
     KeywordResult ret = new KeywordResult();
     for (int i = 0; i < text.Length; i++)
     {
         if ((text[i] == ' ' || text[i] == '\t' || text[i] == '\n' || text[i] == '\r') && buf.Trim().Length > 0)
         {
             buf = buf.Trim();
             // End of building up the buffer.
             if (Keywords.GetKeyword(buf) != "")
             {
                 ret.Keywords.Add(buf);
                 ret.DeclIndex = i;
                 buf = "";
             }
             else
             {
                 // No more keywords.  It's not possible
                 // to have a partial keyword here since
                 // the last character was whitespace.
                 ret.PossibleKeyword = false;
                 return ret;
             }
         }
         else
             buf += text[i];
     }
     if (buf.Length > 0)
     {
         if (Keywords.GetKeyword(buf) != "")
         {
             ret.Keywords.Add(buf);
             ret.DeclIndex = text.Length;
             ret.PossibleKeyword = false;
             buf = "";
             return ret;
         }
         else
         {
             // Check to see whether it's a partial keyword.
             ret.PossibleKeyword = Keywords.IsPartialKeyword(buf);
             return ret;
         }
     }
     else
     {
         ret.PossibleKeyword = false;
         return ret;
     }
 }