/* split: split line into fields */
static int split(void)
{
	char *p, **newf;
	char *sepp; /* pointer to temporary separator character */
	int sepc;   /* temporary separator character */

	nfield = 0;
	if (line[0] == '\0')
		return 0;
	strcpy(sline, line);
	p = sline;

	do {
		if (nfield >= maxfield) {
			maxfield *= 2;			/* double current size */
			newf = (char **) realloc(field, 
						maxfield * sizeof(field[0]));
			if (newf == NULL)
				return NOMEM;
			field = newf;
		}
		if (*p == '"')
			sepp = advquoted(++p);	/* skip initial quote */
		else
			sepp = p + strcspn(p, fieldsep);
		sepc = sepp[0];
		sepp[0] = '\0';				/* terminate field */
		field[nfield++] = p;
		p = sepp + 1;
	} while (sepc == ',');

	return nfield;
}
Exemplo n.º 2
0
/* Splitting lines into fields */
static int split(void)
{
  char *p, **new_field;
  char *temp_sep;      /* pointer to temporary separator character */
  int temp_sep_char;   /* temporary separator character */

  nfields = 0;
  if (line[0] == '\0') return 0;
  strcpy(sep_line, line);
  p = sep_line;

  do {
    if (nfields >= max_field) {
      max_field *= 2;         /* double current size */
      new_field  = (char **) realloc(field,
                   max_field * sizeof(field[0]));

      if (new_field == NULL) return NOMEM;
      field = new_field;
    }

    if (*p == '"') {
      temp_sep = advquoted(++p);
    } else {
      temp_sep = p + strcspn(p, field_sep);
    }

    temp_sep_char = temp_sep[0];
    temp_sep[0] = '\0';           /* terminate field */
    field[nfields++] = p;
    p = temp_sep + 1;
  } while (temp_sep_char == ',');

  return nfields;
}
Exemplo n.º 3
0
static int split(void)
{
	char *p = NULL;
	char *cur = NULL;
	char **newf = NULL;
	char sepc; 
		
	n_field = 0;
	if (line[0] == '\0')
	{
		return 0;
	}
	strcpy(sline, line);
	p = sline;
	cur = sline;

	do	{		if (n_field >= max_field)		
				{			
					max_field *=2;			
					newf = (char**)realloc(field,max_field *sizeof(field[0]));	
					if (newf == NULL)		
					{		
						return NOMEM;	
					}	
					field = newf;		
				}	

		if (*p == '"')
		{
			cur = advquoted(++p);
		}
		else
		{
			cur = p + strcspn(p, fill_sep);
		}
		sepc = cur[0];	
		cur[0] = '\0';	
		field[n_field++] = p;
		p = cur + 1;
	}while(sepc == ',');

	return n_field;
}
Exemplo n.º 4
0
void CCSVParse::split(vector<string>& field, string line)
{
	string fld;
	unsigned int i, j = 0;

	if (line.length() == 0)
		return;
	i = 0;

	do
	{
		if (j < line.length() && line[i] == '"')
			j = advquoted(line, fld, ++i);
		else
			j = advplain(line, fld, i);

		field.push_back(fld);
		i = j + 1;
	} while (j < line.length());
}
Exemplo n.º 5
0
Arquivo: csv.c Projeto: faisal-w/mlelr
/* split: split line into fields */
static int split(char delim, int compress)
{
	char *p, **newf;
	char *sepp; /* pointer to temporary separator character */
	int sepc;   /* temporary separator character */

	nfield = 0;
	if (line[0] == '\0')
		return 0;
	strcpy(sline, line);
	p = sline;

	do {
		if (nfield >= maxfield) {
			maxfield *= 2;			/* double current size */
			newf = (char **) realloc(field,
						maxfield * sizeof(field[0]));
			if (newf == NULL)
				return NOMEM;
			field = newf;
		}
		/* compress subsequent delimiter characters */
		if (compress) {
		    while (*p != '\0' && *p == delim) {
		        p++;
		    }
		}
		if (*p == '"')
			sepp = advquoted(++p, delim);	/* skip initial quote */
		else
			sepp = p + strcspn(p, &delim);
		sepc = sepp[0];
		sepp[0] = '\0';				/* terminate field */
		field[nfield++] = p;
		p = sepp + 1;
	} while (sepc == (int) delim);

	return nfield;
}