#nullable enable using System; using System.Collections.Generic; namespace UVC.Data { /// /// URL ÁÖ¼Ò¸¦ Ű-°ª ½ÖÀ¸·Î ÀúÀåÇÏ°í °ü¸®Çϴ Ŭ·¡½ºÀÔ´Ï´Ù. /// public static class URLList { /// /// URLÀ» ÀúÀåÇÏ´Â ³»ºÎ Dictionary Ä÷º¼Ç /// private static Dictionary urls = new Dictionary(); /// /// ÁöÁ¤µÈ Ű¿Í URLÀ» Ä÷º¼Ç¿¡ Ãß°¡ÇÕ´Ï´Ù. ۰¡ ÀÌ¹Ì Á¸ÀçÇϸé URLÀ» ¾÷µ¥ÀÌÆ®ÇÕ´Ï´Ù. /// /// URL¿¡ Á¢±ÙÇϱâ À§ÇÑ °íÀ¯ Ű /// ÀúÀåÇÒ URL ¹®ÀÚ¿­ /// /// /// URLList.Add("google", "https://www.google.com"); /// URLList.Add("naver", "https://www.naver.com"); /// /// // ±âÁ¸ ŰÀÇ URL ¾÷µ¥ÀÌÆ® /// URLList.Add("google", "https://www.google.co.kr"); /// /// public static void Add(string key, string url) { if (!urls.ContainsKey(key)) { urls.Add(key, url); } else { urls[key] = url; // Update existing URL } } /// /// ÁöÁ¤µÈ Ű¿¡ ÇØ´çÇÏ´Â URLÀ» Ä÷º¼Ç¿¡¼­ Á¦°ÅÇÕ´Ï´Ù. /// /// Á¦°ÅÇÒ URLÀÇ Å° /// /// /// URLList.Add("temp", "https://www.temp.com"); /// /// // URL Á¦°Å /// URLList.Remove("temp"); /// /// // Á¸ÀçÇÏÁö ¾Ê´Â Ű Á¦°Å ½Ãµµ(¾Æ¹« Àϵµ ¹ß»ýÇÏÁö ¾ÊÀ½) /// URLList.Remove("nonexistent"); /// /// public static void Remove(string key) { if (urls.ContainsKey(key)) { urls.Remove(key); } } /// /// ÁöÁ¤µÈ ۰¡ Ä÷º¼Ç¿¡ Á¸ÀçÇÏ´ÂÁö È®ÀÎÇÕ´Ï´Ù. /// /// È®ÀÎÇÒ Å° /// ۰¡ Á¸ÀçÇϸé true, ±×·¸Áö ¾ÊÀ¸¸é false /// /// /// URLList.Add("github", "https://github.com"); /// /// // Ű Á¸Àç ¿©ºÎ È®ÀÎ /// if(URLList.ContainsKey("github")) /// { /// Console.WriteLine("GitHub URLÀÌ Á¸ÀçÇÕ´Ï´Ù."); /// } /// /// if(!URLList.ContainsKey("gitlab")) /// { /// Console.WriteLine("GitLab URLÀÌ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù."); /// } /// /// public static bool ContainsKey(string key) { return urls.ContainsKey(key); } /// /// ÁöÁ¤µÈ Ű¿¡ ÇØ´çÇÏ´Â URLÀ» ¹ÝȯÇÕ´Ï´Ù. /// /// °¡Á®¿Ã URLÀÇ Å° /// Ű¿¡ ÇØ´çÇÏ´Â URL ¶Ç´Â ۰¡ Á¸ÀçÇÏÁö ¾ÊÀ» °æ¿ì null /// /// /// URLList.Add("youtube", "https://www.youtube.com"); /// /// // URL °¡Á®¿À±â /// string youtubeUrl = URLList.Get("youtube"); /// if (youtubeUrl != null) /// { /// Console.WriteLine($"YouTube URL: {youtubeUrl}"); /// } /// /// // Á¸ÀçÇÏÁö ¾Ê´Â Ű·Î URL °¡Á®¿À±â /// string nullUrl = URLList.Get("nonexistent"); /// if (nullUrl == null) /// { /// Console.WriteLine("URLÀÌ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù."); /// } /// /// public static string? Get(string key) { if (urls.TryGetValue(key, out string url)) { return url; } return null; // or throw an exception if preferred } /// /// URL¿¡¼­ µµ¸ÞÀÎ ºÎºÐÀ» ÃßÃâÇÕ´Ï´Ù. /// /// µµ¸ÞÀÎÀ» ÃßÃâÇÒ URL /// ÃßÃâµÈ µµ¸ÞÀÎ ¶Ç´Â ÆÄ½Ì ½ÇÆÐ ½Ã null /// /// /// string domain = URLList.ExtractDomain("https://www.example.com/path/page.html"); /// Console.WriteLine(domain); // Ãâ·Â: www.example.com /// /// public static string? ExtractDomain(string url) { if (string.IsNullOrEmpty(url)) return null; try { Uri uri = new Uri(url); return uri.Host; } catch (UriFormatException) { return null; } } } }