Example #1
0
 private static bool NeedsTruncation(string s)
 {
     // Optimization: only count the actual number of bytes if there is the possibility
     // of the string exceeding maxStringBytes
     return(encoding.GetMaxByteCount(s.Length) > maxStringBytes &&
            encoding.GetByteCount(s) > maxStringBytes);
 }
        static int _m_GetMaxByteCount(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                System.Text.Encoding gen_to_be_invoked = (System.Text.Encoding)translator.FastGetCSObj(L, 1);



                {
                    int _charCount = LuaAPI.xlua_tointeger(L, 2);

                    int gen_ret = gen_to_be_invoked.GetMaxByteCount(
                        _charCount);
                    LuaAPI.xlua_pushinteger(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Example #3
0
        public override void Encode(string s, int start, int end, Generic.List <byte> buf)
        {
            System.Text.Encoding enc = System.Text.Encoding.GetEncoding(1252); // Not sure if this is right.
            int len  = end - start;
            int need = enc.GetMaxByteCount(len);

            if (need > EncBuffer.Length)
            {
                EncBuffer = Util.GetBuf(need);
            }
            int nb = enc.GetBytes(s, start, len, EncBuffer, 0);

            for (int i = 0; i < nb; i += 1)
            {
                byte b = EncBuffer[i];
                if (b != 10)
                {
                    buf.Add(b);
                }
            }
        }
 public override int GetMaxByteCount(int charCount)
 {
     return(utf8Encoding.GetMaxByteCount(charCount));
 }