From 9e7b30ef23c6ea8c0baa81b741be1905316ac5c8 Mon Sep 17 00:00:00 2001 From: Elivo Date: Mon, 7 Jul 2025 16:24:43 +0800 Subject: [PATCH] =?UTF-8?q?NetworkUtility=EF=BC=9A=E5=A2=9E=E5=8A=A0=20Uri?= =?UTF-8?q?.Segmental=20=E6=89=A9=E5=B1=95=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Apewer/NetworkUtility.cs | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/Apewer/NetworkUtility.cs b/Apewer/NetworkUtility.cs index 5832e55..8478440 100644 --- a/Apewer/NetworkUtility.cs +++ b/Apewer/NetworkUtility.cs @@ -1,19 +1,16 @@ using Apewer.Network; using System; -using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Net; using System.Net.NetworkInformation; using System.Net.Sockets; -using System.Runtime.InteropServices; -using System.Text; namespace Apewer { /// - public class NetworkUtility + public static class NetworkUtility { #region UDP @@ -567,6 +564,33 @@ namespace Apewer #endregion + #region URI + + /// 获取路径片段。 + /// URI + /// Segmentals 的索引。索引 0 的位置为空(HOST 部分)。 + /// 解码 URL。 + public static string Segmental(this Uri uri, int index, bool decode = false) + { + if (uri == null) return null; + return Segmental(uri.Segments, index, decode); + } + + /// 获取路径片段。 + /// 片段集合。 + /// Segmentals 的索引。索引 0 的位置为空(HOST 部分)。 + /// 解码 URL。 + internal static string Segmental(string[] segmentals, int index, bool decode = false) + { + if (segmentals == null || segmentals.Length < 1) return null; + if (index < 1 || index >= segmentals.Length) return null; + var segmental = segmentals[index]; + if (decode) segmental = TextUtility.DecodeUrl(segmental); + return segmental; + } + + #endregion + } }