Reading Object-Oriented Programming with ANSI-C. Compile with GCC / Mingw through Make
- Completely fix dict / vector GetbyInt/GetbyStr
- Repr print function
#include <ooc.h>
int main(void)
{
var str = String.Fread("data.txt");
var vec = Vector.Strsplit(s, "\n");
shared line;
var it = Iter(vec);
while (line = Next(it)) {
Println("{}", line);
}
Del(it);
Del(str);
Del(vec);
return 0;
}
#include <ooc.h>
int main(void)
{
var dict = New(Dict.Class);
Dict.Initializer(dict,
New(String.Class, "Hamlet"), String.Fread("hamlet.txt"),
New(String.Class, "Macbeth"), String.Fread("macbeth.txt"),
New(String.Class, "Othello"), String.Fread("othello.txt"),
NULL
);
var it = Iter(dict);
tuple2 *item;
while (item = Next(it)) {
Println("{}:", item->key);
var lines = Vector.Strsplit(item->value, "\n\r");
var line_it = Iter(lines);
shared line;
while (line = Next(line_it)) {
Println("{}", line);
}
Del(line_it);
Del(lines);
}
Del(it);
Del(dict);
return 0;
}
Shorthand notation, indicated by the leading $
#include <ooc.h>
int main(void)
{
var dict = $Dict();
Dict.Initializer(d,
$String("Key1"), $Int(1),
$String("Key2"), $Real(3.14159),
NULL);
$For(tuple2 *, item, dict, {
Println("{}: {}", item->key, item->value);
});
Del(dict);
return 0;
}
Json reading and writing
#include <ooc.h>
int main(void)
{
var json = Json.Load("test/test.json");
Println("{}", json);
var str = Json.Loads("test/test.json");
Println("Also string loading: {}", str);
Dict.Take(json, $String("New entry"), $Real(134.3));
Json.Dump(json, "test/out.json");
Del(str);
Del(json);
return 0;
}