Пример #1
0
        public static RC MemTranslate(Mem mem, TEXTENCODE desiredEncode)
        {
            Debugger.Break(); // TODO -
            int len;          // Maximum length of output string in bytes

            //unsigned char *zOut; // Output buffer
            //unsigned char *zIn; // Input iterator
            //unsigned char *zTerm; // End of input
            //unsigned char *z; // Output iterator
            //unsigned int c;

            Debug.Assert(mem.Ctx == null || MutexEx.Held(mem.Ctx.Mutex));
            Debug.Assert((mem.Flags & MEM.Str) != 0);
            Debug.Assert(mem.Encode != desiredEncode);
            Debug.Assert(mem.Encode != 0);
            Debug.Assert(mem.N >= 0);

#if TRANSLATE_TRACE && DEBUG
            //{
            //    char[] buf = new char[100];
            //    MemPrettyPrint(mem, zBuf);
            //    fprintf(stderr, "INPUT:  %s\n", zBuf);
            //}
#endif

            Debugger.Break();
            // If the translation is between UTF-16 little and big endian, then all that is required is to swap the byte order. This case is handled differently from the others.
            //if (mem.Encode != TEXTENCODE.UTF8 && desiredEncode != TEXTENCODE.UTF8)
            //{
            //    u8 temp;
            //    RC rc = MemMakeWriteable(mem);
            //    if (rc != RC.OK)
            //    {
            //        Debug.Assert(rc == RC.NOMEM);
            //        return RC.NOMEM;
            //    }
            //    in_ = mem.Z;
            //    term_ = in_[mem.N & ~1];
            //    while (in_ < term_)
            //    {
            //        temp = in_;
            //        in_ = (in_ + 1);
            //        in_++;
            //        in_++ = temp;
            //    }
            //    mem.Encode = desiredEncode;
            //    goto translate_out;
            //}

            // Set len to the maximum number of bytes required in the output buffer.
            if (desiredEncode == TEXTENCODE.UTF8)
            {
                // When converting from UTF-16, the maximum growth results from translating a 2-byte character to a 4-byte UTF-8 character.
                // A single byte is required for the output string nul-terminator.
                mem.N &= ~1;
                len    = mem.N * 2 + 1;
            }
            else
            {
                // When converting from UTF-8 to UTF-16 the maximum growth is caused when a 1-byte UTF-8 character is translated into a 2-byte UTF-16
                // character. Two bytes are required in the output buffer for the nul-terminator.
                len = mem.N * 2 + 2;
            }

            Debugger.Break();
            // Set zIn to point at the start of the input buffer and zTerm to point 1 byte past the end.
            // Variable zOut is set to point at the output buffer, space obtained from sqlite3_malloc().

            //zIn = (u8*)pMem.z;
            //zTerm = &zIn[pMem->n];
            //zOut = sqlite3DbMallocRaw(pMem->db, len);
            //if( !zOut ){
            //  return SQLITE_NOMEM;
            //}
            //z = zOut;

            //if( pMem->enc==SQLITE_UTF8 ){
            //  if( desiredEnc==SQLITE_UTF16LE ){
            //    /* UTF-8 -> UTF-16 Little-endian */
            //    while( zIn<zTerm ){
            ///* c = sqlite3Utf8Read(zIn, zTerm, (const u8**)&zIn); */
            //READ_UTF8(zIn, zTerm, c);
            //      WRITE_UTF16LE(z, c);
            //    }
            //  }else{
            //    Debug.Assert( desiredEnc==SQLITE_UTF16BE );
            //    /* UTF-8 -> UTF-16 Big-endian */
            //    while( zIn<zTerm ){
            ///* c = sqlite3Utf8Read(zIn, zTerm, (const u8**)&zIn); */
            //READ_UTF8(zIn, zTerm, c);
            //      WRITE_UTF16BE(z, c);
            //    }
            //  }
            //  pMem->n = (int)(z - zOut);
            //  *z++ = 0;
            //}else{
            //  Debug.Assert( desiredEnc==SQLITE_UTF8 );
            //  if( pMem->enc==SQLITE_UTF16LE ){
            //    /* UTF-16 Little-endian -> UTF-8 */
            //    while( zIn<zTerm ){
            //      READ_UTF16LE(zIn, zIn<zTerm, c);
            //      WRITE_UTF8(z, c);
            //    }
            //  }else{
            //    /* UTF-16 Big-endian -> UTF-8 */
            //    while( zIn<zTerm ){
            //      READ_UTF16BE(zIn, zIn<zTerm, c);
            //      WRITE_UTF8(z, c);
            //    }
            //  }
            //  pMem->n = (int)(z - zOut);
            //}
            //*z = 0;
            //Debug.Assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len );

            //sqlite3VdbeMemRelease(pMem);
            //pMem->flags &= ~(MEM_Static|MEM_Dyn|MEM_Ephem);
            //pMem->enc = desiredEnc;
            //pMem->flags |= (MEM_Term|MEM_Dyn);
            //pMem.z = (char*)zOut;
            //pMem.zMalloc = pMem.z;

            //translate_out:
#if TRANSLATE_TRACE && DEBUG
            //{
            //    char[] zBuf = new char[100];
            //    MemPrettyPrint(mem, zBuf);
            //    fprintf(stderr, "OUTPUT: %s\n", zBuf);
            //}
#endif
            return(RC.OK);
        }
Пример #2
0
 public static TYPE Value_Type(Mem p)
 {
     return(p.Type);
 }
Пример #3
0
 public static void Result_Value(FuncContext fctx, Mem value)
 {
     Debug.Assert(MutexEx.Held(fctx.S.Ctx.Mutex));
     MemCopy(fctx.S, value);
 }
Пример #4
0
 public static string Value_Text(Mem p)
 {
     return(ValueText(p, TEXTENCODE.UTF8));
 }
Пример #5
0
 public static string Value_Text16le(Mem p)
 {
     return(ValueText(p, TEXTENCODE.UTF16LE));
 }
Пример #6
0
 public static long Value_Int64(Mem p)
 {
     return(IntValue(p));
 }
Пример #7
0
 public static int Value_Int(Mem p)
 {
     return((int)IntValue(p));
 }
Пример #8
0
 public static double Value_Double(Mem p)
 {
     return(RealValue(p));
 }
Пример #9
0
 public static int Balue_Bytes16(Mem p)
 {
     return(ValueBytes(p, TEXTENCODE.UTF16NATIVE));
 }
Пример #10
0
 public static int Value_Bytes(Mem p)
 {
     return(ValueBytes(p, TEXTENCODE.UTF8));
 }