#define I18N_H
#include "log.qh"
+#include "map.qc"
#include "unsafe.qh"
// translation helpers
#endif
#if CTX_CACHE
- ArrayList CTX_cache;
+ HashMap CTX_cache;
STATIC_INIT(CTX_cache)
{
- AL_NEW(CTX_cache, 0, string_null, s);
+ HM_NEW(CTX_cache);
}
SHUTDOWN(CTX_cache)
{
- AL_DELETE(CTX_cache);
+ HM_DELETE(CTX_cache);
}
#endif
string CTX(string s)
{
#if CTX_CACHE
- int i = strid(s);
- string c = AL_gets(CTX_cache, i);
- if (c) return c;
+ string c = HM_gets(CTX_cache, s);
+ if (c != "") return c;
#endif
int p = strstrofs(s, "^", 0);
string ret = (p < 0) ? s : substring(s, p + 1, -1);
#if CTX_CACHE
LOG_DEBUGF("CTX(\"%s\")\n", s);
- AL_sets(CTX_cache, i, ret);
+ HM_sets(CTX_cache, s, ret);
#endif
return ret;
}
#ifndef MAP_H
#define MAP_H
+#include "int.qh"
+
// Databases (hash tables)
const int DB_BUCKETS = 8192;
void db_save(int db, string filename)
fclose(fh);
}
+typedef int HashMap;
+
int db_create()
{
return buf_create();
}
+#define HM_NEW(this) (this = db_create())
void db_put(int db, string key, string value);
{
buf_del(db);
}
+#define HM_DELETE(this) db_close(this)
string db_get(int db, string key)
{
int h = crc16(false, key) % DB_BUCKETS;
return uri_unescape(infoget(bufstr_get(db, h), key));
}
+#define HM_gets(this, k) db_get(this, k)
#define db_remove(db, key) db_put(db, key, "")
int h = crc16(false, key) % DB_BUCKETS;
bufstr_set(db, h, infoadd(bufstr_get(db, h), key, uri_escape(value)));
}
+#define HM_sets(this, key, val) db_put(this, key, val)
void db_test()
{
X(rawfunc)
#undef X
-#define strid(s) ITOF(reinterpret_cast(int, s))
+#define _strid(s) ITOF(reinterpret_cast(int, s))
+#define strid(s) stof(sprintf("%i", s))
.int _unsafe_fld1, _unsafe_fld2;
int INTEGER_ONE;