Logo Search packages:      
Sourcecode: maxdb-7.5.00 version File versions  Download package

externC tsp78ConversionResult eo602_ConvertPascalStringToUTF8Unicode ( tsp00_Int4  msgEnconding,
const tsp00_Byte *  msgTextPascal,
tsp00_Uint4  msgTextSizeInBytes,
tsp00_Byte *  bufferUTF8,
tsp00_Uint4  bufferSizeInBytes 
)

Convert a given PascalString into UTF8

PascalString is padded with spaces up to msgTextSizeInBytes. The specified encoding is used, to select the conversion routine. Convertion result is returned. Even on error, the result buffer is always zero terminated!!!

Parameters:
msgEncoding [in] The given encoding on msgTextPascal
msgTextPascal [in] The space padded string (not zero terminated)
msgTextSizeInBytes [in] The number of bytes in msgTextPascal
bufferUTF8 [out] The target buffer
bufferSizeInBytes [in] The target buffer size value The convertion result

Definition at line 110 of file veo602.c.

References t_sp77encoding::EncodingType.

{
  tsp78ConversionResult result = sp78_Ok;
  register const tsp00_Byte *spaceCharPtr;
                 tsp00_Uint4 stepWidth;
                 tsp00_Uint4 trimmedTextSizeInBytes;

  if ( msgEncoding == csp_unicode_native )
  {
    msgEncoding = sp77nativeUnicodeEncoding()->EncodingType;
  }

  /* Find stepWidth and set spaceCharPtr to last possible space position */
  switch( msgEncoding )
  {
  case csp_unicode:
    stepWidth = 2;
    spaceCharPtr = msgTextPascal + msgTextSizeInBytes - 1;
    break;
  case csp_unicode_swap:
    stepWidth = 2;
    spaceCharPtr = msgTextPascal + msgTextSizeInBytes - stepWidth;
    break;
  default:
    stepWidth = 1;
    spaceCharPtr = msgTextPascal + msgTextSizeInBytes - 1;
    break;
  }

  trimmedTextSizeInBytes = msgTextSizeInBytes;

  /* Loop until begin of string or no more spaces found */
  while ( (spaceCharPtr >= msgTextPascal)
       && (*spaceCharPtr == ' ') )
  {
    spaceCharPtr -= stepWidth;
    trimmedTextSizeInBytes -= stepWidth;
  }

  if ( trimmedTextSizeInBytes > 0 )
  {
    if ( msgEncoding != csp_unicode && msgEncoding != csp_unicode_swap )
    {
      /* Prevent UTF8 buffer overflow... */
      if ( trimmedTextSizeInBytes > bufferSizeInBytes )
      {
        trimmedTextSizeInBytes = bufferSizeInBytes - 1;
      }

      /* We trust the caller... ASCII-7bit and UTF8 are simply copied */
      memcpy(bufferUTF8, msgTextPascal, trimmedTextSizeInBytes);

      /* Terminate buffer with zero */
      bufferUTF8[trimmedTextSizeInBytes] = 0;
    }
    else
    {
      const tsp77encoding *UCS2encoding;
      tsp00_Uint4 srcBytesParsed;
      tsp00_Uint4 destBytesWritten;
      
      UCS2encoding = ( msgEncoding == csp_unicode_swap 
                     ? sp77encodingUCS2Swapped : sp77encodingUCS2 );

      result = sp78convertString( sp77encodingUTF8,
                                  bufferUTF8,
                                  bufferSizeInBytes,
                                  &destBytesWritten,
                                  true, /* Make sure result is 0 terminated */
                                  UCS2encoding,
                                  msgTextPascal, 
                                  trimmedTextSizeInBytes,
                                  &srcBytesParsed );
      bufferUTF8[bufferSizeInBytes-1] = 0;
    }
  }
  else
  {
    /* only spaces found, so we return an empty string */
    bufferUTF8[0] = 0;
  }

  return result;
}


Generated by  Doxygen 1.6.0   Back to index