Exemplo n.º 1
0
        internal IList <Token> Tokenize(TextReader reader)
        {
            var           tokenizer = new StreamTokenizer(reader);
            IList <Token> tokens    = new List <Token>();

            tokenizer.Tokenize(tokens);     // Read directly all tokens
            return(tokens);
        }
Exemplo n.º 2
0
        /**
         *  Removes the HTML tags from the given String, inserting line breaks at
         *  appropriate places. Needs a little work.
         */

        public static String StripHTMLTags(String original)
        {
            //Strip the tags from the HTML description
            var skipping  = false;
            var writing   = false;
            var buffer    = new StringBuilder();
            var tokenizer = new StreamTokenizer();

            tokenizer.Settings.WordChars("<>");
            var tokens = new List <Token>();

            if (tokenizer.Tokenize(tokens))
            {
                var i = -1;
                while (i < tokens.Count)
                {
                    i++;
                    var token = tokens[i].StringValue;
                    if (token.Equals("<", StringComparison.InvariantCultureIgnoreCase))
                    {
                        skipping = true;
                        writing  = false;
                        continue;
                    }
                    if (token.Equals(">", StringComparison.InvariantCultureIgnoreCase))
                    {
                        skipping = false;
                        continue;
                    }
                    if (skipping)
                    {
                        continue;
                    }

                    if (token.Trim().Length == 0)
                    {
                        continue;
                    }
                    if (!writing)
                    {
                        buffer.Append("\n");
                    }
                    writing = true;
                    buffer.Append(token.Trim());
                }
            }
            return(buffer.ToString());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Converts a Well-known Text representation to a <c>Geometry</c>.
        /// </summary>
        /// <param name="reader">
        /// A Reader which will return a "Geometry Tagged Text"
        /// string (see the OpenGIS Simple Features Specification).
        /// </param>
        /// <returns>A <c>Geometry</c> read from <c>reader</c>.
        /// </returns>
        public IGeometry Read(TextReader reader)
        {
            StreamTokenizer tokenizer = new StreamTokenizer(reader);
            ArrayList       tokens    = new ArrayList();

            tokenizer.Tokenize(tokens);     // Read directly all tokens
            index = 0;                      // Reset pointer to start of tokens
            try
            {
                return(ReadGeometryTaggedText(tokens));
            }
            catch (IOException e)
            {
                throw new ParseException(e.ToString());
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Converts a Well-known Text representation to a <c>Geometry</c>.
        /// </summary>
        /// <param name="reader">
        /// A Reader which will return a "Geometry Tagged Text"
        /// string (see the OpenGIS Simple Features Specification).
        /// </param>
        /// <returns>A <c>Geometry</c> read from <c>reader</c>.
        /// </returns>
        public IGeometryRef Read(TextReader reader)
        {
            StreamTokenizer tokenizer = new StreamTokenizer(reader);
            var             tokens    = new List <Token>();

            tokenizer.Tokenize(tokens);     // Read directly all tokens
            index = 0;                      // Reset pointer to start of tokens

            try
            {
                var geom = ReadGeometryTaggedText(tokens);
                return(new GeoAPIGeometryRef(geom));
            }
            catch (IOException e)
            {
                throw new GeoAPI.IO.ParseException(e.ToString());
            }
        }
        /// <summary>
        /// This is a simple condition matching designed for only the configuration
        /// and platform conditions.
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="platform"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        public static bool IsConditionMatched(string configuration,
                                              string platform, string condition)
        {
            // Format: '$(Configuration)|$(Platform)' == 'Debug|x86'
            //         '$(Configuration)|$(Platform)' == 'Release|AnyCPU'
            bool isMatched = false;

            if (String.IsNullOrEmpty(condition) && String.IsNullOrEmpty(configuration))
            {
                return(isMatched);
            }

            StreamTokenizer tokenizer = new StreamTokenizer(condition);
            List <Token>    tokens    = new List <Token>();

            if (!tokenizer.Tokenize(tokens))
            {
                return(isMatched);
            }

            String        symbols      = String.Empty;
            List <string> quotedValues = new List <string>();

            foreach (Token token in tokens)
            {
                switch (token.Type)
                {
                case TokenType.Char:
                    if (Char.IsSymbol(token.StringValue, 0))
                    {
                        symbols += token.StringValue;
                    }
                    break;

                case TokenType.Quote:
                    // Format: '$(Configuration)', we remove the single quotes...
                    quotedValues.Add(token.StringValue.Trim('\''));
                    break;
                }
            }

            symbols = symbols.Trim();
            if (!symbols.Equals("==", StringComparison.Ordinal) ||
                quotedValues.Count != 2)
            {
                return(isMatched);
            }

            IDictionary <string, string> expressionMap = ExtractConditionMap(
                quotedValues[0], quotedValues[1]);

            if (expressionMap == null || expressionMap.Count == 0)
            {
                return(isMatched);
            }
            string configurationValue;

            if (!expressionMap.TryGetValue("Configuration", out configurationValue) ||
                String.IsNullOrEmpty(configurationValue))
            {
                return(isMatched);
            }
            if (!configuration.Equals(configurationValue,
                                      StringComparison.OrdinalIgnoreCase))
            {
                return(isMatched);
            }
            if (!String.IsNullOrEmpty(platform) && expressionMap.Count > 1)
            {
                string platformValue;
                if (!expressionMap.TryGetValue("Platform", out platformValue) ||
                    String.IsNullOrEmpty(platformValue))
                {
                    isMatched = false;
                }
                else if (platform.Equals("AnyCPU", StringComparison.OrdinalIgnoreCase) ||
                         platform.Equals("Any CPU", StringComparison.OrdinalIgnoreCase))
                {
                    platform  = platform.Replace(" ", "");
                    isMatched = platform.Equals(platformValue.Replace(" ", ""),
                                                StringComparison.OrdinalIgnoreCase);
                }
                else
                {
                    isMatched = platform.Equals(platformValue, StringComparison.OrdinalIgnoreCase);
                }
            }

            return(isMatched);
        }