Remove prefixes and postfixes from declaration names
This commit is contained in:
parent
409aab92ff
commit
c77c886290
@ -8,38 +8,38 @@ def locale_conf_path = "/etc/locale.conf";
|
|||||||
|
|
||||||
// Returns the locale to use for character classification and case conversion.
|
// Returns the locale to use for character classification and case conversion.
|
||||||
// The memory is statically allocated and must not be free'd. It may be
|
// The memory is statically allocated and must not be free'd. It may be
|
||||||
// overwritten later, so use [[locale_dup]] to extend its lifetime.
|
// overwritten later, so use [[dup]] to extend its lifetime.
|
||||||
export fn get_ctype() locale = get_locale("LC_CTYPE");
|
export fn get_ctype() locale = get_locale("LC_CTYPE");
|
||||||
|
|
||||||
// Returns the locale to use for collation order.
|
// Returns the locale to use for collation order.
|
||||||
// The memory is statically allocated and must not be free'd. It may be
|
// The memory is statically allocated and must not be free'd. It may be
|
||||||
// overwritten later, so use [[locale_dup]] to extend its lifetime.
|
// overwritten later, so use [[dup]] to extend its lifetime.
|
||||||
export fn get_collate() locale = get_locale("LC_COLLATE");
|
export fn get_collate() locale = get_locale("LC_COLLATE");
|
||||||
|
|
||||||
// Returns the locale to use for monetary formatting.
|
// Returns the locale to use for monetary formatting.
|
||||||
// The memory is statically allocated and must not be free'd. It may be
|
// The memory is statically allocated and must not be free'd. It may be
|
||||||
// overwritten later, so use [[locale_dup]] to extend its lifetime.
|
// overwritten later, so use [[dup]] to extend its lifetime.
|
||||||
export fn get_monetary() locale = get_locale("LC_MONETARY");
|
export fn get_monetary() locale = get_locale("LC_MONETARY");
|
||||||
|
|
||||||
// Returns the locale to use for numeric, non-monetary formatting.
|
// Returns the locale to use for numeric, non-monetary formatting.
|
||||||
// The memory is statically allocated and must not be free'd. It may be
|
// The memory is statically allocated and must not be free'd. It may be
|
||||||
// overwritten later, so use [[locale_dup]] to extend its lifetime.
|
// overwritten later, so use [[dup]] to extend its lifetime.
|
||||||
export fn get_numeric() locale = get_locale("LC_NUMERIC");
|
export fn get_numeric() locale = get_locale("LC_NUMERIC");
|
||||||
|
|
||||||
// Returns the locale to use for date and time formats.
|
// Returns the locale to use for date and time formats.
|
||||||
// The memory is statically allocated and must not be free'd. It may be
|
// The memory is statically allocated and must not be free'd. It may be
|
||||||
// overwritten later, so use [[locale_dup]] to extend its lifetime.
|
// overwritten later, so use [[dup]] to extend its lifetime.
|
||||||
export fn get_time() locale = get_locale("LC_TIME");
|
export fn get_time() locale = get_locale("LC_TIME");
|
||||||
|
|
||||||
// Returns the locale to use for formats of informative and diagnostic messages
|
// Returns the locale to use for formats of informative and diagnostic messages
|
||||||
// and interactive responses.
|
// and interactive responses.
|
||||||
// The memory is statically allocated and must not be free'd. It may be
|
// The memory is statically allocated and must not be free'd. It may be
|
||||||
// overwritten later, so use [[locale_dup]] to extend its lifetime.
|
// overwritten later, so use [[dup]] to extend its lifetime.
|
||||||
export fn get_messages() locale = get_locale("LC_MESSAGES");
|
export fn get_messages() locale = get_locale("LC_MESSAGES");
|
||||||
|
|
||||||
// Returns the locale to use for linguistic translations.
|
// Returns the locale to use for linguistic translations.
|
||||||
// The memory is statically allocated and must not be free'd. It may be
|
// The memory is statically allocated and must not be free'd. It may be
|
||||||
// overwritten later, so use [[locale_dup]] to extend its lifetime.
|
// overwritten later, so use [[dup]] to extend its lifetime.
|
||||||
export fn get_lang() locale = get_locale("LC_LANG");
|
export fn get_lang() locale = get_locale("LC_LANG");
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
@ -58,7 +58,7 @@ fn get_locale(var: str) locale =
|
|||||||
|
|
||||||
fn get_env_locale(var: str) (locale | errors::invalid) =
|
fn get_env_locale(var: str) (locale | errors::invalid) =
|
||||||
match (os::getenv(var)) {
|
match (os::getenv(var)) {
|
||||||
case let env: str => return parse_locale(env);
|
case let env: str => return parse(env);
|
||||||
case => return errors::invalid;
|
case => return errors::invalid;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ fn get_locale_conf_entry(var: str) (locale | errors::invalid) = {
|
|||||||
get_locale_conf();
|
get_locale_conf();
|
||||||
for (let entry .. locale_conf) {
|
for (let entry .. locale_conf) {
|
||||||
let (key, value) = strings::cut(entry, "=");
|
let (key, value) = strings::cut(entry, "=");
|
||||||
if (key == var) return parse_locale(value);
|
if (key == var) return parse(value);
|
||||||
};
|
};
|
||||||
return errors::invalid;
|
return errors::invalid;
|
||||||
};
|
};
|
||||||
|
@ -2,38 +2,38 @@ use errors;
|
|||||||
|
|
||||||
// Returns the locale to use for character classification and case conversion.
|
// Returns the locale to use for character classification and case conversion.
|
||||||
// The memory is statically allocated and must not be free'd. It may be
|
// The memory is statically allocated and must not be free'd. It may be
|
||||||
// overwritten later, so use [[locale_dup]] to extend its lifetime.
|
// overwritten later, so use [[dup]] to extend its lifetime.
|
||||||
export fn get_ctype() locale = c;
|
export fn get_ctype() locale = c;
|
||||||
|
|
||||||
// Returns the locale to use for collation order.
|
// Returns the locale to use for collation order.
|
||||||
// The memory is statically allocated and must not be free'd. It may be
|
// The memory is statically allocated and must not be free'd. It may be
|
||||||
// overwritten later, so use [[locale_dup]] to extend its lifetime.
|
// overwritten later, so use [[dup]] to extend its lifetime.
|
||||||
export fn get_collate() locale = c;
|
export fn get_collate() locale = c;
|
||||||
|
|
||||||
// Returns the locale to use for monetary formatting.
|
// Returns the locale to use for monetary formatting.
|
||||||
// The memory is statically allocated and must not be free'd. It may be
|
// The memory is statically allocated and must not be free'd. It may be
|
||||||
// overwritten later, so use [[locale_dup]] to extend its lifetime.
|
// overwritten later, so use [[dup]] to extend its lifetime.
|
||||||
export fn get_monetary() locale = c;
|
export fn get_monetary() locale = c;
|
||||||
|
|
||||||
// Returns the locale to use for numeric, non-monetary formatting.
|
// Returns the locale to use for numeric, non-monetary formatting.
|
||||||
// The memory is statically allocated and must not be free'd. It may be
|
// The memory is statically allocated and must not be free'd. It may be
|
||||||
// overwritten later, so use [[locale_dup]] to extend its lifetime.
|
// overwritten later, so use [[dup]] to extend its lifetime.
|
||||||
export fn get_numeric() locale = c;
|
export fn get_numeric() locale = c;
|
||||||
|
|
||||||
// Returns the locale to use for date and time formats.
|
// Returns the locale to use for date and time formats.
|
||||||
// The memory is statically allocated and must not be free'd. It may be
|
// The memory is statically allocated and must not be free'd. It may be
|
||||||
// overwritten later, so use [[locale_dup]] to extend its lifetime.
|
// overwritten later, so use [[dup]] to extend its lifetime.
|
||||||
export fn get_time() locale = c;
|
export fn get_time() locale = c;
|
||||||
|
|
||||||
// Returns the locale to use for formats of informative and diagnostic messages
|
// Returns the locale to use for formats of informative and diagnostic messages
|
||||||
// and interactive responses.
|
// and interactive responses.
|
||||||
// The memory is statically allocated and must not be free'd. It may be
|
// The memory is statically allocated and must not be free'd. It may be
|
||||||
// overwritten later, so use [[locale_dup]] to extend its lifetime.
|
// overwritten later, so use [[dup]] to extend its lifetime.
|
||||||
export fn get_messages() locale = c;
|
export fn get_messages() locale = c;
|
||||||
|
|
||||||
// Returns the locale to use for linguistic translations.
|
// Returns the locale to use for linguistic translations.
|
||||||
// The memory is statically allocated and must not be free'd. It may be
|
// The memory is statically allocated and must not be free'd. It may be
|
||||||
// overwritten later, so use [[locale_dup]] to extend its lifetime.
|
// overwritten later, so use [[dup]] to extend its lifetime.
|
||||||
export fn get_lang() locale = c;
|
export fn get_lang() locale = c;
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
@ -22,9 +22,9 @@ export def c = locale {
|
|||||||
//
|
//
|
||||||
// Where _COUNTRY, .ENCODING, and @MODIFIER may be omitted. The function
|
// Where _COUNTRY, .ENCODING, and @MODIFIER may be omitted. The function
|
||||||
// returns a [[locale]], or [[errors::invalid]] if the input cannot be parsed.
|
// returns a [[locale]], or [[errors::invalid]] if the input cannot be parsed.
|
||||||
// All memory is borrowed from the input, so [[locale_finish]] should not be
|
// All memory is borrowed from the input, so [[finish]] should not be used to
|
||||||
// used to free it.
|
// free it.
|
||||||
export fn parse_locale(in: str) (locale | errors::invalid) = {
|
export fn parse(in: str) (locale | errors::invalid) = {
|
||||||
let (in, modifier) = strings::rcut(in, "@");
|
let (in, modifier) = strings::rcut(in, "@");
|
||||||
if (strings::compare(in, "") == 0) return void: errors::invalid;
|
if (strings::compare(in, "") == 0) return void: errors::invalid;
|
||||||
let (in, encoding) = strings::rcut(in, ".");
|
let (in, encoding) = strings::rcut(in, ".");
|
||||||
@ -40,7 +40,7 @@ export fn parse_locale(in: str) (locale | errors::invalid) = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Formats a [[locale]]. The caller must free the return value.
|
// Formats a [[locale]]. The caller must free the return value.
|
||||||
export fn format_locale(local: locale) str = {
|
export fn format(local: locale) str = {
|
||||||
let output = strings::dup(local.lang);
|
let output = strings::dup(local.lang);
|
||||||
if (strings::compare(local.country, "") != 0) {
|
if (strings::compare(local.country, "") != 0) {
|
||||||
let new_output = strings::join("_", output, local.country);
|
let new_output = strings::join("_", output, local.country);
|
||||||
@ -61,14 +61,14 @@ export fn format_locale(local: locale) str = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Checks if two [[locale]]s are equal.
|
// Checks if two [[locale]]s are equal.
|
||||||
export fn locale_equal(a: locale, b: locale) bool =
|
export fn equal(a: locale, b: locale) bool =
|
||||||
a.lang == b.lang &&
|
a.lang == b.lang &&
|
||||||
a.country == b.country &&
|
a.country == b.country &&
|
||||||
a.encoding == b.encoding &&
|
a.encoding == b.encoding &&
|
||||||
a.modifier == b.modifier;
|
a.modifier == b.modifier;
|
||||||
|
|
||||||
// Duplicates a [[locale]] structure. Use [[locale_finish]] to get rid of it.
|
// Duplicates a [[locale]] structure. Use [[finish]] to get rid of it.
|
||||||
export fn locale_dup(local: locale) locale = locale {
|
export fn dup(local: locale) locale = locale {
|
||||||
lang = strings::dup(local.lang),
|
lang = strings::dup(local.lang),
|
||||||
country = strings::dup(local.country),
|
country = strings::dup(local.country),
|
||||||
encoding = strings::dup(local.encoding),
|
encoding = strings::dup(local.encoding),
|
||||||
@ -76,7 +76,7 @@ export fn locale_dup(local: locale) locale = locale {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Frees memory associated with a [[locale]] structure.
|
// Frees memory associated with a [[locale]] structure.
|
||||||
export fn locale_finish(local: locale) void = {
|
export fn finish(local: locale) void = {
|
||||||
free(local.lang);
|
free(local.lang);
|
||||||
free(local.country);
|
free(local.country);
|
||||||
free(local.encoding);
|
free(local.encoding);
|
||||||
|
@ -2,8 +2,8 @@ use fmt;
|
|||||||
use errors;
|
use errors;
|
||||||
use strings;
|
use strings;
|
||||||
|
|
||||||
@test fn parse_locale_full() void = {
|
@test fn parse_full() void = {
|
||||||
let local = match(parse_locale("lang_COUNTRY.ENCODING@MODIFIER")) {
|
let local = match(parse("lang_COUNTRY.ENCODING@MODIFIER")) {
|
||||||
case let local: locale => yield local;
|
case let local: locale => yield local;
|
||||||
case => abort("error");
|
case => abort("error");
|
||||||
};
|
};
|
||||||
@ -17,8 +17,8 @@ use strings;
|
|||||||
assert(strings::compare(local.modifier, "MODIFIER") == 0);
|
assert(strings::compare(local.modifier, "MODIFIER") == 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
@test fn parse_locale_sparse_a() void = {
|
@test fn parse_sparse_a() void = {
|
||||||
let local = match(parse_locale("lang.ENCODING@MODIFIER")) {
|
let local = match(parse("lang.ENCODING@MODIFIER")) {
|
||||||
case let local: locale => yield local;
|
case let local: locale => yield local;
|
||||||
case => abort("error");
|
case => abort("error");
|
||||||
};
|
};
|
||||||
@ -32,8 +32,8 @@ use strings;
|
|||||||
assert(strings::compare(local.modifier, "MODIFIER") == 0);
|
assert(strings::compare(local.modifier, "MODIFIER") == 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
@test fn parse_locale_sparse_b() void = {
|
@test fn parse_sparse_b() void = {
|
||||||
let local = match(parse_locale("lang.ENCODING")) {
|
let local = match(parse("lang.ENCODING")) {
|
||||||
case let local: locale => yield local;
|
case let local: locale => yield local;
|
||||||
case => abort("error");
|
case => abort("error");
|
||||||
};
|
};
|
||||||
@ -47,8 +47,8 @@ use strings;
|
|||||||
assert(strings::compare(local.modifier, "") == 0);
|
assert(strings::compare(local.modifier, "") == 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
@test fn parse_locale_sparse_c() void = {
|
@test fn parse_sparse_c() void = {
|
||||||
let local = match(parse_locale("lang")) {
|
let local = match(parse("lang")) {
|
||||||
case let local: locale => yield local;
|
case let local: locale => yield local;
|
||||||
case => abort("error");
|
case => abort("error");
|
||||||
};
|
};
|
||||||
@ -62,15 +62,15 @@ use strings;
|
|||||||
assert(strings::compare(local.modifier, "") == 0);
|
assert(strings::compare(local.modifier, "") == 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
@test fn parse_locale_error() void = {
|
@test fn parse_error() void = {
|
||||||
let local = match(parse_locale("_COUNTRY.ENCODING@MODIFIER")) {
|
let local = match(parse("_COUNTRY.ENCODING@MODIFIER")) {
|
||||||
case errors::invalid => void;
|
case errors::invalid => void;
|
||||||
case => abort("error");
|
case => abort("error");
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@test fn format_locale_a() void = {
|
@test fn format_a() void = {
|
||||||
let string = format_locale(locale {
|
let string = format(locale {
|
||||||
lang = "lang",
|
lang = "lang",
|
||||||
country = "COUNTRY",
|
country = "COUNTRY",
|
||||||
encoding = "ENCODING",
|
encoding = "ENCODING",
|
||||||
@ -81,8 +81,8 @@ use strings;
|
|||||||
assert(strings::compare(string, "lang_COUNTRY.ENCODING@MODIFIER") == 0);
|
assert(strings::compare(string, "lang_COUNTRY.ENCODING@MODIFIER") == 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
@test fn format_locale_b() void = {
|
@test fn format_b() void = {
|
||||||
let string = format_locale(locale {
|
let string = format(locale {
|
||||||
lang = "lang",
|
lang = "lang",
|
||||||
country = "COUNTRY",
|
country = "COUNTRY",
|
||||||
modifier = "MODIFIER",
|
modifier = "MODIFIER",
|
||||||
@ -93,8 +93,8 @@ use strings;
|
|||||||
assert(strings::compare(string, "lang_COUNTRY@MODIFIER") == 0);
|
assert(strings::compare(string, "lang_COUNTRY@MODIFIER") == 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
@test fn format_locale_c() void = {
|
@test fn format_c() void = {
|
||||||
let string = format_locale(locale {
|
let string = format(locale {
|
||||||
lang = "lang",
|
lang = "lang",
|
||||||
...
|
...
|
||||||
});
|
});
|
||||||
@ -103,8 +103,8 @@ use strings;
|
|||||||
assert(strings::compare(string, "lang") == 0);
|
assert(strings::compare(string, "lang") == 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
@test fn locale_equal() void = {
|
@test fn equal() void = {
|
||||||
assert(locale_equal(locale {
|
assert(equal(locale {
|
||||||
lang = "lang",
|
lang = "lang",
|
||||||
country = "COUNTRY",
|
country = "COUNTRY",
|
||||||
encoding = "ENCODING",
|
encoding = "ENCODING",
|
||||||
@ -116,7 +116,7 @@ use strings;
|
|||||||
encoding = "ENCODING",
|
encoding = "ENCODING",
|
||||||
modifier = "MODIFIER",
|
modifier = "MODIFIER",
|
||||||
}));
|
}));
|
||||||
assert(!locale_equal(locale {
|
assert(!equal(locale {
|
||||||
lang = "lang",
|
lang = "lang",
|
||||||
country = "COUNTRY",
|
country = "COUNTRY",
|
||||||
encoding = "ENCODING",
|
encoding = "ENCODING",
|
||||||
@ -128,7 +128,7 @@ use strings;
|
|||||||
encoding = "ENCODING",
|
encoding = "ENCODING",
|
||||||
modifier = "MODIFIER",
|
modifier = "MODIFIER",
|
||||||
}));
|
}));
|
||||||
assert(!locale_equal(locale {
|
assert(!equal(locale {
|
||||||
lang = "lang",
|
lang = "lang",
|
||||||
encoding = "ENCODING",
|
encoding = "ENCODING",
|
||||||
modifier = "MODIFIER",
|
modifier = "MODIFIER",
|
||||||
|
Loading…
Reference in New Issue
Block a user