当前位置: 首页>>代码示例>>C#>>正文


C# IdnMapping.GetUnicode方法代码示例

本文整理汇总了C#中System.Globalization.IdnMapping.GetUnicode方法的典型用法代码示例。如果您正苦于以下问题:C# IdnMapping.GetUnicode方法的具体用法?C# IdnMapping.GetUnicode怎么用?C# IdnMapping.GetUnicode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Globalization.IdnMapping的用法示例。


在下文中一共展示了IdnMapping.GetUnicode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetUnicodeInvalid

		void GetUnicodeInvalid (IdnMapping m, string s, object label)
		{
			try {
				m.GetUnicode (s);
				Assert.Fail (label != null ? label.ToString () + ":" + s : s);
			} catch (ArgumentException) {
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:8,代码来源:IdnMappingTest.cs

示例2: Index

        // GET: Home
        public ActionResult Index(string id = "")
        {
            _logger.Debug("哈哈");

            string domin = Request.Headers["host"];
            //Regex r = new Regex(@"[\u4e00-\u9fa5]+");
            //Match mc = r.Match(domin);
            //if (mc.Length != 0)//含中文域名
            //{
            //    IdnMapping dd = new IdnMapping();
            //    domin = dd.GetUnicode(domin);
            //}
            IdnMapping dd = new IdnMapping();
            domin = dd.GetUnicode(domin);
            ViewBag.Domin = domin + " | "+id;
            return View();
        }
开发者ID:yimogit,项目名称:YimoFramework,代码行数:18,代码来源:HomeController.cs

示例3: UnicodeEquivalent

        internal unsafe static string UnicodeEquivalent(char* hostname, int start, int end, ref bool allAscii, ref bool atLeastOneValidIdn)
        {
            IdnMapping map = new IdnMapping();

            // hostname already validated
            allAscii = true;
            atLeastOneValidIdn = false;
            string idn = null;
            if (end <= start)
                return idn;

            string unescapedHostname = Uri.StripBidiControlCharacter(hostname, start, (end - start));

            string unicodeEqvlHost = null;
            int curPos = 0;
            int newPos = 0;
            int length = unescapedHostname.Length;
            bool asciiLabel = true;
            bool foundAce = false;
            bool checkedAce = false;
            bool foundDot = false;


            // We run a loop where for every label
            // a) if label is ascii and no ace then we lowercase it
            // b) if label is ascii and ace and not valid idn then just lowercase it
            // c) if label is ascii and ace and is valid idn then get its unicode eqvl
            // d) if label is unicode then clean it by running it through idnmapping
            do
            {
                asciiLabel = true;
                foundAce = false;
                checkedAce = false;
                foundDot = false;

                //find the dot or hit the end
                newPos = curPos;
                while (newPos < length)
                {
                    char c = unescapedHostname[newPos];
                    if (!checkedAce)
                    {
                        checkedAce = true;
                        if ((newPos + 3 < length) && (c == 'x') && IsIdnAce(unescapedHostname, newPos))
                            foundAce = true;
                    }
                    if (asciiLabel && (c > '\x7F'))
                    {
                        asciiLabel = false;
                        allAscii = false;
                    }
                    if ((c == '.') || (c == '\u3002') ||    //IDEOGRAPHIC FULL STOP 
                        (c == '\uFF0E') ||                  //FULLWIDTH FULL STOP
                        (c == '\uFF61'))                    //HALFWIDTH IDEOGRAPHIC FULL STOP
                    {
                        foundDot = true;
                        break;
                    }
                    ++newPos;
                }

                if (!asciiLabel)
                {
                    string asciiForm = unescapedHostname.Substring(curPos, newPos - curPos);
                    try
                    {
                        asciiForm = map.GetAscii(asciiForm);
                    }
                    catch (ArgumentException)
                    {
                        throw new UriFormatException(SR.net_uri_BadUnicodeHostForIdn);
                    }

                    unicodeEqvlHost += map.GetUnicode(asciiForm);
                    if (foundDot)
                        unicodeEqvlHost += ".";
                }
                else
                {
                    bool aceValid = false;
                    if (foundAce)
                    {
                        // check ace validity
                        try
                        {
                            unicodeEqvlHost += map.GetUnicode(unescapedHostname.Substring(curPos, newPos - curPos));
                            if (foundDot)
                                unicodeEqvlHost += ".";
                            aceValid = true;
                            atLeastOneValidIdn = true;
                        }
                        catch (ArgumentException)
                        {
                            // not valid ace so treat it as a normal ascii label
                        }
                    }

                    if (!aceValid)
                    {
                        // for invalid aces we just lowercase the label
//.........这里部分代码省略.........
开发者ID:er0dr1guez,项目名称:corefx,代码行数:101,代码来源:DomainNameHelper.cs

示例4: IdnEquivalent

        //
        // Will convert a host name into its idn equivalent + tell you if it had a valid idn label
        //
        internal unsafe static string IdnEquivalent(char* hostname, int start, int end, ref bool allAscii, ref bool atLeastOneValidIdn)
        {
            string bidiStrippedHost = null;
            string idnEquivalent = IdnEquivalent(hostname, start, end, ref allAscii, ref bidiStrippedHost);

            if (idnEquivalent != null)
            {
                string strippedHost = (allAscii ? idnEquivalent : bidiStrippedHost);

                fixed (char* strippedHostPtr = strippedHost)
                {
                    int length = strippedHost.Length;
                    int newPos = 0;
                    int curPos = 0;
                    bool foundAce = false;
                    bool checkedAce = false;
                    bool foundDot = false;

                    do
                    {
                        foundAce = false;
                        checkedAce = false;
                        foundDot = false;

                        //find the dot or hit the end
                        newPos = curPos;
                        while (newPos < length)
                        {
                            char c = strippedHostPtr[newPos];
                            if (!checkedAce)
                            {
                                checkedAce = true;
                                if ((newPos + 3 < length) && IsIdnAce(strippedHostPtr, newPos))
                                {
                                    newPos += 4;
                                    foundAce = true;
                                    continue;
                                }
                            }

                            if ((c == '.') || (c == '\u3002') ||    //IDEOGRAPHIC FULL STOP 
                                (c == '\uFF0E') ||                  //FULLWIDTH FULL STOP
                                (c == '\uFF61'))                    //HALFWIDTH IDEOGRAPHIC FULL STOP
                            {
                                foundDot = true;
                                break;
                            }
                            ++newPos;
                        }

                        if (foundAce)
                        {
                            // check ace validity
                            try
                            {
                                IdnMapping map = new IdnMapping();
                                map.GetUnicode(new string(strippedHostPtr, curPos, newPos - curPos));
                                atLeastOneValidIdn = true;
                                break;
                            }
                            catch (ArgumentException)
                            {
                                // not valid ace so treat it as a normal ascii label
                            }
                        }

                        curPos = newPos + (foundDot ? 1 : 0);
                    } while (curPos < length);
                }
            }
            else
            {
                atLeastOneValidIdn = false;
            }
            return idnEquivalent;
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:79,代码来源:DomainNameHelper.cs

示例5: EmbeddedNulls

        public void EmbeddedNulls()
        {
            var idn = new IdnMapping();

            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000"));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000", 0));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000", 0, 2));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101"));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101", 0));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101", 0, 3));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101\u0000"));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101\u0000", 0));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101\u0000", 0, 4));
            Assert.Throws<ArgumentException>(() => idn.GetUnicode("abc\u0000", 0, 4));
            Assert.Throws<ArgumentException>(() => idn.GetUnicode("ab\u0000c", 0, 4));
        }
开发者ID:hitomi333,项目名称:corefx,代码行数:16,代码来源:GetAsciiTests.cs

示例6: GetUnicode

		void GetUnicode (IdnMapping m, string source, string expected, object label)
		{
			Assert.AreEqual (expected, m.GetUnicode (source), label != null ? label.ToString () : expected);
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:4,代码来源:IdnMappingTest.cs

示例7: GetImportableItems

        public static List<string> GetImportableItems(int packageId, int itemTypeId)
        {
            List<string> items = new List<string>();

            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.IsAdmin | DemandAccount.NotDemo);
            if (accountCheck < 0) return items;

            // load item type
            if (itemTypeId > 0)
            {
                ServiceProviderItemType itemType = PackageController.GetServiceItemType(itemTypeId);

                // load group
                ResourceGroupInfo group = ServerController.GetResourceGroup(itemType.GroupId);

                // Is it DNS Zones? Then create a IDN Mapping object
                var isDnsZones = group.GroupName == "DNS";
                var idn = new IdnMapping();

                // get service id
                int serviceId = PackageController.GetPackageServiceId(packageId, group.GroupName);
                if (serviceId == 0)
                    return items;

                DataTable dtServiceItems = PackageController.GetServiceItemsDataSet(serviceId).Tables[0];
                DataTable dtPackageItems = PackageController.GetPackageItemsDataSet(packageId).Tables[0];

                // instantiate controller
                IImportController ctrl = null;
                try
                {
                    List<string> importableItems = null;
                    ctrl = Activator.CreateInstance(Type.GetType(group.GroupController)) as IImportController;
                    if (ctrl != null)
                    {
                        importableItems = ctrl.GetImportableItems(packageId, itemTypeId, Type.GetType(itemType.TypeName), group);
                    }

                    foreach (string importableItem in importableItems)
                    {
                        // filter items by service
                        bool serviceContains = false;
                        foreach (DataRow dr in dtServiceItems.Rows)
                        {
                            string serviceItemName = (string)dr["ItemName"];
                            int serviceItemTypeId = (int)dr["ItemTypeId"];

                            if (String.Compare(importableItem, serviceItemName, true) == 0
                                && serviceItemTypeId == itemTypeId)
                            {
                                serviceContains = true;
                                break;
                            }
                        }

                        // filter items by package
                        bool packageContains = false;
                        foreach (DataRow dr in dtPackageItems.Rows)
                        {
                            string packageItemName = (string)dr["ItemName"];
                            int packageItemTypeId = (int)dr["ItemTypeId"];

                            if (String.Compare(importableItem, packageItemName, true) == 0
                                && packageItemTypeId == itemTypeId)
                            {
                                packageContains = true;
                                break;
                            }
                        }

                        if (!serviceContains && !packageContains)
                        {
                            var itemToImport = importableItem;

                            // For DNS zones the compare has been made using ascii, convert to unicode if necessary to make the list of items easier to read
                            if (isDnsZones && itemToImport.StartsWith("xn--"))
                            {
                                itemToImport = idn.GetUnicode(importableItem);
                            }

                            items.Add(itemToImport);
                        }
                    }

                }
                catch { /* do nothing */ }
            }
            else
                return GetImportableCustomItems(packageId, itemTypeId);

            return items;
        }
开发者ID:jonwbstr,项目名称:Websitepanel,代码行数:93,代码来源:ImportController.cs

示例8: UnicodeEquivalent

 internal static unsafe string UnicodeEquivalent(char* hostname, int start, int end, ref bool allAscii, ref bool atLeastOneValidIdn)
 {
     IdnMapping mapping = new IdnMapping();
     allAscii = true;
     atLeastOneValidIdn = false;
     string str = null;
     if (end <= start)
     {
         return str;
     }
     string input = Uri.StripBidiControlCharacter(hostname, start, end - start);
     string str3 = null;
     int startIndex = 0;
     int index = 0;
     int length = input.Length;
     bool flag = true;
     bool flag2 = false;
     bool flag3 = false;
     bool flag4 = false;
     do
     {
         flag = true;
         flag2 = false;
         flag3 = false;
         flag4 = false;
         index = startIndex;
         while (index < length)
         {
             char ch = input[index];
             if (!flag3)
             {
                 flag3 = true;
                 if ((((index + 3) < length) && (ch == 'x')) && IsIdnAce(input, index))
                 {
                     flag2 = true;
                 }
             }
             if (flag && (ch > '\x007f'))
             {
                 flag = false;
                 allAscii = false;
             }
             if (((ch == '.') || (ch == '。')) || ((ch == 0xff0e) || (ch == 0xff61)))
             {
                 flag4 = true;
                 break;
             }
             index++;
         }
         if (!flag)
         {
             string unicode = input.Substring(startIndex, index - startIndex);
             try
             {
                 unicode = mapping.GetAscii(unicode);
             }
             catch (ArgumentException)
             {
                 throw new UriFormatException(SR.GetString("net_uri_BadUnicodeHostForIdn"));
             }
             str3 = str3 + mapping.GetUnicode(unicode);
             if (flag4)
             {
                 str3 = str3 + ".";
             }
         }
         else
         {
             bool flag5 = false;
             if (flag2)
             {
                 try
                 {
                     str3 = str3 + mapping.GetUnicode(input.Substring(startIndex, index - startIndex));
                     if (flag4)
                     {
                         str3 = str3 + ".";
                     }
                     flag5 = true;
                     atLeastOneValidIdn = true;
                 }
                 catch (ArgumentException)
                 {
                 }
             }
             if (!flag5)
             {
                 str3 = str3 + input.Substring(startIndex, index - startIndex).ToLowerInvariant();
                 if (flag4)
                 {
                     str3 = str3 + ".";
                 }
             }
         }
         startIndex = index + (flag4 ? 1 : 0);
     }
     while (startIndex < length);
     return str3;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:99,代码来源:DomainNameHelper.cs

示例9: GetImportableItems

        public List<string> GetImportableItems(int packageId, int itemTypeId, Type itemType, ResourceGroupInfo group)
        {
            List<string> items = new List<string>();

            // get service id
            int serviceId = PackageController.GetPackageServiceId(packageId, group.GroupName);
            if (serviceId == 0)
                return items;

            // Mail provider
            DNSServer dns = new DNSServer();
            ServiceProviderProxy.Init(dns, serviceId);

            // IDN: The list of importable names is populated with unicode names, to make it easier for the user
            var idn = new IdnMapping();

            if (itemType == typeof(DnsZone))
                items.AddRange(dns.GetZones().Select(z =>
                    Encoding.UTF8.GetByteCount(z) == z.Length ? // IsASCII
                    idn.GetUnicode(z) : z ));

            return items;
        }
开发者ID:lwhitelock,项目名称:Websitepanel,代码行数:23,代码来源:DnsServerController.cs


注:本文中的System.Globalization.IdnMapping.GetUnicode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。