Fan.Sys.OutStream.writeUtfString C# (CSharp) Méthode

writeUtfString() private méthode

private writeUtfString ( string s ) : OutStream
s string
Résultat OutStream
        private OutStream writeUtfString(string s)
        {
            int slen = s.Length;
              int utflen = 0;

              // first we have to figure m_out the utf Length
              for (int i=0; i<slen; ++i)
              {
            int c = s[i];
            if (c <= 0x007F)
              utflen +=1;
            else if (c > 0x07FF)
              utflen += 3;
            else
              utflen += 2;
              }

              // sanity check
              if (utflen > 65536) throw IOErr.make("String too big").val;

              // write Length as 2 byte value
              w((utflen >> 8) & 0xFF);
              w((utflen >> 0) & 0xFF);

              // write characters
              for (int i=0; i<slen; ++i)
              {
            int c = s[i];
            if (c <= 0x007F)
            {
              w(c);
            }
            else if (c > 0x07FF)
            {
              w(0xE0 | ((c >> 12) & 0x0F));
              w(0x80 | ((c >>  6) & 0x3F));
              w(0x80 | ((c >>  0) & 0x3F));
            }
            else
            {
              w(0xC0 | ((c >>  6) & 0x1F));
              w(0x80 | ((c >>  0) & 0x3F));
            }
              }
              return this;
        }