Exemplo n.º 1
0
        /// <summary>
        /// v5 > osigurava da URL pocne pravilnom shemom - ako je shema unknown onda nista
        /// </summary>
        /// <param name="url"></param>
        /// <param name="shema"></param>
        /// <returns></returns>
        public static string validateUrlShema(this string url, urlShema shema)
        {
            if (shema == urlShema.unknown)
            {
                shema = urlShema.http;
            }
            if (shema == urlShema.none)
            {
                shema = urlShema.http;
            }
            string sufix = "";

            if (shema != urlShema.none)
            {
                bool hasShema = url.Contains(urlShemaSufix);
                if (!url.StartsWith(shema.ToString(), StringComparison.CurrentCultureIgnoreCase))
                {
                    if (hasShema)
                    {
                        sufix = url.Substring(url.IndexOf(urlShemaSufix) + urlShemaSufix.Length);
                    }
                    sufix = shema.ToString() + urlShemaSufix;
                }
            }
            return(sufix.add(url, "/"));
        }
Exemplo n.º 2
0
        //  public static Regex _getDomain = new Regex()

        /// <summary>
        /// Vrši standardizaciju URL-a
        /// (staro rešenje)
        /// </summary>
        /// <param name="url"></param>
        /// <param name="addWww"></param>
        /// <param name="addLastBackSlash"></param>
        /// <returns></returns>
        public static string getStandardizedUrl(string url, urlShema targetShema)
        {
            string output = url.validateUrlShema(targetShema); // url.validateUrlShema(targetShema);
            Uri    res    = null;

            Uri.TryCreate(url, UriKind.Absolute, out res);

            if (res != null)
            {
                return(res.AbsoluteUri);
            }
            else
            {
                return("");
            }

            /*
             * UriBuilder ub = new UriBuilder(url);
             * output = ub.Uri.AbsoluteUri;
             *
             */

            /*
             * url.removeStartsWith("//");
             * url.removeEndsWith("//");
             *
             *
             *
             *
             *
             *
             * output = output.Replace("http://", "");
             *
             * output = output.Replace("//", "/");
             *
             * if (addWww) output = output.Replace("www.", "");
             *
             * String prefix = "http://";
             * if (addWww) prefix = prefix + "www.";
             *
             * output = prefix + output;
             *
             *
             *
             * if (addLastBackSlash)
             * {
             *  if (!(output[output.Length - 1] == Convert.ToChar("/")))
             *  {
             *      output += "/";
             *  }
             * }*/

            return(output);
        }