• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Text.UTF32Encoding类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Text.UTF32Encoding的典型用法代码示例。如果您正苦于以下问题:C# UTF32Encoding类的具体用法?C# UTF32Encoding怎么用?C# UTF32Encoding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



UTF32Encoding类属于System.Text命名空间,在下文中一共展示了UTF32Encoding类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: EncodingDetecingInputStream

		static EncodingDetecingInputStream ()
		{
			StrictUTF8 = new UTF8Encoding (false, true);
			Strict1234UTF32 = new UTF32Encoding (true, false, true);
			StrictBigEndianUTF16 = new UnicodeEncoding (true, false, true);
			StrictUTF16 = new UnicodeEncoding (false, false, true);
		}
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:JsonReader.cs


示例2: GetUtf32

 public static string GetUtf32(string unicodeString)
 {
     var utf8 = new UTF32Encoding();
     byte[] encodeBytes = utf8.GetBytes(unicodeString);
     string decodedString = utf8.GetString(encodeBytes);
     return decodedString;
 }
开发者ID:mnt777,项目名称:MineStocks,代码行数:7,代码来源:Utility.cs


示例3: StflApi

        static StflApi()
        {
            // check if he has a graphical terminal. screen/tmux in not
            // detected in case someone is using it in pure text mode
            string termName = Environment.GetEnvironmentVariable("TERM");
            IsXterm = (termName != null && (termName.StartsWith("xterm") ||
                termName.StartsWith("rxvt")));
            // detect UTF-8 locale according to:
            // http://www.cl.cam.ac.uk/~mgk25/unicode.html#activate
            var locale = Environment.GetEnvironmentVariable("LC_ALL") ??
                         Environment.GetEnvironmentVariable("LC_LCTYPE") ??
                         Environment.GetEnvironmentVariable("LANG") ??
                         String.Empty;
            locale = locale.ToUpperInvariant();
            IsUtf8Locale = locale.Contains("UTF-8") || locale.Contains("UTF8");

            EscapeLessThanCharacter = "<>";
            EscapeGreaterThanCharacter = ">";

            Utf32NativeEndian = new UTF32Encoding(
                bigEndian: !BitConverter.IsLittleEndian,
                byteOrderMark: false,
                throwOnInvalidCharacters: true
            );

            // UTF-32 handling is broken in mono < 4.2
            // fix in 4.4: https://github.com/mono/mono/commit/6bfb7e6d149f5e5c0fe04d680e3f7d36769ef541
            // fix in 4.2: https://github.com/mono/mono/commit/ea4ed4a47b98832e294d166bee5b8301fe87e216
            BrokenUtf32Handling = IsMonoVersionLessThan(4, 2);
        }
开发者ID:pacificIT,项目名称:smuxi,代码行数:30,代码来源:StflApi.cs


示例4: button2_Click

        private void button2_Click(object sender, EventArgs e)
        {
            SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
            UTF32Encoding utf8 = new UTF32Encoding();
            string hashResult = BitConverter.ToString(sha1.ComputeHash(utf8.GetBytes(textBox2.Text)));

            label4.Text = hashResult;
            label3.Text = hashResult.Length.ToString();
        }
开发者ID:TheSniper102,项目名称:winformsTuts,代码行数:9,代码来源:Hashing.cs


示例5: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            UTF32Encoding utf8 = new UTF32Encoding();
            string hashResult = BitConverter.ToString(md5.ComputeHash(utf8.GetBytes(textBox1.Text)));

            label1.Text = hashResult;
            label2.Text = hashResult.Length.ToString();
        }
开发者ID:TheSniper102,项目名称:winformsTuts,代码行数:9,代码来源:Hashing.cs


示例6: Md5Encrypte

        public static string Md5Encrypte(string inputString)
        {
            var u = new System.Text.UTF32Encoding();
            byte[] bytes = u.GetBytes(inputString);
            System.Security.Cryptography.MD5 md = new System.Security.Cryptography.MD5CryptoServiceProvider();

            byte[] result = md.ComputeHash(bytes);
            return Convert.ToBase64String(result);
        }
开发者ID:nstungxd,项目名称:ips-project-vdc,代码行数:9,代码来源:Common.cs


示例7: FromString

		/// <summary>hashing from string. Result in format of 000-000</summary>
		public static string FromString(string input)
		{
			if (input.IsNullOrEmpty())
				return FromBuffer(null);


			var utf32 = new UTF32Encoding();
			return FromBuffer(utf32.GetBytes(input));
		}
开发者ID:cssack,项目名称:CsGlobals,代码行数:10,代码来源:SmallHash.cs


示例8: CreateHash

        /// <summary>
        /// Creates a password hash from the details provided
        /// </summary>
        /// <param name="created">The time when the person was created</param>
        /// <param name="password">The desired password</param>
        /// <param name="salt">The login's salt</param>
        /// <returns>A Byte[] with the password hash</returns>
        public Byte[] CreateHash(DateTime created, string password, string salt)
        {
            if (password == null) throw new ArgumentNullException("password");
            if (salt == null) throw new ArgumentNullException("salt");

            SHA1 sha = new SHA1CryptoServiceProvider();
            UTF32Encoding enc = new UTF32Encoding();
            var stringValue = string.Concat(_configurationManager.HashConstant, created, password, salt);
            return sha.ComputeHash(enc.GetBytes(stringValue));
        }
开发者ID:ardliath,项目名称:BigSpace,代码行数:17,代码来源:CryptographyManager.cs


示例9: GetByteCount2

		[Category ("NotDotNet")] // A1/B1 return 24 on MS
		public void GetByteCount2 ()
		{
			string s = "za\u0306\u01FD\u03B2\uD8FF\uDCFF";

			UTF32Encoding le = new UTF32Encoding (false, true);
			Assert.AreEqual (28, le.GetByteCount (s), "#A1");
			Assert.AreEqual (0, le.GetByteCount (string.Empty), "#A2");

			UTF32Encoding be = new UTF32Encoding (true, true);
			Assert.AreEqual (28, be.GetByteCount (s), "#B1");
			Assert.AreEqual (0, be.GetByteCount (string.Empty), "#B2");
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:13,代码来源:UTF32EncodingTest.cs


示例10: GetByteCount1

		[Category ("NotDotNet")] // A1/B1 return 24 on MS
		public void GetByteCount1 ()
		{
			char [] chars = new char[] { 'z', 'a', '\u0306',
				'\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };

			UTF32Encoding le = new UTF32Encoding (false, true);
			Assert.AreEqual (28, le.GetByteCount (chars), "#A1");
			Assert.AreEqual (0, le.GetByteCount (new char [0]), "#A2");

			UTF32Encoding be = new UTF32Encoding (true, true);
			Assert.AreEqual (28, be.GetByteCount (chars), "#B1");
			Assert.AreEqual (0, be.GetByteCount (new char [0]), "#B2");
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:14,代码来源:UTF32EncodingTest.cs


示例11: GetByteCount

		[Test] // GetByteCount (String)
		public void GetByteCount2_S_Null ()
		{
			UTF32Encoding enc = new UTF32Encoding ();
			try {
				enc.GetByteCount ((string) null);
				Assert.Fail ("#1");
			} catch (ArgumentNullException ex) {
				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
				Assert.IsNull (ex.InnerException, "#3");
				Assert.IsNotNull (ex.Message, "#4");
				Assert.AreEqual ("s", ex.ParamName, "#5");
			}
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:14,代码来源:UTF32EncodingTest.cs


示例12: OpensReaderWithoutAutoDetectEncoding

        public void OpensReaderWithoutAutoDetectEncoding()
        {
            string expected = "test";
            Encoding utf32 = new UTF32Encoding(false, true);
            byte[] resourceData = GetBytes(expected, utf32);
            EncodedResource r = new EncodedResource(new InputStreamResource(new MemoryStream(resourceData), "description"), Encoding.UTF8, false);
            StreamReader reader = (StreamReader)r.OpenReader();
            Assert.AreEqual(Encoding.UTF8.EncodingName, reader.CurrentEncoding.EncodingName);
            string actual = reader.ReadToEnd();
//            Assert.AreEqual("\uFFFD\uFFFD\0\0t\0\0\0e\0\0\0s\0\0\0t\0\0\0", actual);
            Assert.AreEqual(Encoding.UTF8.GetString(resourceData), actual);
            Assert.AreEqual(Encoding.UTF8.EncodingName, reader.CurrentEncoding.EncodingName);
        }
开发者ID:Binodesk,项目名称:spring-net,代码行数:13,代码来源:EncodedResourceTests.cs


示例13: OpensReaderWithAutoDetectEncoding

        public void OpensReaderWithAutoDetectEncoding()
        {
            string expected = "test";
            Encoding utf32 = new UTF32Encoding(false, true);
            byte[] resourceData = GetBytes(expected, utf32);
            resourceData = (byte[])ArrayUtils.Concat(utf32.GetPreamble(), resourceData);
            EncodedResource r = new EncodedResource( new InputStreamResource( new MemoryStream( resourceData), "description" ), Encoding.UTF8, true);
            StreamReader reader = (StreamReader)r.OpenReader();
            Assert.AreEqual(Encoding.UTF8.EncodingName, reader.CurrentEncoding.EncodingName);
            string actual = reader.ReadToEnd();
            Assert.AreEqual( "\uFEFF" + expected , actual);
// interestingly the line below is *not* true!
//            Assert.AreEqual(utf32.GetString(resourceData), actual);
            Assert.AreEqual(utf32, reader.CurrentEncoding);
        }
开发者ID:Binodesk,项目名称:spring-net,代码行数:15,代码来源:EncodedResourceTests.cs


示例14: ComputeSaltedHash

        /// <summary>
        /// Compute the salted hash of the given password
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public string ComputeSaltedHash(string password)
        {
            if (password == null)
                throw new ArgumentNullException("password");

            //Encoder for password (text->bytes)
            UTF32Encoding encoder = new UTF32Encoding();

            //Put password bytes and then saly bytes into byte array
            var toHash = encoder.GetBytes(password)
                .Concat(BitConverter.GetBytes(Salt))
                .ToArray();

            // Hash the salted password
            using (SHA512Managed sha1 = new SHA512Managed())
                return BitConverter.ToString(sha1.ComputeHash(toHash)).Replace("-", "");
        }
开发者ID:WildGenie,项目名称:Bastet-Legacy,代码行数:22,代码来源:User.cs


示例15: DefineEncoding

        private static Encoding DefineEncoding(Encoding enc, FileStream fs)
        {
            int bytesPerSignature = 0;
            byte[] signature = new byte[4];
            int c = fs.Read(signature, 0, 4);
            if (signature[0] == 0xFF && signature[1] == 0xFE && signature[2] == 0x00 && signature[3] == 0x00 && c >= 4)
            {
                enc = Encoding.UTF32;//UTF32 LE
                bytesPerSignature = 4;
            }
            else
            if (signature[0] == 0x00 && signature[1] == 0x00 && signature[2] == 0xFE && signature[3] == 0xFF)
            {
                enc = new UTF32Encoding(true, true);//UTF32 BE
                bytesPerSignature = 4;
            }
            else
            if (signature[0] == 0xEF && signature[1] == 0xBB && signature[2] == 0xBF)
            {
                enc = Encoding.UTF8;//UTF8
                bytesPerSignature = 3;
            }
            else
            if (signature[0] == 0xFE && signature[1] == 0xFF)
            {
                enc = Encoding.BigEndianUnicode;//UTF16 BE
                bytesPerSignature = 2;
            }
            else
            if (signature[0] == 0xFF && signature[1] == 0xFE)
            {
                enc = Encoding.Unicode;//UTF16 LE
                bytesPerSignature = 2;
            }

            fs.Seek(bytesPerSignature, SeekOrigin.Begin);

            return enc;
        }
开发者ID:WendyH,项目名称:HMSEditor_addon,代码行数:39,代码来源:FileTextSource.cs


示例16: GetEncodingRare

        [System.Security.SecurityCritical]  // auto-generated
        private static Encoding GetEncodingRare(int codepage)
        {
            Contract.Assert(codepage != 0 && codepage != 1200 && codepage != 1201 && codepage != 65001,
                "[Encoding.GetEncodingRare]This code page (" + codepage + ") isn't supported by GetEncodingRare!");
            Encoding result;
            switch (codepage)
            {
                case CodePageUTF7:              // 65000
                    result = UTF7;
                    break;
                case CodePageUTF32:             // 12000
                    result = UTF32;
                    break;
                case CodePageUTF32BE:           // 12001
                    result = new UTF32Encoding(true, true);
                    break;
                case ISCIIAssemese:
                case ISCIIBengali:
                case ISCIIDevanagari:
                case ISCIIGujarathi:
                case ISCIIKannada:
                case ISCIIMalayalam:
                case ISCIIOriya:
                case ISCIIPanjabi:
                case ISCIITamil:
                case ISCIITelugu:
                    result = new ISCIIEncoding(codepage);
                    break;
                // GB2312-80 uses same code page for 20936 and mac 10008
                case CodePageMacGB2312:
          //     case CodePageGB2312:
          //        result = new DBCSCodePageEncoding(codepage, EUCCN);
                    result = new DBCSCodePageEncoding(CodePageMacGB2312, CodePageGB2312);
                    break;

                // Mac Korean 10003 and 20949 are the same
                case CodePageMacKorean:
                    result = new DBCSCodePageEncoding(CodePageMacKorean, CodePageDLLKorean);
                    break;
                // GB18030 Code Pages
                case GB18030:
                    result = new GB18030Encoding();
                    break;
                // ISO2022 Code Pages
                case ISOKorean:
            //    case ISOSimplifiedCN
                case ChineseHZ:
                case ISO2022JP:         // JIS JP, full-width Katakana mode (no half-width Katakana)
                case ISO2022JPESC:      // JIS JP, esc sequence to do Katakana.
                case ISO2022JPSISO:     // JIS JP with Shift In/ Shift Out Katakana support
                    result = new ISO2022Encoding(codepage);
                    break;
                // Duplicate EUC-CN (51936) just calls a base code page 936,
                // so does ISOSimplifiedCN (50227), which's gotta be broken
                case DuplicateEUCCN:
                case ISOSimplifiedCN:
                    result = new DBCSCodePageEncoding(codepage, EUCCN);    // Just maps to 936
                    break;
                case EUCJP:
                    result = new EUCJPEncoding();
                    break;
                case EUCKR:
                    result = new DBCSCodePageEncoding(codepage, CodePageDLLKorean);    // Maps to 20949
                    break;
                case ENC50229:
                    throw new NotSupportedException(Environment.GetResourceString("NotSupported_CodePage50229"));
                case ISO_8859_8I:
                    result = new SBCSCodePageEncoding(codepage, ISO_8859_8_Visual);        // Hebrew maps to a different code page
                    break;
                default:
                    // Not found, already tried codepage table code pages in GetEncoding()
                    throw new NotSupportedException(
                        Environment.GetResourceString("NotSupported_NoCodepageData", codepage));
            }
            return result;
        }
开发者ID:enavro,项目名称:coreclr,代码行数:77,代码来源:Encoding.cs


示例17: GetEncoding

        [System.Security.SecuritySafeCritical]  // auto-generated
#endif
        public static Encoding GetEncoding(int codepage)
        {
            Encoding result = EncodingProvider.GetEncodingFromProvider(codepage);
            if (result != null)
                return result;

            //
            // NOTE: If you add a new encoding that can be get by codepage, be sure to
            // add the corresponding item in EncodingTable.
            // Otherwise, the code below will throw exception when trying to call
            // EncodingTable.GetDataItem().
            //
            if (codepage < 0 || codepage > 65535) {
                throw new ArgumentOutOfRangeException(
                    "codepage", Environment.GetResourceString("ArgumentOutOfRange_Range",
                        0, 65535));
            }

            Contract.EndContractBlock();

            // Our Encoding

            // See if we have a hash table with our encoding in it already.
            if (encodings != null) {
                result = (Encoding)encodings[codepage];
            }

            if (result == null)
            {
                // Don't conflict with ourselves
                lock (InternalSyncObject)
                {
                    // Need a new hash table
                    // in case another thread beat us to creating the Dictionary
                    if (encodings == null) {
                        encodings = new Hashtable();
                    }

                    // Double check that we don't have one in the table (in case another thread beat us here)
                    if ((result = (Encoding)encodings[codepage]) != null)
                        return result;

                    // Special case the commonly used Encoding classes here, then call
                    // GetEncodingRare to avoid loading classes like MLangCodePageEncoding
                    // and ASCIIEncoding.  ASP.NET uses UTF-8 & ISO-8859-1.
                    switch (codepage)
                    {
                        case CodePageDefault:                   // 0, default code page
                            result = Encoding.Default;
                            break;
                        case CodePageUnicode:                   // 1200, Unicode
                            result = Unicode;
                            break;
                        case CodePageBigEndian:                 // 1201, big endian unicode
                            result = BigEndianUnicode;
                            break;
#if FEATURE_CODEPAGES_FILE                            
                        case CodePageWindows1252:               // 1252, Windows
                            result = new SBCSCodePageEncoding(codepage);
                            break;
#else

#if FEATURE_UTF7
                            // on desktop, UTF7 is handled by GetEncodingRare.
                            // On Coreclr, we handle this directly without bringing GetEncodingRare, so that we get real UTF-7 encoding.
                        case CodePageUTF7:                      // 65000, UTF7
                            result = UTF7;
                            break;
#endif 

#if FEATURE_UTF32        
                        case CodePageUTF32:             // 12000
                            result = UTF32;
                            break;
                        case CodePageUTF32BE:           // 12001
                            result = new UTF32Encoding(true, true);
                            break;
#endif

#endif
                        case CodePageUTF8:                      // 65001, UTF8
                            result = UTF8;
                            break;

                        // These are (hopefully) not very common, but also shouldn't slow us down much and make default
                        // case able to handle more code pages by calling GetEncodingCodePage
                        case CodePageNoOEM:             // 1
                        case CodePageNoMac:             // 2
                        case CodePageNoThread:          // 3
                        case CodePageNoSymbol:          // 42
                            // Win32 also allows the following special code page values.  We won't allow them except in the
                            // CP_ACP case.
                            // #define CP_ACP                    0           // default to ANSI code page
                            // #define CP_OEMCP                  1           // default to OEM  code page
                            // #define CP_MACCP                  2           // default to MAC  code page
                            // #define CP_THREAD_ACP             3           // current thread's ANSI code page
                            // #define CP_SYMBOL                 42          // SYMBOL translations
                            throw new ArgumentException(Environment.GetResourceString(
//.........这里部分代码省略.........
开发者ID:enavro,项目名称:coreclr,代码行数:101,代码来源:Encoding.cs


示例18: IsMailNewsDisplay

		public void IsMailNewsDisplay ()
		{
			UTF32Encoding le = new UTF32Encoding (false, true);
			Assert.IsFalse (le.IsMailNewsDisplay);

			UTF32Encoding be = new UTF32Encoding (true, true);
			Assert.IsFalse (be.IsMailNewsDisplay, "#2");
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:8,代码来源:UTF32EncodingTest.cs


示例19: IsMailNewsSave

		public void IsMailNewsSave ()
		{
			UTF32Encoding le = new UTF32Encoding (false, true);
			Assert.IsFalse (le.IsMailNewsSave);

			UTF32Encoding be = new UTF32Encoding (true, true);
			Assert.IsFalse (be.IsMailNewsSave, "#2");
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:8,代码来源:UTF32EncodingTest.cs


示例20: GetPreamble

		public void GetPreamble ()
		{
			byte[] lePreamble = new UTF32Encoding(false, true).GetPreamble();
			Assert.AreEqual (new byte [] { 0xff, 0xfe, 0, 0 }, lePreamble, "#1");

			byte[] bePreamble = new UTF32Encoding(true, true).GetPreamble();
			Assert.AreEqual (new byte [] { 0, 0, 0xfe, 0xff }, bePreamble, "#2");
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:8,代码来源:UTF32EncodingTest.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Text.UTF7Encoding类代码示例发布时间:2022-05-26
下一篇:
C# Text.StringBuilderWrapper类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap