Exemplo n.º 1
0
Arquivo: csv.c Projeto: clownfysh/cf
cf_x_case_array_t *cf_x_file_csv_get_field_by_index_as_array
(cf_x_file_csv_t *csv, unsigned long field_index)
{
  assert(csv);
  cf_x_case_array_t *array;
  unsigned long each_object;
  char *value;
  char *value_copy;

  array = cf_x_case_array_create(csv->object_count, cf_x_core_string_compare,
      cf_x_core_string_copy, cf_x_core_string_destroy);
  if (array) {
    for (each_object = 0; each_object < csv->object_count; each_object++) {
      value = get_value_by_index_as_string(csv, each_object, field_index);
      value_copy = strdup(value);
      if (value_copy) {
        cf_x_case_array_add(array, each_object, value_copy);
      } else {
        cf_x_core_trace("strdup");
        cf_x_case_array_destroy(array);
        array = NULL;
        break;
      }
    }
  } else {
    cf_x_core_trace("x_case_array_create");
  }

  return array;
}
Exemplo n.º 2
0
Arquivo: csv.c Projeto: clownfysh/cf
unsigned short cf_x_file_csv_get_value_by_index_as_unsigned_short
(cf_x_file_csv_t *csv, unsigned long object_index, unsigned long field_index)
{
  assert(csv);
  char *value_string;
  unsigned short value_unsigned_short;

  value_string = get_value_by_index_as_string(csv, object_index, field_index);
  value_unsigned_short = atoi(value_string);

  return value_unsigned_short;
}
Exemplo n.º 3
0
Arquivo: csv.c Projeto: clownfysh/cf
long cf_x_file_csv_get_value_by_index_as_long(cf_x_file_csv_t *csv,
    unsigned long object_index, unsigned long field_index)
{
  assert(csv);
  char *value_string;
  long value_long;

  value_string = get_value_by_index_as_string(csv, object_index, field_index);
  value_long = atol(value_string);

  return value_long;
}
Exemplo n.º 4
0
Arquivo: csv.c Projeto: clownfysh/cf
double cf_x_file_csv_get_value_by_index_as_double(cf_x_file_csv_t *csv,
    unsigned long object_index, unsigned long field_index)
{
  assert(csv);
  char *value_string;
  double value_double;

  value_string = get_value_by_index_as_string(csv, object_index, field_index);
  value_double = atof(value_string);

  return value_double;
}
Exemplo n.º 5
0
unsigned char ih_file_csv_get_value_by_index_as_unsigned_char
(ih_file_csv_t *csv, unsigned long object_index, unsigned long field_index)
{
  assert(csv);
  char *value_string;
  unsigned char value_unsigned_char;

  value_string = get_value_by_index_as_string(csv, object_index, field_index);
  value_unsigned_char = atoi(value_string);

  return value_unsigned_char;
}
Exemplo n.º 6
0
Arquivo: csv.c Projeto: clownfysh/cf
char cf_x_file_csv_get_value_by_index_as_char(cf_x_file_csv_t *csv,
    unsigned long object_index, unsigned long field_index)
{
  assert(csv);
  char *value_string;
  char value_char;

  value_string = get_value_by_index_as_string(csv, object_index, field_index);
  if (strlen(value_string) > 0) {
    value_char = *value_string;
  } else {
    value_char = '\0';
  }

  return value_char;
}
Exemplo n.º 7
0
Arquivo: csv.c Projeto: clownfysh/cf
char *get_value_by_name_as_string(cf_x_file_csv_t *csv,
    unsigned long object_index, char *field_name)
{
  assert(csv);
  unsigned long field_index;
  unsigned long *field_index_object;
  char *value;

  field_index_object = cf_x_case_map_find(csv->name_to_index, field_name);
  if (field_index_object) {
    field_index = *((unsigned long *) field_index_object);
    value = get_value_by_index_as_string(csv, object_index, field_index);
  } else {
    value = NULL;
    cf_x_core_trace("x_case_map_find");
  }

  return value;
}
Exemplo n.º 8
0
Arquivo: csv.c Projeto: clownfysh/cf
cf_x_core_bool_t cf_x_file_csv_get_value_by_index_as_bool(cf_x_file_csv_t *csv,
    unsigned long object_index, unsigned long field_index)
{
  assert(csv);
  char *value_string;
  cf_x_core_bool_t value_bool;

  value_string = get_value_by_index_as_string(csv, object_index, field_index);
  if (strlen(value_string) > 0) {
    if ('1' == *value_string) {
      value_bool = cf_x_core_bool_true;
    } else {
      value_bool = cf_x_core_bool_false;
    }
  } else {
    value_bool = cf_x_core_bool_false;
  }

  return value_bool;
}
Exemplo n.º 9
0
Arquivo: csv.c Projeto: clownfysh/cf
cf_x_core_bit_t cf_x_file_csv_get_value_by_index_as_bit(cf_x_file_csv_t *csv,
    unsigned long object_index, unsigned long field_index)
{
  assert(csv);
  char *value_string;
  char value_bit;

  value_string = get_value_by_index_as_string(csv, object_index, field_index);
  if (strlen(value_string) > 0) {
    if ('1' == *value_string) {
      value_bit = 1;
    } else {
      value_bit = 0;
    }
  } else {
    value_bit = 0;
  }

  return value_bit;
}
Exemplo n.º 10
0
Arquivo: csv.c Projeto: clownfysh/cf
char *cf_x_file_csv_get_value_by_index_as_string(cf_x_file_csv_t *csv,
    unsigned long object_index, unsigned long field_index)
{
  return get_value_by_index_as_string(csv, object_index, field_index);
}