예제 #1
0
CubitSimpleAttrib::CubitSimpleAttrib(const CubitString new_character_type,
                                     const CubitString new_string_data,
                                     const CubitString new_more_string_data,
                                     const int* new_integer_data,
                                     const double* new_double_data)
{
  assert(new_character_type.length() > 0);

  stringDataList.push_back(new_character_type);

  if (new_string_data.length()) {
    stringDataList.push_back(new_string_data);
  }
  
  if (new_more_string_data.length()) {
    stringDataList.push_back(new_more_string_data);
  }
  
  if(new_double_data)
    doubleDataList.push_back( *new_double_data );
  if(new_integer_data)
    intDataList.push_back( *new_integer_data );

  return;
}
예제 #2
0
CubitStatus RefEntityName::clean(CubitString &raw_name)
{
  if (raw_name == "")
    return CUBIT_FAILURE;

    // A valid name consists of alphanumeric characters plus '.', '_', '-', or '@'
  CubitStatus found_invalid_character = CUBIT_FAILURE;

  // Initial character must be alphabetic or "_".
  char c = raw_name.get_at(0);
  if (!is_valid_first_char(c)) {
    if (is_valid_first_char(get_character("replace")))
      raw_name.put_at(0, get_character("replace"));
    else
      raw_name.put_at(0, '_');
    found_invalid_character = CUBIT_SUCCESS;
  }
  
  for (unsigned int i = 1; i < raw_name.length(); i++) {
    c = raw_name.get_at(i);
    if (!is_valid_char(c)) {
      found_invalid_character = CUBIT_SUCCESS;
      raw_name.put_at(i, get_character("replace"));
    }
  }
  return found_invalid_character;
}
예제 #3
0
CubitString CubitUtil::get_temporary_filename()
{

  CubitString ret_str;

#ifdef WIN32
  
  //get a place to put the temporary file
  CubitString temp_path = get_temp_directory();

  // make an empty temporary and return the name for it
  wchar_t temp_file_name[MAX_PATH];
  if( GetTempFileNameW(CubitString::toUtf16(temp_path.c_str()).c_str(), L"CBT", 0, temp_file_name) != 0 )
    ret_str = CubitString::toUtf8(temp_file_name); 

#else

  CubitString tmpdir = get_temp_directory();
  const char* filepattern = "CBT.XXXXXX";
    //needs to be two longer because of the "/"?
  char *temp_file_name = new char[tmpdir.length() + strlen(filepattern) + 2];
  sprintf(temp_file_name, "%s/%s", tmpdir.c_str(), filepattern);

  // make an empty file and return the name for it
  int fd = mkstemp(temp_file_name);
  if( fd != -1 )
  {
    ret_str = temp_file_name; 
    // release the open done by mkstemp,
    // temporary file still exists
    close(fd);
  }
  delete [] temp_file_name;

#endif

  return ret_str;
}
예제 #4
0
CubitStatus RefEntityName::generate_unique_name(CubitString &name)
{
  // The method used to generate a unique name is to append
  // 'suffixCharacter' and
  // a letter from A-Z, a-z, or 0-9 to the end of name.
  // If none of these produce a unique name, CUBIT_FALSE is returned.

  CubitString alphabet =
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  CubitString suffix("  ");
  suffix.put_at(0, suffixCharacter);
  
  CubitString internal = name;

  // See if there is an suffixCharacter sign in name already. If so, is it
  // the second to the last character in the string.
  if (name.length() < 2 ||
      name.get_at(name.length()-2) != suffixCharacter) {
    // Name does not contain suffixCharacter at correct location, add one on.
    internal += suffix;
  }
  
  CubitStatus found_unique = CUBIT_FAILURE;
  int continue_trying = CUBIT_TRUE;

  while (!found_unique && continue_trying) {
	 
    continue_trying = CUBIT_FALSE;
    int name_length = internal.length();
    unsigned int number_tested = 0;
    for (unsigned int i=0; i < alphabet.length(); i++) {
      internal.put_at(name_length-1, (char)alphabet.get_at(i));
      if (!nameEntityList.move_to(internal)) {
	found_unique = CUBIT_SUCCESS;
	break;
      }
      number_tested++;
    }

    if (number_tested == alphabet.length()) {
      // All suffixes used. Add another suffixCharacter and try again
      // Name will look like 'Name@@1' or 'Name@@@1'...
      // Find LAST suffixCharacter in name
      int ch;
      for (ch = (int)(internal.length())-1; ch >= 0; ch--) {
	if (internal.get_at(ch) == suffixCharacter) {
	  break;
	}
      }
      if (internal.get_at(ch) == suffixCharacter) {
	// Add another suffixCharacter at ch+1
	// Assured that position ch+1 exists or we wouldn't be here
	internal.put_at(ch+1, suffixCharacter);
	if (ch+2 < (int)internal.length())
	  internal.put_at(ch+2, ' ');
	else
	  internal += " ";
	continue_trying = CUBIT_TRUE;
      }
    }
  }
  
  if (found_unique)
    name = internal;

  return found_unique;
}