static int GetComponents(IntPtr L) { try { ToLua.CheckArgsCount(L, 3); System.Uri obj = (System.Uri)ToLua.CheckObject <System.Uri>(L, 1); System.UriComponents arg0 = (System.UriComponents)ToLua.CheckObject(L, 2, typeof(System.UriComponents)); System.UriFormat arg1 = (System.UriFormat)ToLua.CheckObject(L, 3, typeof(System.UriFormat)); string o = obj.GetComponents(arg0, arg1); LuaDLL.lua_pushstring(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int Compare(IntPtr L) { try { ToLua.CheckArgsCount(L, 5); System.Uri arg0 = (System.Uri)ToLua.CheckObject <System.Uri>(L, 1); System.Uri arg1 = (System.Uri)ToLua.CheckObject <System.Uri>(L, 2); System.UriComponents arg2 = (System.UriComponents)ToLua.CheckObject(L, 3, typeof(System.UriComponents)); System.UriFormat arg3 = (System.UriFormat)ToLua.CheckObject(L, 4, typeof(System.UriFormat)); System.StringComparison arg4 = (System.StringComparison)ToLua.CheckObject(L, 5, typeof(System.StringComparison)); int o = System.Uri.Compare(arg0, arg1, arg2, arg3, arg4); LuaDLL.lua_pushinteger(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
private string Format(string s, System.UriFormat format) { if (s.Length == 0) { return(string.Empty); } switch (format) { case System.UriFormat.UriEscaped: return(System.Uri.EscapeString(s, false, true, true)); case System.UriFormat.Unescaped: return(System.Uri.Unescape(s, false)); case System.UriFormat.SafeUnescaped: s = System.Uri.Unescape(s, false); return(s); default: throw new ArgumentOutOfRangeException("format"); } }
/// <summary>Gets the components from a URI.</summary> /// <returns>A string that contains the components.</returns> /// <param name="uri">The URI to parse.</param> /// <param name="components">The <see cref="T:System.UriComponents" /> to retrieve from <paramref name="uri" />.</param> /// <param name="format">One of the <see cref="T:System.UriFormat" /> values that controls how special characters are escaped.</param> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="uriFormat" /> is invalid.- or -<paramref name="uriComponents" /> is not a combination of valid <see cref="T:System.UriComponents" /> values. </exception> /// <exception cref="T:System.InvalidOperationException"> /// <paramref name="uri" /> requires user-driven parsing- or -<paramref name="uri" /> is not an absolute URI. Relative URIs cannot be used with this method.</exception> protected internal virtual string GetComponents(System.Uri uri, System.UriComponents components, System.UriFormat format) { if (format < System.UriFormat.UriEscaped || format > System.UriFormat.SafeUnescaped) { throw new ArgumentOutOfRangeException("format"); } System.Text.RegularExpressions.Match match = System.UriParser.uri_regex.Match(uri.OriginalString); string value = this.scheme_name; int defaultPort = this.default_port; if (value == null || value == "*") { value = match.Groups[2].Value; defaultPort = System.Uri.GetDefaultPort(value); } else if (string.Compare(value, match.Groups[2].Value, true) != 0) { throw new SystemException("URI Parser: scheme mismatch: " + value + " vs. " + match.Groups[2].Value); } System.UriComponents uriComponents = components; switch (uriComponents) { case System.UriComponents.Scheme: return(value); case System.UriComponents.UserInfo: return(System.UriParser.ParseAuthority(match.Groups[4]).Groups[2].Value); default: { if (uriComponents == System.UriComponents.Path) { return(this.Format(this.IgnoreFirstCharIf(match.Groups[5].Value, '/'), format)); } if (uriComponents == System.UriComponents.Query) { return(this.Format(match.Groups[7].Value, format)); } if (uriComponents == System.UriComponents.Fragment) { return(this.Format(match.Groups[9].Value, format)); } if (uriComponents != System.UriComponents.StrongPort) { if (uriComponents == System.UriComponents.SerializationInfoString) { components = System.UriComponents.AbsoluteUri; } System.Text.RegularExpressions.Match match2 = System.UriParser.ParseAuthority(match.Groups[4]); StringBuilder stringBuilder = new StringBuilder(); if ((components & System.UriComponents.Scheme) != (System.UriComponents) 0) { stringBuilder.Append(value); stringBuilder.Append(System.Uri.GetSchemeDelimiter(value)); } if ((components & System.UriComponents.UserInfo) != (System.UriComponents) 0) { stringBuilder.Append(match2.Groups[1].Value); } if ((components & System.UriComponents.Host) != (System.UriComponents) 0) { stringBuilder.Append(match2.Groups[3].Value); } if ((components & System.UriComponents.StrongPort) != (System.UriComponents) 0) { System.Text.RegularExpressions.Group group = match2.Groups[4]; stringBuilder.Append((!group.Success) ? (":" + defaultPort) : group.Value); } if ((components & System.UriComponents.Port) != (System.UriComponents) 0) { string value2 = match2.Groups[5].Value; if (value2 != null && value2 != string.Empty && value2 != defaultPort.ToString()) { stringBuilder.Append(match2.Groups[4].Value); } } if ((components & System.UriComponents.Path) != (System.UriComponents) 0) { stringBuilder.Append(match.Groups[5]); } if ((components & System.UriComponents.Query) != (System.UriComponents) 0) { stringBuilder.Append(match.Groups[6]); } if ((components & System.UriComponents.Fragment) != (System.UriComponents) 0) { stringBuilder.Append(match.Groups[8]); } return(this.Format(stringBuilder.ToString(), format)); } System.Text.RegularExpressions.Group group2 = System.UriParser.ParseAuthority(match.Groups[4]).Groups[5]; return((!group2.Success) ? defaultPort.ToString() : group2.Value); } case System.UriComponents.Host: return(System.UriParser.ParseAuthority(match.Groups[4]).Groups[3].Value); case System.UriComponents.Port: { string value3 = System.UriParser.ParseAuthority(match.Groups[4]).Groups[5].Value; if (value3 != null && value3 != string.Empty && value3 != defaultPort.ToString()) { return(value3); } return(string.Empty); } } }