Ejemplo n.º 1
0
        /// <summary>
        /// Construct an instance of the Text URI data type.
        /// </summary>
        /// <param name="uriPath">Either the LocalPath or AbsolutePath from a "data:" URI (that does not contain "base64,"</param>
        /// <param name="otherParameters">Returns any additional, unrecognized URI parameters.</param>
        public Text(string uriPath, out List <UriParameter> otherParameters)
        {
            if (string.IsNullOrWhiteSpace(uriPath))
            {
                throw new ArgumentNullException(nameof(uriPath));
            }
            if (uriPath.NonQuotedIndexOf(SEPARATOR) < 0)
            {
                throw new ArgumentException(ParsingHelper.UriPathNotWellFormedMessage("text data"), nameof(uriPath));
            }

            var pair = uriPath.NonQuotedSplitOnFirst(SEPARATOR);

            Data = pair.Item2;
            if (string.IsNullOrWhiteSpace(pair.Item1) || pair.Item1.NonQuotedIndexOf(';') < 0)
            {
                _mediaType      = null;
                _charSet        = null;
                otherParameters = null;
                return;
            }
            otherParameters = new List <UriParameter>();
            foreach (string s in pair.Item1.NonQuotedSplit(';'))
            {
                UriParameter p = new UriParameter(s);
                if (string.IsNullOrWhiteSpace(p.Value))
                {
                    MediaType = p.Name;
                }
                else if (p.Is("charset"))
                {
                    CharacterSet = p.Value;
                }
                else
                {
                    otherParameters.Add(p);
                }
            }
            if (otherParameters.Count < 1)
            {
                otherParameters = null;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Construct an instance of the GeoLoc URI data type
        /// </summary>
        /// <param name="uriPath">Either the LocalPath or AbsolutePath from a "geo:" URI</param>
        /// <param name="otherParameters">Returns any additional, unrecognized URI parameters</param>
        public GeoLoc(string uriPath, out List <UriParameter> otherParameters)
        {
            if (string.IsNullOrWhiteSpace(uriPath))
            {
                throw new ArgumentNullException(nameof(uriPath));
            }

            List <string> split1 = uriPath.NonQuotedSplit(';', StringSplitOptions.RemoveEmptyEntries, true);

            if (!split1[0].Contains(","))
            {
                throw new ArgumentException(ParsingHelper.UriPathNotWellFormedMessage("geo-loc"), nameof(uriPath));
            }

            List <string> coords = split1[0].NonQuotedSplit(',', false);

            if (coords.Count > 1)
            {
                if (float.TryParse(coords[0], out float a))
                {
                    Latitude = a;
                }
                else
                {
                    throw new ArgumentException(ParsingHelper.UriPathEncodingError(nameof(Latitude), "float"), nameof(uriPath));
                }
                if (float.TryParse(coords[1], out float b))
                {
                    Longitude = b;
                }
                else
                {
                    throw new ArgumentException(ParsingHelper.UriPathEncodingError(nameof(Longitude), "float"), nameof(uriPath));
                }
            }
            if (coords.Count > 2)
            {
                if (float.TryParse(coords[2], out float c))
                {
                    Altitude = c;
                }
                else
                {
                    throw new ArgumentException(ParsingHelper.UriPathEncodingError(nameof(Altitude), "float"), nameof(uriPath));
                }
            }
            else
            {
                Altitude = null;
            }

            Uncertainty = null;

            if (split1.Count > 1)
            {
                otherParameters = new List <UriParameter>();
                for (int i = 1; i < split1.Count; i++)
                {
                    UriParameter param;
                    try {
                        param = new UriParameter(split1[i]);
                        if (param.Is("crs"))
                        {
                            CrsLabel = param.Value;
                        }
                        else if (param.Is("u"))
                        {
                            if (float.TryParse(param.Value, out float u))
                            {
                                Uncertainty = u;
                            }
                            else
                            {
                                Uncertainty = null;
                            }
                        }
                        else
                        {
                            otherParameters.Add(param);
                        }
                    } catch { }
                }
                if (otherParameters.Count < 1)
                {
                    otherParameters = null;
                }
            }
            else
            {
                otherParameters = null;
            }
        }