Example #1
0
 public static void StringToUnicodeBytes(ByteArrayOutputStream b, string s, bool doubleSingleQuotes)
 {
     if (s != null)
     {
         int length = s.Length;
         int num2   = 0;
         if (length != 0)
         {
             char[] chArray = s.ToCharArray();
             b.EnsureRoom((length * 2) + 5);
             for (int i = 0; i < length; i++)
             {
                 char ch = chArray[i];
                 if (ch == '\\')
                 {
                     if ((i < (length - 1)) && (chArray[i + 1] == 'u'))
                     {
                         b.WriteNoCheck(ch);
                         b.WriteNoCheck(0x75);
                         b.WriteNoCheck(0x30);
                         b.WriteNoCheck(0x30);
                         b.WriteNoCheck(0x35);
                         b.WriteNoCheck(0x63);
                         num2 += 5;
                     }
                     else
                     {
                         b.Write(ch);
                     }
                 }
                 else if ((ch >= ' ') && (ch <= '\x007f'))
                 {
                     b.WriteNoCheck(ch);
                     if ((ch == '\'') & doubleSingleQuotes)
                     {
                         b.WriteNoCheck(ch);
                         num2++;
                     }
                 }
                 else
                 {
                     b.WriteNoCheck(0x5c);
                     b.WriteNoCheck(0x75);
                     b.WriteNoCheck(Hexbytes[(ch >> 12) & '\x000f']);
                     b.WriteNoCheck(Hexbytes[(ch >> 8) & '\x000f']);
                     b.WriteNoCheck(Hexbytes[(ch >> 4) & '\x000f']);
                     b.WriteNoCheck(Hexbytes[ch & '\x000f']);
                     num2 += 5;
                 }
                 if (num2 > length)
                 {
                     b.EnsureRoom((length + num2) + 5);
                     num2 = 0;
                 }
             }
         }
     }
 }
Example #2
0
 public static int StringToUtfBytes(string str, ByteArrayOutputStream o)
 {
     byte[] bytes = Encoding.UTF8.GetBytes(str);
     o.EnsureRoom(bytes.Length);
     o.Write(bytes);
     return(bytes.Length);
 }