コード例 #1
0
ファイル: DWN_utilitys.cpp プロジェクト: NANIMproj/NANIM_PNNL
int Get_Numbers(const char* ze_string, int* numbers, int variable_max)
       {
       //Prepare the test string for integer retrieval---

       char temp_string[MAX_PHRASE_LENGTH];
       char* temp_pointer;
       strcpy(temp_string, ze_string);
       int string_length = strlen(ze_string);
       
       bool is_num_back;
       bool is_not_num_here;
       for (int index = 1; index < string_length; ++index)
        //Separate the string numbers with NULL characters.
           {
           is_num_back = Is_Number(temp_string[index - 1]);
           is_not_num_here = !(Is_Number(temp_string[index]));
           if (is_num_back && is_not_num_here)
            //Found the end of a number string. Separate it with
			//a null-terminating character---
              {
              temp_string[index] = '\0';             
              }
           }

	   //Grab the numbers, one by one, from the prepared string---
           
       bool is_NULL;
       numbers[0] = Get_Number(temp_string);
	    //Grab the first number from the string.
       int count_temp = 1;
       for (int index = 0; index < (string_length - 1); ++index)
        //Process each separated number.
           {
		   if (count_temp == variable_max)
              {  
			  break;
              }

           is_NULL = (temp_string[index] == '\0');
		    //Found the start of a new number in the string.
           if (is_NULL)
              {
              temp_pointer = &(temp_string[index + 1]);
              numbers[count_temp] = Get_Number(temp_pointer);
              ++count_temp;         
              }     
           }
      
       return count_temp;
       }  
コード例 #2
0
ファイル: DWN_utilitys.cpp プロジェクト: NANIMproj/NANIM_PNNL
int Get_Positive_Number(const char* ze_string)
       {
       if (!Has_Number(ze_string))
          {
          return 0;
          }         
       
       int start_index = Find_First_Integer_From_End(ze_string);
       
       int number = 0;
       int multi_factor = 1;
       int index;
       for (int a = 0; a < MAX_POI_DIGITS; ++a)
           {
           index = start_index - a;
           
           if (index < 0)
              {
              break; 
              }
           
           if (Is_Number(ze_string[index]))
              {
              number += multi_factor * int(ze_string[index] - '0');
              multi_factor *= 10;     
              }
           else
              {
              break;      
              }
           }     
       
       return number;
       }    
コード例 #3
0
ファイル: DWN_utilitys.cpp プロジェクト: NANIMproj/NANIM_PNNL
bool Has_Number_At_End(const char* ze_string)
       {
       bool has_number = FALSEV;
       int char_index = Find_First_Meaningful_Char_From_End(ze_string);
       if (Is_Number(ze_string[char_index]))
          {
          has_number = TRUEV;            
          }
       return has_number;    
       }
コード例 #4
0
//-------------------------------------------------------------------------------------------------
bool classLUA::GetGlobalValue (const char *VarName, int  &iNumber)
{
	this->GetGlobal( VarName );	// 	lua_getglobal (m_pState, VarName)
	if ( Is_Number( -1 ) ) {	//	lua_isstring  (m_pState, -1)
		iNumber = To_Number( -1 );
		return true;
	}

	return false;
}
コード例 #5
0
ファイル: DWN_utilitys.cpp プロジェクト: NANIMproj/NANIM_PNNL
int Find_First_FPChar_From_End(const char* ze_string)
    {
    int string_size = strlen(ze_string);
    int char_index = -1;
	if (string_size > 0)
	   {
	   char_index = string_size - 1;
	   char test_char = ze_string[char_index];
	   while (!( Is_Number(test_char) || (test_char == '.') ) && (char_index > 0))
        //Move past white space.
          {
          --char_index;
          test_char = ze_string[char_index];
          }   
	    if (!( Is_Number(test_char) || (test_char == '.') ))
	      {
		  char_index = -1;
	      }
	    }
    return char_index;                                    
    }
コード例 #6
0
ファイル: DWN_utilitys.cpp プロジェクト: NANIMproj/NANIM_PNNL
bool Contains_Capital_Then_Number_At_Start(const char* ze_string)
	{
	bool contains_capnum = FALSEV;
	if ((strlen(ze_string) > 1))
	   {
	   if (Is_Capital_Letter(ze_string[0]) && Is_Number(ze_string[1]))
	      {
		  contains_capnum = TRUEV;
	      }
	   }
	return contains_capnum;
	}
コード例 #7
0
ファイル: DWN_utilityd.cpp プロジェクト: NANIMproj/NANIM_PNNL
void Show_File(const char* file_name, bool pause_mode)
	 {
	 ifstream show_file(file_name, ios::in);
     if (show_file.is_open())
		{
		char test;
		bool is_letter;
		bool is_number;
		bool is_special;

		cout << endl << "File Read Starts on Next Line: " << endl;
		while (!show_file.eof())
			{
			show_file.get(test);
			is_letter = Is_Text(test);
			is_number = Is_Number(test);
			is_special =   ( (test >= 32) && (test <= 47) ) 
				        || ( (test >= 58) && (test <= 64) )
						|| ( (test >= 91) && (test <= 96) )
						|| ( (test >= 123) && (test <= 126) );
			 //Additional ASCII characters that would be
			 //output as characters, not ASCII integers.
			if (is_letter || is_number || is_special)
			   {
			   cout << test;
			   }
			else
			   {
			   cout << int(test) << " ";
			   }

			if (test == '\n')
			 //Process the end of line.
			   {
			   cout << endl;
			   if (pause_mode)
			     {
				 system("PAUSE");
			     }
			   }

			}
		cout << endl << "End File Read!";
	    show_file.close();
		}
	 }
コード例 #8
0
ファイル: DWN_utilitys.cpp プロジェクト: NANIMproj/NANIM_PNNL
int Get_Number(const char* ze_string)
       {
       if (!Has_Number(ze_string))
          {
          return 0;
          }         
       
       int start_index = Find_First_Integer_From_End(ze_string);
       
       int number = 0;
       int multi_factor = 1;
       int index;
       for (int a = 0; a < MAX_I_DIGITS; ++a)
           {
           index = start_index - a;
           
           if (index < 0)
              {
              break; 
              }
           
           if (Is_Number(ze_string[index]))
              {
              number += multi_factor * int(ze_string[index] - '0');
              multi_factor *= 10;     
              }
           else
              {
              break;      
              }
           }     
       
       if ( (index >= 0) && (ze_string[index] == '-') )
        //Number is meant to be negative.
          {
          number *= -1;                  
          }    
       
       return number;
       }    
コード例 #9
0
ファイル: DWN_utilitys.cpp プロジェクト: NANIMproj/NANIM_PNNL
void Remove_Number(char* ze_string)
     {
     if (!Has_Number_At_End(ze_string))
          {
          return;               
          }         
       
     int string_size = strlen(ze_string);
     int offset = 1;
     int index;
     char current_digit;     
     do
      //Find the first character, moving back from the end of the string, 
      //that is not a number or minus sign.
      {
      ++offset;
      index = string_size - offset;
      current_digit = ze_string[index];               
      }
     while ( (Is_Number(current_digit)) || (current_digit == '-') );
       
     ze_string[index + 1] = '\0';
      //Remove number by placing a NULL terminating character before it.                            
     } 
コード例 #10
0
ファイル: DWN_utilitys.cpp プロジェクト: NANIMproj/NANIM_PNNL
void Change_FPS(char* line, double* change_vals, int num_vals)
     {
	 int num_count = 0;
	 char* line_pointer;
	 int end_number_location;
	 bool found_num, set_space_to_null, is_num_dec, is_num_minus_sign;

	 //Go through string, finding integers to apply changes to, and applying
	 //those changes---

	 for (int a = 0; a < int(strlen(line)); ++a)
		{
		if (a < (int(strlen(line)) - 1))
		   {
           is_num_dec = (line[a] == '.') && (Is_Number(line[a + 1]));
		   is_num_minus_sign = (line[a] == '-') && 
			                   ( Is_Number(line[a + 1]) || (line[a + 1] == '.') );
		   }
		else
		   {
		   is_num_dec = is_num_minus_sign = FALSEV;
		   }
		if (Is_Number(line[a]) || is_num_dec || is_num_minus_sign)
		   {
		   found_num = TRUEV;
		   if ( (a != 0) )
			//Only consider a number that is preceded by white space (and thus set apart).
		      {
			  if (line[a - 1] != ' ')
			     {
				 found_num = FALSEV;
			     }
		      }
		   if (found_num)
		      {
			  line_pointer = &(line[a]);
			  set_space_to_null = FALSEV;
			  for (int b = a; b < int(strlen(line)); ++b)
			     {
			     if (line[b] == ' ')
				    {
					end_number_location = b;
					set_space_to_null = TRUEV;
					break;
				    }
			     }
			  if (set_space_to_null)
			     {
				 line[end_number_location] = '\0';
			     }
			  Change_FP(line_pointer, change_vals[num_count]);   
			  if (set_space_to_null)
				//Undo the change.
			     {
				 line[end_number_location] = ' ';
			     }
			  ++num_count;
		      }
		   }

		if (num_count == num_vals)
		   {
		   break;
		   }
	    }
     }
コード例 #11
0
ファイル: DWN_utilitys.cpp プロジェクト: NANIMproj/NANIM_PNNL
void Change_FP(char* line, double change_val)
     {
	 //Determine the new value of the variable---

	 double orig_val = Get_FP_Number(line);
	 double new_val = orig_val + change_val;

	 //Characterize the floating-point string---

	 int val_size = 0;
	 int after_dec = 0;
	 int before_dec = 0;
	 int number_location;
	 bool num_found = FALSEV;
	 bool period_found = FALSEV;
	 bool is_num_dec;
	 for (int a = 0; a < int(strlen(line)); ++a)
	     {	
		 is_num_dec = (line[a] == '.') && (Is_Number(line[a + 1]));
		 if (is_num_dec)
		    {
			period_found = TRUEV;
		    }
		 if ( (Is_Number(line[a]) || period_found) && !num_found)
		  //Start of the number string has been found.
		    {
			number_location = a;
			num_found = TRUEV;
		    }
		 if (Is_Number(line[a]) && num_found)
	      //Determine how many digits are before and after the decimal place.
		    {
			++val_size;
			if (period_found)
			  {
			  ++after_dec;
			  }
			else
			  {
			  ++before_dec;
			  }
		    }
		 if (!(Is_Number(line[a]) || is_num_dec) && num_found)
		  //End of the number string has been encountered.
		    {
			break;
		    }
	     }

	 //Change the floating-point string to the new value---

	 int dif_from_ones_place = 0;
	 int char_index;
	 double temp_shift;
	 double abs_val = abs(new_val);
	 for (int b = 0; b < val_size; ++b)
	     {
		 char_index = b;
		 dif_from_ones_place = (before_dec - 1) - b;
		 temp_shift = pow(10.0, double(dif_from_ones_place));
		 if (b >= before_dec)
		  //Skip the decimal point.
		    {
			++char_index;
		    } 
		 line[number_location + char_index] = '0' + 
			  char( int(abs_val/temp_shift + FP_ERROR_FIX) % 10 );
	     }

	 //Check for the need to remove a minus sign---

	 if ( (number_location != 0) && (line[number_location - 1] == '-') && (new_val > 0.0) )
	  //If number has been changed from negative value to positive value,
	  //the minus sign must be removed. Reverse case is not allowed here.
	     {
         line[number_location - 1] = '0';
		  //Replace with a zero. Keeps the string length the same.
	     }

	 //Check for a failed change to the FP value---

	 double num_temp = Get_FP_Number(line);
	 if (!Check_FP_Equality(num_temp, new_val))
	     {
		 Show_Warning("AUTOMATION OF FILE TEXT REQUIRES MORE SPACE FOR FP VALUES!");
		 Change_FP(line, -1.0*num_temp);
		  //Zero the FP value.
	     }
     }
コード例 #12
0
ファイル: DWN_utilitys.cpp プロジェクト: NANIMproj/NANIM_PNNL
void Change_Integers(char* line, int* change_vals, int num_vals)
     {
	 int num_count = 0;
	 bool found_num, set_space_to_null, is_minus;
	 char* line_pointer;
	 int end_number_location;

	 //Go through string, finding integers to apply changes to, and applying
	 //those changes---

	 for (int a = 0; a < int(strlen(line)); ++a)
		{
		if (a < (int(strlen(line)) - 1))
		   {
		   is_minus = (line[a] == '-') && (Is_Number(line[a + 1]));
		   }
		else
		   {
		   is_minus = FALSEV;
		   }
		if (Is_Number(line[a]) || is_minus)
		   {
		   found_num = TRUEV;
		   if ( (a != 0) )
			//Only accept numbers that are set apart by white space.
		      {
			  if (line[a - 1] != ' ')
			     {
				 found_num = FALSEV;
			     }
		      }
		   if (found_num)
			//Found a number to apply the change to.
		      {
			  line_pointer = &(line[a]);
			  set_space_to_null = FALSEV;
			  for (int b = a; b < int(strlen(line)); ++b)
			     {
			     if (line[b] == ' ')
				    {
					end_number_location = b;
					set_space_to_null = TRUEV;
					break;
				    }
			     }
			  if (set_space_to_null)
			     {
				 line[end_number_location] = '\0';
			     }
			  Change_Integer(line_pointer, change_vals[num_count]);   
			  if (set_space_to_null)
				//Undo the change.
			     {
				 line[end_number_location] = ' ';
			     }
			  ++num_count;
		      }
		   }

		if (num_count == num_vals)
		   {
		   break;
		   }
	    }
     }
コード例 #13
0
ファイル: DWN_utilitys.cpp プロジェクト: NANIMproj/NANIM_PNNL
void Change_Integer(char* line, int change_val)
     {
	 //Determine the new value of the integer---

	 int orig_val = Get_Number(line);
	 int new_val = orig_val + change_val;

	 //Characterize the integer string---

	 int val_size = 0;
	 int number_location;
	 bool num_found = FALSEV;
	 for (int a = 0; a < int(strlen(line)); ++a)
	     {
		 if (Is_Number(line[a]) && !num_found)
		  //Found starting index for the integer.
		    {
			number_location = a;
			num_found = TRUEV;
		    }
		 if (Is_Number(line[a]) && num_found)
		  //Get string length of the integer.
		    {
			++val_size;
		    }
		 if (!Is_Number(line[a]) && num_found)
		    {
			break;
		    }
	     }

	 //Change the integer string to the new value---

	 int division_factor = 1;
	 int abs_val = abs(new_val);
	 for (int b = 0; b < val_size; ++b)
	     {
		 line[number_location + val_size - 1 - b] = '0' + 
			  char(abs_val/division_factor % 10);
		 division_factor *= 10;
	     }

	 //Check for a minus sign that needs to be removed---

	 if ( (number_location != 0) && (line[number_location - 1] == '-') && (new_val > 0) )
	  //If number has been changed from negative value to positive value,
	  //the minus sign must be removed. Reverse case is not allowed here.
	     {
         line[number_location - 1] = '0';
		  //Replace with a zero. Keeps string length of the number the same.
	     }

	 //Check for a new value that is larger in string space than the original value---

	 int num_temp = Get_Number(line);
	 if (new_val != num_temp)
	     {
		 Show_Warning("AUTOMATION OF FILE TEXT REQUIRES MORE SPACE IN INTEGER NUMBER STRINGS!");
		 Change_Integer(line, -1*num_temp);
		  //Zero the integer string in the case of overflow.
	     }
	 }
コード例 #14
0
ファイル: DWN_utilitys.cpp プロジェクト: NANIMproj/NANIM_PNNL
double Get_FP_Number(const char* ze_string)
       {
       if (!Has_Number(ze_string))
          {
          return 0.00;               
          }         
       
       int start_index = Find_First_FPChar_From_End(ze_string);
       
	   //Find decimal point, if present---

       int index, decimal_index;
       bool has_decimal = FALSEV;
       for (int a = 0; a < MAX_FP_DIGITS; ++a)
        //Find the decimal point, if present.
           {
           index = start_index - a; 
           
           if (index < 0)
            //Don't want to explore negative space.
              {
              break;  
              }
           else if (ze_string[index] == '.')
              {
              decimal_index = index;
              has_decimal = TRUEV;
			  break;
              }    
		   else if (!Is_Number(ze_string[index]))
		    //No period found.
			  {
			  break;
			  }
           }	
	          
	   //Evaluate the base 10 exponent for the
	   //first number in the string---

       double number = 0.00;
       double multi_factor = 1.0;
       if (has_decimal)
          {
          int num_dec_digits = start_index - decimal_index;
		   //Get number of digits after the decimal place.
          multi_factor = pow(10.0, -1*num_dec_digits);
           //Determine base 10 power for the last digit in the FP number string.
          }
       
	   //Determine the floating-point value of the string number---

       for (int a = 0; a < MAX_FP_DIGITS; ++a)
           {
           index = start_index - a;
           
		   if (index < 0)
			  {
			  break;
			  }

           if (has_decimal && (index == decimal_index))
            //Do not mathematically evalute the decimal place.
              {
              continue;              
              }
			
           if (Is_Number(ze_string[index]))
              {
              number += multi_factor * double(ze_string[index] - '0');
              multi_factor *= 10.0;     
              }
           else
              {
              break;  
              }
           }     
       
       if ( (index >= 0) && (ze_string[index] == '-'))
        //Number is negative.
          {
          number *= -1.0;                  
          }    
       
       return number;
       }