// file: pfil_token_1.cc
//

// isip include files
//
#include "param_file.h"
#include "param_file_constants.h"

// system include files
//
#include <stdlib.h>
#include <string.h>

// method: token_count_cc
//
// arguments:
//  int_4& num_values: (output) size of array of values
//  char_1 delimiter: (input) delimiter character
//  char_1* string_to_tokenize: (input) string to tokenize
//
// return: a logical_1 indicating status
//
// this method counts the number of times a character appears in the
// given string. note that if you tokenize you need to use 1 + num
// array positions, since delimiters are seperators.
//
logical_1 Param_file::token_count_cc(int_4& num_values_a, char_1 delimiter_a,
				   char_1* string_to_tokenize_a) {
				   

  // check arguments, allocate values_a if necessary
  //
  if (string_to_tokenize_a == (char_1*)NULL) {
    error_handler_cc((char_1*)"token_count_cc",
		     (char_1*)"the input string is NULL");
  }    
  
  num_values_a = 0;
  char_1* temp = string_to_tokenize_a;

  temp = (char_1*)strchr((char*)temp, (char)delimiter_a);
  
  // count the tokens in a non-destructive manner
  //
  while (temp != (char_1*)NULL) {
    temp ++;
    temp = (char_1*)strchr((char*)temp, (char)delimiter_a);
    num_values_a++;
  }
    
  // exit gracefully
  //
  return ISIP_TRUE;  
}
