Example #1
0
 /// <summary>Decompress the byte array previously returned by
 /// compressString back into a String
 /// </summary>
 public static System.String DecompressString(byte[] value_Renamed)
 {
     UnicodeUtil.UTF16Result result = new UnicodeUtil.UTF16Result();
     byte[] bytes = Decompress(value_Renamed);
     UnicodeUtil.UTF8toUTF16(bytes, 0, bytes.Length, result);
     return(new System.String(result.result, 0, result.length));
 }
Example #2
0
 // Currently used only by assert statements
 private bool InitUTF16Results()
 {
     utf16Result1 = new UnicodeUtil.UTF16Result();
     utf16Result2 = new UnicodeUtil.UTF16Result();
     return(true);
 }
 // currently used only by assert statements
 private bool InitUTF16Results()
 {
     utf16Result1 = new UnicodeUtil.UTF16Result();
     utf16Result2 = new UnicodeUtil.UTF16Result();
     return true;
 }
Example #4
0
		/// <summary>Decompress the byte array previously returned by
		/// compressString back into a String 
		/// </summary>
		public static System.String DecompressString(byte[] value_Renamed)
		{
			UnicodeUtil.UTF16Result result = new UnicodeUtil.UTF16Result();
			byte[] bytes = Decompress(value_Renamed);
			UnicodeUtil.UTF8toUTF16(bytes, 0, bytes.Length, result);
			return new System.String(result.result, 0, result.length);
		}
Example #5
0
		public virtual void  TestIncrementalUnicodeStrings()
		{
			r = NewRandom();
			char[] buffer = new char[20];
			char[] expected = new char[20];
			
			UnicodeUtil.UTF8Result utf8 = new UnicodeUtil.UTF8Result();
			UnicodeUtil.UTF16Result utf16 = new UnicodeUtil.UTF16Result();
			UnicodeUtil.UTF16Result utf16a = new UnicodeUtil.UTF16Result();
			
			bool hasIllegal = false;
			byte[] last = new byte[60];
			
			for (int iter = 0; iter < 100000; iter++)
			{
				
				int prefix;
				
				if (iter == 0 || hasIllegal)
					prefix = 0;
				else
					prefix = NextInt(20);
				
				hasIllegal = FillUnicode(buffer, expected, prefix, 20 - prefix);
				
				UnicodeUtil.UTF16toUTF8(buffer, 0, 20, utf8);
				if (!hasIllegal)
				{
					byte[] b = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(new System.String(buffer, 0, 20));
					Assert.AreEqual(b.Length, utf8.length);
					for (int i = 0; i < b.Length; i++)
						Assert.AreEqual(b[i], utf8.result[i]);
				}
				
				int bytePrefix = 20;
				if (iter == 0 || hasIllegal)
					bytePrefix = 0;
				else
					for (int i = 0; i < 20; i++)
						if (last[i] != utf8.result[i])
						{
							bytePrefix = i;
							break;
						}
				System.Array.Copy(utf8.result, 0, last, 0, utf8.length);
				
				UnicodeUtil.UTF8toUTF16(utf8.result, bytePrefix, utf8.length - bytePrefix, utf16);
				Assert.AreEqual(20, utf16.length);
				for (int i = 0; i < 20; i++)
					Assert.AreEqual(expected[i], utf16.result[i]);
				
				UnicodeUtil.UTF8toUTF16(utf8.result, 0, utf8.length, utf16a);
				Assert.AreEqual(20, utf16a.length);
				for (int i = 0; i < 20; i++)
					Assert.AreEqual(expected[i], utf16a.result[i]);
			}
		}
Example #6
0
		public virtual void  TestRandomUnicodeStrings()
		{
			r = NewRandom();
			
			char[] buffer = new char[20];
			char[] expected = new char[20];
			
			UnicodeUtil.UTF8Result utf8 = new UnicodeUtil.UTF8Result();
			UnicodeUtil.UTF16Result utf16 = new UnicodeUtil.UTF16Result();
			
			for (int iter = 0; iter < 100000; iter++)
			{
				bool hasIllegal = FillUnicode(buffer, expected, 0, 20);
				
				UnicodeUtil.UTF16toUTF8(buffer, 0, 20, utf8);
				if (!hasIllegal)
				{
					byte[] b = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(new System.String(buffer, 0, 20));
					Assert.AreEqual(b.Length, utf8.length);
					for (int i = 0; i < b.Length; i++)
						Assert.AreEqual(b[i], utf8.result[i]);
				}
				
				UnicodeUtil.UTF8toUTF16(utf8.result, 0, utf8.length, utf16);
				Assert.AreEqual(utf16.length, 20);
				for (int i = 0; i < 20; i++)
					Assert.AreEqual(expected[i], utf16.result[i]);
			}
		}
Example #7
0
		public virtual void  TestAllUnicodeChars()
		{
			
			UnicodeUtil.UTF8Result utf8 = new UnicodeUtil.UTF8Result();
			UnicodeUtil.UTF16Result utf16 = new UnicodeUtil.UTF16Result();
			char[] chars = new char[2];
			for (int ch = 0; ch < 0x0010FFFF; ch++)
			{
				
				if (ch == 0xd800)
				// Skip invalid code points
					ch = 0xe000;
				
				int len = 0;
				if (ch <= 0xffff)
				{
					chars[len++] = (char) ch;
				}
				else
				{
					chars[len++] = (char) (((ch - 0x0010000) >> 10) + UnicodeUtil.UNI_SUR_HIGH_START);
					chars[len++] = (char) (((ch - 0x0010000) & 0x3FFL) + UnicodeUtil.UNI_SUR_LOW_START);
				}
				
				UnicodeUtil.UTF16toUTF8(chars, 0, len, utf8);
				
				System.String s1 = new System.String(chars, 0, len);
				System.String s2 = System.Text.Encoding.UTF8.GetString(utf8.result, 0, utf8.length);
				Assert.AreEqual(s1, s2, "codepoint " + ch);
				
				UnicodeUtil.UTF8toUTF16(utf8.result, 0, utf8.length, utf16);
				Assert.AreEqual(s1, new String(utf16.result, 0, utf16.length), "codepoint " + ch);
				
				byte[] b = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(s1);
				Assert.AreEqual(utf8.length, b.Length);
				for (int j = 0; j < utf8.length; j++)
					Assert.AreEqual(utf8.result[j], b[j]);
			}
		}