Re: [Vala] Starting with Vala, problems with strings
- From: Diego Jacobi <jacobidiego gmail com>
- To: vala-list gnome org
- Subject: Re: [Vala] Starting with Vala, problems with strings
- Date: Tue, 21 Apr 2009 04:36:48 +0200
Hi again.
I am still having troubles with things that i should easily do in C.
Maybe because i have never programmed in C#, or mono or anything like
it.
In my test code i want to split a math sentence in terms, like the
next string example:
"(2+a)*d+(a*b-3)-4-q/2"
My function split_in_terms, is a very bad implementation (i know) that
should split the string into 4 terms, and if not possible, return
NULL.
For that i have tryed with a List, but when using nth_data it prints
this string: "g_list_nth_data", only once. So i think that Lists are
not yet fully implemented so i switched to Array.
Where now i cant compile it.
ERROR:arraylist.c:322:gee_array_list_real_get: assertion failed: (_tmp0)
And i dont have any clue where the problem is.
Also i dont know when should i use pointers in Vala.
I know from C that every object must be defined as a pointer, but the
Vala bindings, doesnt defines them as pointer, so, why should i add an
*
If i dont add it, i cant change the value of the parameter.
supouse a function like next:
private static void split_in_terms(string strmath, string* term_left,
string* term_right)
This also gives a lot of warnings for term_left and right.
Please note too the casting in: new Array<string>(false, true,
(uint)sizeof(string));
Seems like the new array requires an ulong instead of uint which is
returned by sizeof. I dont know if this is the correct behavior or
not, but it seems strange.
private static Array<string>* split_in_terms(string strmath)
{
int x = 0;
int parentesis=0;
Array<string> list = new Array<string>(false, true, (uint)sizeof(string));
string str = strmath;
StringBuilder term = new StringBuilder("");
int p = 0;
stdout.printf("str = %s\n", str);
for(weak string s = str; s.get_char()!=0 ; s = s.next_char())
{
unichar c = s.get_char();
if ( c == '(')
{
parentesis++;
term.append_unichar(c);
}
else if ( c == ')')
{
parentesis--;
term.append_unichar(c);
}
else if ( c == '+')
{
if ( parentesis == 0)
{
list.append_val( term.str );
print("%s\n",term.str);
term = new StringBuilder("");
p = x+1;
if ( str.len() >= p )
list.append_val( "+" );
}
}
else
{
term.append_unichar(c);
}
x++;
}
list.append_val( term.str );
if (parentesis != 0)
{
stdout.printf("SintaxERROR: Los parentesis no cierran
adecuadamente: %s\n", str);
return null;
}
return &list;
}
public void calculate ()
{
double mean, max, min;
string str = "holaaa+world";
print ("1");
Array<string>* list = split_in_terms( str );
print ("2");
for (int i = 0; i < list->length; i++)
stdout.printf ("term%d = %s\n", i, list->index(i));
/* for (int i = 0; i < list->length(); i++)
stdout.printf ("term%d = %s\n", i, list->nth_data (i)*/);*/
print ("3");
.....
Cheers.
Diego
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]