Пример #1
0
Int32 Attributes::trimFillerSpaces
     (const char* buf, Int32 precision, Int32 maxBufLen, CharInfo::CharSet cs)
{
#if 0 /* All callers have already checked this for speed reasons. May need this if SJIS supported later. */
  if (cs == CharInfo::UTF8)
#endif
  {
     if ( precision > 0 )
     {
        Int32 endOff = lightValidateUTF8Str(buf, maxBufLen, precision, FALSE);
        if (endOff >= 0)   // If no error
            return (endOff);
        // else bad UTF8 chars will get detected later by caller
     }
  }
  return (maxBufLen);
}
// Generate a lock name from the input simple object name and the given suffix.
// If the generated name is longer than 128 NAWchar's, remove the extra char's
// from the simple object name part in the generated lock name without changing
// the suffix.
//
static NABoolean generateLockName(const char * objInternal1PartName, // in UTF-8 format
                                  const char * lockSuffix, // contains 7-bit ASCII chars only
                                  char * lockInternal1PartNameOutBuf, // in UTF-8 format
                                  Int32 lockInInternal1PartNameOutBufLen) // in bytes
{
  Int32 objInt1PartNameLen = str_len(objInternal1PartName);
  char *tempPtr;
  char buf[20];
  Int32 hashValue = 0;
  Int32 suffixLen = str_len(lockSuffix)+8; // 8 characters for hashvalue of truncated
                                           // object name
  // More than 60 characters won't be truncated and hence 8 characters should be
  // good enough
  Int32 allowedLen = lightValidateUTF8Str(objInternal1PartName,
                                          objInt1PartNameLen,
                      // max allowed chars in UTF-8 (same as allowed bytes in ISO)
                            ComMAX_1_PART_INTERNAL_ISO88591_NAME_LEN -suffixLen);

  if (lockInternal1PartNameOutBuf == NULL ||
      allowedLen + suffixLen >= lockInInternal1PartNameOutBufLen)
    return FALSE;
  if (allowedLen < objInt1PartNameLen)
  {
     // Just simple hashing by adding the byte contents
     tempPtr = (char *)objInternal1PartName + allowedLen;
     for (; *tempPtr != '\0';)
        hashValue += *tempPtr++;
  }
  str_cpy_all(lockInternal1PartNameOutBuf,
              objInternal1PartName,
              allowedLen);
  lockInternal1PartNameOutBuf[allowedLen] = '\0';
  if (hashValue > 0)
  {
     str_sprintf(buf, "%d", hashValue); 
     buf[8] = '\0';
     strcat(lockInternal1PartNameOutBuf, buf);
  }
  strcat(lockInternal1PartNameOutBuf, lockSuffix);
  return TRUE;
}