CheckSchemeName() public static method

public static CheckSchemeName ( string schemeName ) : bool
schemeName string
return bool
Example #1
0
        //
        // Static Registration methods
        //
        //
        // Registers a custom Uri parser based on a scheme string
        //
        public static void Register(UriParser uriParser, string schemeName, int defaultPort)
        {
            if (uriParser == null)
            {
                throw new ArgumentNullException(nameof(uriParser));
            }

            if (schemeName == null)
            {
                throw new ArgumentNullException(nameof(schemeName));
            }

            if (schemeName.Length == 1)
            {
                throw new ArgumentOutOfRangeException(nameof(schemeName));
            }

            if (!Uri.CheckSchemeName(schemeName))
            {
                throw new ArgumentOutOfRangeException(nameof(schemeName));
            }

            if ((defaultPort >= 0xFFFF || defaultPort < 0) && defaultPort != -1)
            {
                throw new ArgumentOutOfRangeException(nameof(defaultPort));
            }

            schemeName = schemeName.ToLowerInvariant();
            FetchSyntax(uriParser, schemeName, defaultPort);
        }
Example #2
0
        //
        // Static Registration methods
        //
        //
        // Registers a custom Uri parser based on a scheme string
        //
        public static void Register(UriParser uriParser, string schemeName, int defaultPort)
        {
            ExceptionHelper.InfrastructurePermission.Demand();

            if (uriParser == null)
            {
                throw new ArgumentNullException("uriParser");
            }

            if (schemeName == null)
            {
                throw new ArgumentNullException("schemeName");
            }

            if (schemeName.Length == 1)
            {
                throw new ArgumentOutOfRangeException("schemeName");
            }

            if (!Uri.CheckSchemeName(schemeName))
            {
                throw new ArgumentOutOfRangeException("schemeName");
            }

            if ((defaultPort >= 0xFFFF || defaultPort < 0) && defaultPort != -1)
            {
                throw new ArgumentOutOfRangeException("defaultPort");
            }

            schemeName = schemeName.ToLower(CultureInfo.InvariantCulture);
            FetchSyntax(uriParser, schemeName, defaultPort);
        }
Example #3
0
 public UriBuilder(String scheme, String host, int port, String path,
                   String extraValue)
 {
     scheme = scheme.ToLower();
     if (!Uri.CheckSchemeName(scheme))
     {
         throw new ArgumentException
                   (S._("Arg_UriScheme"));
     }
     this.scheme = scheme;
     this.host   = host;
     if (port < 0 || (port < -1 && scheme == "file"))
     {
         throw new ArgumentOutOfRangeException("port");
     }
     this.port = port;
     this.path = path;
     if (extraValue[0] == '?')
     {
         this.query = extraValue;
     }
     else if (extraValue[0] == '#')
     {
         this.fragment = extraValue;
     }
     else if (extraValue != null && extraValue.Length != 0)
     {
         throw new ArgumentException
                   (S._("Exception_Argument"), "extraValue");
     }
     this.username = "";
     this.password = "";
 }
Example #4
0
        //
        // Is a Uri scheme known to System.Uri?
        //
        public static bool IsKnownScheme(string schemeName)
        {
            ArgumentNullException.ThrowIfNull(schemeName);

            if (!Uri.CheckSchemeName(schemeName))
            {
                throw new ArgumentOutOfRangeException(nameof(schemeName));
            }

            UriParser?syntax = UriParser.GetSyntax(schemeName.ToLowerInvariant());

            return(syntax != null && syntax.NotAny(UriSyntaxFlags.V1_UnknownUri));
        }
Example #5
0
        //
        // Is a Uri scheme known to System.Uri?
        //
        public static bool IsKnownScheme(string schemeName)
        {
            if (schemeName == null)
            {
                throw new ArgumentNullException("schemeName");
            }

            if (!Uri.CheckSchemeName(schemeName))
            {
                throw new ArgumentOutOfRangeException("schemeName");
            }

            UriParser syntax = UriParser.GetSyntax(schemeName.ToLower(CultureInfo.InvariantCulture));

            return(syntax != null && syntax.NotAny(UriSyntaxFlags.V1_UnknownUri));
        }
Example #6
0
        // 3.1) scheme      = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
        private static bool ParseScheme(ParserState state)
        {
            string part = state.remaining;

            StringBuilder sb = new StringBuilder();

            sb.Append(part [0]);

            int index;

            for (index = 1; index < part.Length; index++)
            {
                char ch = part [index];
                if (ch != '.' && ch != '-' && ch != '+' && !IsAlpha(ch) && !Char.IsDigit(ch))
                {
                    break;
                }

                sb.Append(ch);
            }

            if (index == 0 || index >= part.Length)
            {
                if (state.kind == UriKind.Absolute)
                {
                    state.error = "Invalid URI: The format of the URI could not be determined.";
                    return(false);
                }

                state.elements.isAbsoluteUri = false;
                return(state.remaining.Length > 0);
            }

            if (part [index] != ':')
            {
                if (state.kind == UriKind.Absolute)
                {
                    state.error = "Invalid URI: The URI scheme is not valid.";
                    return(false);
                }

                state.elements.isAbsoluteUri = false;
                return(state.remaining.Length > 0);
            }

            state.elements.scheme = sb.ToString().ToLowerInvariant();
            state.remaining       = part.Substring(index);

            // Check scheme name characters as specified in RFC2396.
            // Note: different checks in 1.x and 2.0
            if (!Uri.CheckSchemeName(state.elements.scheme))
            {
                if (state.kind == UriKind.Absolute)
                {
                    state.error = "Invalid URI: The URI scheme is not valid.";
                    return(false);
                }

                state.elements.isAbsoluteUri = false;
                return(state.remaining.Length > 0);
            }

            return(ParseDelimiter(state));
        }
Example #7
0
        // 3.1) scheme      = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
        private static bool ParseScheme(ParserState state)
        {
            string part = state.remaining;

            StringBuilder sb = new StringBuilder();

            sb.Append(part [0]);

            int index;

            for (index = 1; index < part.Length; index++)
            {
                char ch = part [index];
                if (ch != '.' && ch != '-' && ch != '+' && !IsAlpha(ch) && !Char.IsDigit(ch))
                {
                    break;
                }

                sb.Append(ch);
            }

            if (index == 0 || index >= part.Length)
            {
                if (state.kind == UriKind.Absolute)
                {
                    state.error = "Invalid URI: The format of the URI could not be determined.";
                    return(false);
                }

                state.elements.isAbsoluteUri = false;
                return(state.remaining.Length > 0);
            }

            if (part [index] != ':')
            {
                if (state.kind == UriKind.Absolute)
                {
                    state.error = "Invalid URI: The URI scheme is not valid.";
                    return(false);
                }

                state.elements.isAbsoluteUri = false;
                return(state.remaining.Length > 0);
            }

            state.elements.scheme = sb.ToString().ToLowerInvariant();
            state.remaining       = part.Substring(index);

            // Check scheme name characters as specified in RFC2396.
            // Note: different checks in 1.x and 2.0
            if (!Uri.CheckSchemeName(state.elements.scheme))
            {
                if (state.kind == UriKind.Absolute)
                {
                    state.error = "Invalid URI: The URI scheme is not valid.";
                    return(false);
                }

                state.elements.isAbsoluteUri = false;
                return(state.remaining.Length > 0);
            }

            if (state.elements.scheme == Uri.UriSchemeFile)
            {
                // under Windows all file:// URI are considered UNC, which is not the case other MacOS (e.g. Silverlight)
#if BOOTSTRAP_BASIC
                state.elements.isUnc = (Path.DirectorySeparatorChar == '\\');
#else
                state.elements.isUnc = Environment.IsRunningOnWindows;
#endif
            }

            return(ParseDelimiter(state));
        }