fn-misc.c 1.05 KB
Newer Older
Arturo Espinosa's avatar
Arturo Espinosa committed
1
2
3
4
5
6
7
8
9
/*
 * fn-misc.c:  Miscelaneous built-in functions
 *
 * Author:
 *  Miguel de Icaza (miguel@gnu.org)
 *
 */
#include <config.h>
#include <gnome.h>
10
#include <ctype.h>
Arturo Espinosa's avatar
Arturo Espinosa committed
11
12
13
14
15
16
#include "math.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
#include "func.h"

17
18
19
static char *help_clean = {
	N_("@FUNCTION=CLEAN\n"
	   "@SYNTAX=CLEAN(string)\n"
Arturo Espinosa's avatar
Arturo Espinosa committed
20

21
22
23
24
25
26
	   "@DESCRIPTION="
	   "Cleans the string from any non-printable characters."
	   "\n"
	   
	   "@SEEALSO=")
};
Arturo Espinosa's avatar
Arturo Espinosa committed
27
static Value *
28
gnumeric_clean (FunctionDefinition *fn, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{
	Value *res;
	char *copy, *p, *q;
	
	if (argv [0]->type != VALUE_STRING){
		*error_string = _("Type mismatch");
		return NULL;
	}
	p = argv [0]->v.str->str;
	copy = q = g_malloc (strlen (p) + 1);
	
	while (p){
		if (isprint (*p))
			*q++ = *p;
		p++;
	}
	*q = 0;

	res = g_new (Value, 1);
	res->type = VALUE_STRING;
	res->v.str = string_get (copy);
	g_free (copy);

	return res;
}

FunctionDefinition misc_functions [] = {
56
	{ "clean", "s",  "text",             &help_clean, NULL, gnumeric_clean },
Arturo Espinosa's avatar
Arturo Espinosa committed
57
58
	{ NULL, NULL }
};