コード例 #1
0
Int32 main(Int32 argc, char** argv)
{
      charBuf* latin1 = 0;

      NAWchar wbuf[1];
      NAWcharBuf uni(wbuf, 1);

      for ( NAWchar i=0; i<0xff; i++ ) {
         wbuf[0] = i;
         latin1 = unicodeToISO88591(uni, 0, latin1);
         if ( latin1 && latin1->data()[0] != i ) {
               printf("u2l1 test failed\n");
               return 1;
         }
      }

      unsigned char buf[1];
      charBuf ascii(buf, 1);
      NAWcharBuf* unicode = 0;

      for ( unsigned char j=0; j<0xff; j++ ) {
         buf[0] = j;
         unicode = ISO88591ToUnicode(ascii, 0, unicode);

         if ( unicode && unicode->data()[0] != j ) {
               printf("l12u test failed\n");
               return 1;
            }
      }

      wbuf[0] = 0xC0F3; // negative test
      latin1 = unicodeToISO88591(uni, 0, latin1);
      if ( latin1 ) 
         printf("negative u2l1 test failed\n");

      printf("test pass\n");
  
     return 0;
}
コード例 #2
0
////////////////////////////////////////////
// get the name of a SQL object id in 
// Unicode.
////////////////////////////////////////////
SQLCLI_LIB_FUNC
NAWchar* getIdInWchar(SQLCLI_OBJ_ID* x)
{
   static NAWcharBuf * buf = new NAWcharBuf(MAX_CHAR_SET_STRING_LENGTH+1);

   if ( x == 0 ) return 0;

   const char* charset = getIdCharSet(x);
   NAWcharBuf* res = 0;

   if ( charset == SQLCHARSETSTRING_UNICODE || str_cmp(charset, SQLCHARSETSTRING_UNICODE,str_len(charset)) == 0 ) {
     return (NAWchar*)(x -> identifier);
   }
   if ( charset == SQLCHARSETSTRING_ISO88591 || str_cmp(charset, SQLCHARSETSTRING_ISO88591,str_len(charset)) == 0 ) {
     res = ISO88591ToUnicode(
	charBuf((unsigned char*)(x->identifier), getIdLen(x)), 
	(CollHeap *)0,
	buf
		      );
     return (res) ? (res -> data()) : 0;
   }
   return 0;
}
コード例 #3
0
////////////////////////////////////////////
// get the name of a SQL module id in 
// Unicode.
////////////////////////////////////////////
SQLCLI_LIB_FUNC
NAWchar* getModNameInWchar(const SQLMODULE_ID* m)
{
   static NAWcharBuf * buf = new NAWcharBuf(MAX_CHAR_SET_STRING_LENGTH+1);

   if ( m == 0 ) return 0;

   const char* charset = getModCharSet(m);
   NAWcharBuf* res = 0;

   if ( charset == SQLCHARSETSTRING_UNICODE || str_cmp(charset, SQLCHARSETSTRING_UNICODE,str_len(charset)) == 0 ) {
     return (NAWchar*)(m -> module_name);
   }
   if ( charset == SQLCHARSETSTRING_ISO88591 || str_cmp(charset, SQLCHARSETSTRING_ISO88591,str_len(charset)) == 0 ) {
     res = ISO88591ToUnicode(
	charBuf((unsigned char*)(m->module_name), getModNameLen(m)), 
	(CollHeap *)0,
	buf
		      );
     return (res) ? (res -> data()) : 0;
   }
   return 0;
}
コード例 #4
0
Lng32 
LocaleStringToUnicode(Lng32 charset, const char* str, Lng32 strLen, 
                      NAWchar* wstrBuf, Lng32 wstrBufLen, NABoolean addNullAtEnd)
{
   // Changed the algorithm to call the new LocaleToUTF16() but keep
   // the old call to old ISO88591ToUnicode() when the character set is
   // ISO88591.  We want to keep the old "pass through" behavior so
   // Use of ISO 8859-15 characters (a.k.a., Latin-9) in
   // CHARACTER SET ISO88591 target column continues to work.

   if (charset == (Lng32) CharInfo::ISO88591)
   {
     NAWcharBuf wcbuf(wstrBuf, wstrBufLen);
     NAWcharBuf* wcbufPtr = &wcbuf;
     NAWcharBuf* res = 0;
     res = ISO88591ToUnicode(
                charBuf((unsigned char*)str, strLen), 0,
                wcbufPtr, addNullAtEnd
                        );
     return (res) ? res->getStrLen() : 0;
   }

   //
   // else (charset != (Lng32) CharInfo::ISO88591)
   //

   enum cnv_charset convCS = convertCharsetEnum(charset);
   if (convCS == cnv_UnknownCharSet)
     return 0; // nothing we can do; exit the routine

   UInt32 outBufSizeInBytes = wstrBufLen*sizeof(NAWchar);
   char * pFirstUntranslatedChar = NULL;
   UInt32 outputDataLenInBytes = 0;
   UInt32 translatedtCharCount = 0;
   Int32 convStatus =
     LocaleToUTF16(cnv_version1,           // const enum cnv_version version
                   str,                    // const char *in_bufr
                   strLen,                 // const int in_len in # of bytes
                   (const char *)wstrBuf,  // const char *out_bufr
                   (const Int32)outBufSizeInBytes,
                   convCS,       // enum cnv_charset charset -- output charset
                   pFirstUntranslatedChar, // char * & first_untranslated_char
                   &outputDataLenInBytes,  // unsigned int *output_data_len_p
                   0,                      // const int cnv_flags (default is 0)
                   (const Int32)addNullAtEnd,
                   &translatedtCharCount); // unsigned int *translated_char_cnt_p

   UInt32 outLenInW = outputDataLenInBytes/sizeof(NAWchar);
   if (convStatus == 0) // success
     return outLenInW;  // include the NULL terminator if (addNullAtEnd == TRUE)

   // If convStatus != 0, LocaleToUTF16 will not add the NULL terminator
   if (addNullAtEnd && wstrBuf && wstrBufLen > 0)
   {
     if (outLenInW < (UInt32)wstrBufLen)
       wstrBuf[outLenInW] = WIDE_('\0');
     else
     {
       // assume the specified wstrBufLen includes room for the NULL terminator
       // when the passed-in addNullAtEnd parameter is set to TRUE
       wstrBuf[wstrBufLen-1] = WIDE_('\0');
     }
   }
   return 0; // tell the caller not to use data in wstrBuf
}