// returned error code described in w:/common/csconvert.h
Int32 ComAnsiNameToUCS2 ( const char * inAnsiNameInMBCS      // in  - valid name in default ANSI name char set
                        , NAWchar *    outBuf4AnsiNameInUCS2 // out - out buffer
                        , const Int32  outBufSizeInNAWchars  // in  - out buffer max len in NAWchars
                        , const NABoolean padWithSpaces      // in  - default is FALSE
                        )
{
  if (outBuf4AnsiNameInUCS2 == NULL || outBufSizeInNAWchars <= 0)
    return -2; // CNV_ERR_BUFFER_OVERRUN - No output buffer or not big enough
  if (inAnsiNameInMBCS == NULL)
    return -3; // CNV_ERR_NOINPUT - No input buffer or input cnt <= 0 
  else if (strlen(inAnsiNameInMBCS) == 0)
  {
    outBuf4AnsiNameInUCS2[0] = 0;
    return 0; // success
  }

  Int32 inAnsiNameLenInBytes = (Int32)strlen(inAnsiNameInMBCS);
  Int32 outBufSizeInBytes = outBufSizeInNAWchars * BYTES_PER_NAWCHAR;
  Int32 ansiNameCharSet = (Int32)ComGetNameInterfaceCharSet();
  Int32 convAnsiNameCS  = (Int32)/*cnv_charset*/convertCharsetEnum (ansiNameCharSet);
  char * pFirstByteOfTheUntranslatedChar = NULL;
  UInt32 iTranslatedStrLenInBytes = 0;
  UInt32 iNumberOfTranslatedChars = 0;
  Int32  iConvErrorCode = LocaleToUTF16
    ( cnv_version1                         // in  - const enum cnv_version version
    , inAnsiNameInMBCS                     // in  - const char *  in_bufr
    , (Int32) inAnsiNameLenInBytes         // in  - const Int32   in_len_in_bytes
    , (const char *) outBuf4AnsiNameInUCS2 // out - const char *  out_bufr
    , (Int32)(outBufSizeInBytes -  BYTES_PER_NAWCHAR) // in - const Int32 out_bufr_max_len_in_bytes
    , (cnv_charset) convAnsiNameCS         // in  - enum cnv_charset conv_charset
    , pFirstByteOfTheUntranslatedChar      // out - char * &      first_untranslated_char
    , &iTranslatedStrLenInBytes            // out - UInt32 *      output_data_len_p
    , (Int32) 0                            // in  - const Int32   conv_flags
    , (Int32) FALSE                        // in  - const Int32   addNullAtEnd_flag
    , &iNumberOfTranslatedChars            // out - UInt32 *      translated_char_cnt_p
 // , 0xffffffff                           // in  - UInt32 max_chars_to_convert = 0xffffffff
    );
  Int32 outStrLenInNAWchars = iTranslatedStrLenInBytes / BYTES_PER_NAWCHAR;
  outBuf4AnsiNameInUCS2[outStrLenInNAWchars]  = 0; // Append the NULL terminator

  if (iConvErrorCode == 0 && padWithSpaces)
  {
    wc_str_pad ( (NAWchar *) &outBuf4AnsiNameInUCS2[outStrLenInNAWchars] // out - NAWchar *str
               , outBufSizeInNAWchars - outStrLenInNAWchars - 1 // in  - Int32 length
               , unicode_char_set::SPACE   // in  - NAWchar padchar = unicode_char_set::SPACE
               );
    outBuf4AnsiNameInUCS2[outBufSizeInNAWchars-1] = 0; // Append the NULL terminator
  }
  return iConvErrorCode;
}
// -----------------------------------------------------------------------
// Translate ANSI SQL names from Default ANSI SQL Name character set
// to UCS-2 encoding values.  The contents of the outWcs parameter is
// clear and set to the newly computed UCS2 string
// -----------------------------------------------------------------------
void CmAnsiNameToUCS2(const NAString &inMbs, NAWString &outWcs)
{
  outWcs.remove(0); // set to an empty string
  if (inMbs.length() <= 0)
  {
    return;
  }
  NAWString * pTargetNAWString =
    charToUnicode ( (Lng32)ComGetNameInterfaceCharSet() // in - Lng32        strCharSet
                  , inMbs.data()                        // in - const char * str
                  , (Int32)inMbs.length()               // in - Int32        len
                  , (NAMemory *)STMTHEAP                // in - NAMemory *   h
                  );
  ComASSERT(pTargetNAWString != NULL AND pTargetNAWString->length() > 0 AND
             pTargetNAWString->length() <= ComMAX_ANSI_IDENTIFIER_INTERNAL_LEN/*in NAWchars*/);
  outWcs.append(pTargetNAWString->data(), pTargetNAWString->length());
  delete pTargetNAWString;
}
// -----------------------------------------------------------------------
// Translate ANSI SQL names from UCS-2/UTF-16 encoding values to
// the Default ANSI SQL Name character set.
// -----------------------------------------------------------------------
void CmAnsiNameToUTF8(const NAWString &inWcs, NAString &outMbs)
{
  outMbs.remove(0); // set to an empty string
  if (inWcs.length() <= 0)
  {
    return;
  }

  NAString *pConvStr =
    unicodeToChar ( inWcs.data()                        // in - const char * str
                  , (Int32)inWcs.length()               // in - Int32        len
                  , (Lng32)ComGetNameInterfaceCharSet() // in - Lng32        strCharSet
                  , (NAMemory *)STMTHEAP                // in - NAMemory *   h
                  , FALSE                               // in - NABoolean allowInvalidChar
                  );
  if (pConvStr != NULL AND pConvStr->length() > 0)
  {
    outMbs = *pConvStr;
  }
  delete pConvStr;
}
Int32 ComAnsiNameToUTF8 ( const NAWchar * inAnsiNameInUCS2  // in  - valid ANSI SQL name in UCS2
                        , char *      outBuf4AnsiNameInMBCS // out - out buffer
                        , const Int32 outBufSizeInBytes     // in  - out buffer max len in bytes
                        )
{
  if (outBuf4AnsiNameInMBCS == NULL || outBufSizeInBytes <= 0)
    return -2; // CNV_ERR_BUFFER_OVERRUN - No output buffer or not big enough
  if (inAnsiNameInUCS2 == NULL)
    return -3; // CNV_ERR_NOINPUT - No input buffer or input cnt <= 0 
  else if (NAWstrlen(inAnsiNameInUCS2) == 0)
  {
    outBuf4AnsiNameInMBCS[0] = 0;
    return 0; // success
  }

  const Int32 inAnsiNameInBytes = NAWstrlen(inAnsiNameInUCS2) * BYTES_PER_NAWCHAR;
  Int32 ansiNameCharSet = (Int32)ComGetNameInterfaceCharSet();
  Int32 convAnsiNameCS  = (Int32)/*cnv_charset*/convertCharsetEnum (ansiNameCharSet);
  char * pFirstByteOfTheUntranslatedChar = NULL;
  UInt32 iOutStrLenInBytesIncludingNull = 0;
  UInt32 iNumTranslatedChars = 0;
  Int32  iConvErrorCode = UTF16ToLocale
    ( cnv_version1                         // in     - const enum cnv_version
    , (const char *) inAnsiNameInUCS2      // in     - const char *     in_bufr
    , (Int32) inAnsiNameInBytes            // in     - const Int32      in_len_in_bytes
    , (const char *) outBuf4AnsiNameInMBCS // in/out - const char *     out_bufr
    , (Int32) outBufSizeInBytes            // in     - const Int32      out_bufr_max_len_in bytes
    , (cnv_charset) convAnsiNameCS         // in     - enum cnv_charset conv_charset
    , pFirstByteOfTheUntranslatedChar      // out    - char * &         first_untranslated_char
    , &iOutStrLenInBytesIncludingNull      // out    - UInt32 *         output_data_len_p
    , 0                                    // in     - const Int32      conv_flags
    , (Int32) TRUE                         // in     - const Int32      add_null_at_end_Flag
    , (Int32) FALSE                        // in     - const int32      allow_invalids
    , &iNumTranslatedChars                 // out    - UInt32 *         translated_char_cnt_p
    , (const char *) NULL /* i.e. "?" */   // in     - const char *     substitution_char = NULL
    );

  return iConvErrorCode;
}