Example #1
0
        bool doScan(ParseStream oStream)
        {
            if (oStream.empty() || oStream.getData()[0] != '#')
                return false;

            oStream.consume(1);

            // read the characters, it is ok if they are empty
            int n = scanIFragmentChars(oStream.getData());
            oStream.consume(n);

            return true;
        }
Example #2
0
        /// <summary>
        /// Static method to build the correct AuthorityPath obj from a String
        /// </summary>
        /// <param name="sPath"></param>
        /// <returns></returns>
        public static AuthorityPath buildAuthorityPath(string sPath)
        {
            ParseStream oStream = new ParseStream(sPath);
            AuthorityPath oPath = scanAuthority(oStream);

            // only return the path if the entire stream was consumed
            return (oStream.getData().Length == 0) ? oPath : null;
        }
Example #3
0
        /// <summary>
        /// Parses the input stream into the obj
        /// </summary>
        /// <param name="oStream">The input stream to scan from</param>
        /// <returns>True if part of the Stream was consumed into the obj</returns>
        bool doScan(ParseStream oStream)
        {
            if (oStream.getData()[0] == XRI.PDELIM)
            {
                this.mbPersistant = true;
                oStream.consume(1);
            }
            else if (oStream.getData()[0] == XRI.RDELIM)
            {
                oStream.consume(1);
            }
            else if (!mbAllowImpliedDelimiter)
            {
                return false;
            }

            // if there is a cross-reference, it has priority in scanning
            XRef oXRef = new XRef();
            if (oXRef.scan(oStream))
            {
                moXRef = oXRef;
                return true;
            }

            // read the characters, it is ok if they are empty
            int n = scanPChars(oStream.getData());
            oStream.consume(n);

            return true;
        }
Example #4
0
        /// <summary>
        /// Parses the input stream into the obj
        /// </summary>
        /// <param name="oStream">The input stream to scan from</param>
        /// <returns>True if part of the Stream was consumed into the obj</returns>
        bool doScan(ParseStream oStream)
        {
            // make sure we start with a slash
            if (oStream.empty() || (oStream.getData()[0] != '/'))
            {
                return false;
            }

            // consume the slash
            oStream.consume(1);

            // now scan the XRI segments as we are supposed to
            base.scanXRISegments(oStream);

            // return true no matter what, we got the slash
            return true;
        }
Example #5
0
        /// <summary>
        /// Scans the Stream for a valid IRI-Authority
        /// </summary>
        /// <param name="oStream"></param>
        /// <returns></returns>
        bool doScan(ParseStream oStream)
        {
            bool bVal = false;
            int n = scanChars(oStream.getData());
            string sData = oStream.getData().Substring(0, n);
            try
            {
                moURI = new Uri("http", sData, null, null, null);
                String sHost = moURI.Host;
                if ((sHost != null) && (sHost.Length > 0))
                {
                    char cFirst = sHost[0];
                    bool bCheckIP = char.IsDigit(cFirst) ||
                        (cFirst == '[');
                    bVal = bCheckIP ? verifyIP(sHost) : verifyDNS(sHost);
                }
            }
            catch (UriFormatException e)
            { }

            // consume and return true if valid
            if (bVal)
            {
                oStream.consume(n);
                return true;
            }

            return false;
        }
Example #6
0
        /// <summary>
        /// Returns a non-null String if an IRI is consumed from the stream
        /// </summary>
        /// <param name="oStream"></param>
        /// <returns></returns>
        static string scanIRI(ParseStream oStream)
        {
            int n = scanIRIChars(oStream.getData());
            string data = oStream.getData().Substring(0, n);

            try
            {
                // try parsing to check validity, Java's URI parser may not be IRI compliant so
                // this is a TODO
                Uri u = new Uri(data);
                if (!u.IsAbsoluteUri)
                {
                    return null;
                }
            }
            catch (UriFormatException)
            {
                return null;
            }

            oStream.consume(n);
            return data;
        }
Example #7
0
        bool doScan(ParseStream oStream)
        {
            if (oStream.empty())
            {
                return false;
            }

            if (oStream.getData()[0] != '(')
            {
                return false;
            }

            ParseStream oTempStream = oStream.begin();
            oTempStream.consume(1);

            String sIRI = null;
            // make sure we have a valid XRI reference
            XRIReference oRef = scanXRIReference(oTempStream);
            if (oRef == null || oTempStream.empty() || (oTempStream.getData()[0] != ')'))
            {
                // if we got a reference, but the resulting temp stream is empty or does not begin with ')'
                // it got parsed wrongly (happens if the XRef is an IRI). Retry parsing with an IRI
                if (oRef != null)
                {
                    oTempStream = oStream.begin();
                    oTempStream.consume(1);
                }
                // if there is no XRI Reference, see if it is an IRI
                sIRI = scanIRI(oTempStream);
                if (sIRI == null)
                {
                    return false;
                }
            }

            // make sure we have the trailing ')'
            if (oTempStream.empty() || (oTempStream.getData()[0] != ')'))
            {
                return false;
            }

            // at this point, complete consumption and return true
            oTempStream.consume(1);
            oStream.end(oTempStream);
            moXRIRef = oRef;
            msIRI = sIRI;

            return true;
        }
Example #8
0
        /// <summary>
        /// Parses the input stream into the GCS Character String
        /// </summary>
        /// <param name="oParseStream">The input stream to scan from</param>
        /// <returns>True if part of the Stream was consumed</returns>
        private bool scanGCSChar(ParseStream oParseStream)
        {
            if (oParseStream.empty())
            {
                return false;
            }

            switch (oParseStream.getData()[0])
            {
                case '+':
                case '=':
                case '@':
                case '$':
                case '!':
                    {
                        // this way provides a clean copy, whereas substring does not
                        msGCSRoot = char.ToString(oParseStream.getData()[0]);
                        oParseStream.consume(1);
                        return true;
                    }
            }

            return false;
        }
Example #9
0
        /// <summary>
        /// Parses the set value.
        /// </summary>
        /// <remarks>
        /// Throws XRIParseException if entire value could not be parsed into the
        /// obj
        /// </remarks>
        protected void parse()
        {
            string value = msValue;

            // only do work if the value isn't already parsed
            if (!mbParsed)
            {
                ParseStream oStream = new ParseStream(msValue);

                if (scan(oStream))
                {
                    // Did we consume the entire string?
                    mbParseResult = oStream.getData().Length == 0;
                }

                // Set to true even if we fail, no need to fail over and over again.
                mbParsed = true;
            }

            // throw an exception if things failed
            if (!mbParseResult)
            {
                throw new XRIParseException(
                        "Not a valid " + this.GetType().Name +
                        " class: \"" + value + "\"");
            }
        }
Example #10
0
        /// <summary>
        /// Parses the input stream into the obj
        /// </summary>
        /// <param name="oXRISegStream">The input stream to scan from</param>
        /// <returns>True if part of the Stream was consumed into the obj</returns>
        bool doScan(ParseStream oXRISegStream)
        {
            moSubSegments = new List<XRISubSegment>();
            bool bAllowImpliedDelimiter = mbAllowImpliedDelimiter;
            bool bAllowReassignable = mbAllowReassignable;

            // loop through the stream, but don't consume the real string unless
            // we are successful
            while (!oXRISegStream.empty())
            {
                // determine if we have a delimiter for the next subsegment
                char c = oXRISegStream.getData()[0];

                // break out if the first character has to be persistent and isn't
                if ((!bAllowReassignable) && (c != XRI.PDELIM))
                {
                    break;
                }

                // check if we have a valid non-null subsegment
                XRISubSegment oSubSegment = new XRISubSegment(bAllowImpliedDelimiter, mbAllowColon);
                if (oSubSegment.scan(oXRISegStream))
                {
                    // if we had a valid sub-segment, consume it and add it to the list
                    moSubSegments.Add(oSubSegment);
                }
                else
                {
                    break;
                }

                bAllowImpliedDelimiter = false;
                bAllowReassignable = true;
            }

            // if we have subsegments, we are good.  Otherwise, it is an error
            if (moSubSegments.Count > 0)
            {
                return true;
            }

            moSubSegments = null;
            return false;
        }