Renamed asc() to ord()
This commit is contained in:
parent
809fa900f6
commit
09091db2f3
4 changed files with 40 additions and 40 deletions
|
|
@ -500,21 +500,21 @@ ValuePtr builtin_chr(const Context *, const EvalContext *evalctx)
|
|||
return ValuePtr(stream.str());
|
||||
}
|
||||
|
||||
ValuePtr builtin_asc(const Context *, const EvalContext *evalctx)
|
||||
ValuePtr builtin_ord(const Context *, const EvalContext *evalctx)
|
||||
{
|
||||
Value::VectorType result;
|
||||
ValuePtr emptyResult = ValuePtr::undefined;
|
||||
for (size_t i = 0; i < evalctx->numArgs(); i++) {
|
||||
const ValuePtr v = evalctx->getArgValue(i);
|
||||
if (v->type() != Value::STRING) {
|
||||
PRINTB("WARNING: asc() argument %s is not of type string.", v->toString());
|
||||
PRINTB("WARNING: ord() argument %s is not of type string.", v->toString());
|
||||
continue;
|
||||
}
|
||||
|
||||
const std::string arg = v->toString();
|
||||
const char *ptr = arg.c_str();
|
||||
if (!g_utf8_validate(ptr, -1, NULL)) {
|
||||
PRINTB("WARNING: asc() argument '%s' is not valid utf8 string.", ptr);
|
||||
PRINTB("WARNING: ord() argument '%s' is not valid utf8 string.", ptr);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -939,7 +939,7 @@ void register_builtin_functions()
|
|||
Builtins::init("ln", new BuiltinFunction(&builtin_ln));
|
||||
Builtins::init("str", new BuiltinFunction(&builtin_str));
|
||||
Builtins::init("chr", new BuiltinFunction(&builtin_chr));
|
||||
Builtins::init("asc", new BuiltinFunction(&builtin_asc));
|
||||
Builtins::init("ord", new BuiltinFunction(&builtin_ord));
|
||||
Builtins::init("concat", new BuiltinFunction(&builtin_concat));
|
||||
Builtins::init("lookup", new BuiltinFunction(&builtin_lookup));
|
||||
Builtins::init("search", new BuiltinFunction(&builtin_search));
|
||||
|
|
|
|||
|
|
@ -9,37 +9,37 @@ a2 = "012345!§$%";
|
|||
u1 = "\u2190\u2191\u2193\u2192\U01F640\U01F0A1\U01F0D1";
|
||||
u2 = "\U01F603";
|
||||
|
||||
echo(text = a1, codepoints = asc(a1));
|
||||
echo(text = a2, codepoints = asc(a2));
|
||||
echo(text = a1, codepoints = ord(a1));
|
||||
echo(text = a2, codepoints = ord(a2));
|
||||
|
||||
echo(text = u1, codepoints = asc(u1));
|
||||
echo(text = u2, codepoints = asc(u2));
|
||||
echo(text = u1, codepoints = ord(u1));
|
||||
echo(text = u2, codepoints = ord(u2));
|
||||
|
||||
echo(empty_string = asc(""));
|
||||
echo(empty_strings = asc("", "", ""));
|
||||
echo(empty_string_and_undef = asc(undef, ""));
|
||||
echo(empty_string = ord(""));
|
||||
echo(empty_strings = ord("", "", ""));
|
||||
echo(empty_string_and_undef = ord(undef, ""));
|
||||
|
||||
echo(multiple_args = asc("a", "b", "", undef, "123"));
|
||||
echo(multiple_args = ord("a", "b", "", undef, "123"));
|
||||
|
||||
ra1 = chr(asc(a1));
|
||||
ra2 = chr(asc(a2));
|
||||
ra1 = chr(ord(a1));
|
||||
ra2 = chr(ord(a2));
|
||||
echo(equals = a1 == ra1, len_input = len(a1), len_output = len(ra1));
|
||||
echo(equals = a2 == ra2, len_input = len(a2), len_output = len(ra2));
|
||||
|
||||
ru1 = chr(asc(u1));
|
||||
ru2 = chr(asc(u2));
|
||||
ru1 = chr(ord(u1));
|
||||
ru2 = chr(ord(u2));
|
||||
echo(equals = u1 == ru1, len_input = len(u1), len_output = len(ru1));
|
||||
echo(equals = u2 == ru2, len_input = len(u2), len_output = len(ru2));
|
||||
|
||||
echo(asc(undef));
|
||||
echo(asc(undef, undef));
|
||||
echo(asc(1/0));
|
||||
echo(asc(-1/0));
|
||||
echo(asc(0/0));
|
||||
echo(asc([2:4]));
|
||||
echo(asc([]));
|
||||
echo(asc([1, 2, 3]));
|
||||
echo(asc(["a", "b"]));
|
||||
echo(ord(undef));
|
||||
echo(ord(undef, undef));
|
||||
echo(ord(1/0));
|
||||
echo(ord(-1/0));
|
||||
echo(ord(0/0));
|
||||
echo(ord([2:4]));
|
||||
echo(ord([]));
|
||||
echo(ord([1, 2, 3]));
|
||||
echo(ord(["a", "b"]));
|
||||
|
||||
// invalid utf-8 string, text €ÄÖÜß as latin15 (bytes: A4 C4 D6 DC DF)
|
||||
echo(asc("¤ÄÖÜß"));
|
||||
echo(ord("¤ÄÖÜß"));
|
||||
|
|
@ -1174,7 +1174,7 @@ list(APPEND ECHO_FILES ${FUNCTION_FILES}
|
|||
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/string-indexing.scad
|
||||
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/string-unicode.scad
|
||||
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/chr-tests.scad
|
||||
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/asc-tests.scad
|
||||
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/ord-tests.scad
|
||||
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/vector-values.scad
|
||||
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/search-tests.scad
|
||||
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/search-tests-unicode.scad
|
||||
|
|
|
|||
|
|
@ -4,32 +4,32 @@ ECHO: text = "←↑↓→🙀🂡🃑", codepoints = [8592, 8593, 8595, 8594, 1
|
|||
ECHO: text = "😃", codepoints = 128515
|
||||
ECHO: empty_string = 0
|
||||
ECHO: empty_strings = 0
|
||||
WARNING: asc() argument undef is not of type string.
|
||||
WARNING: ord() argument undef is not of type string.
|
||||
ECHO: empty_string_and_undef = 0
|
||||
WARNING: asc() argument undef is not of type string.
|
||||
WARNING: ord() argument undef is not of type string.
|
||||
ECHO: multiple_args = [97, 98, 49, 50, 51]
|
||||
ECHO: equals = true, len_input = 10, len_output = 10
|
||||
ECHO: equals = true, len_input = 10, len_output = 10
|
||||
ECHO: equals = true, len_input = 7, len_output = 7
|
||||
ECHO: equals = true, len_input = 1, len_output = 1
|
||||
WARNING: asc() argument undef is not of type string.
|
||||
WARNING: ord() argument undef is not of type string.
|
||||
ECHO: undef
|
||||
WARNING: asc() argument undef is not of type string.
|
||||
WARNING: asc() argument undef is not of type string.
|
||||
WARNING: ord() argument undef is not of type string.
|
||||
WARNING: ord() argument undef is not of type string.
|
||||
ECHO: undef
|
||||
WARNING: asc() argument inf is not of type string.
|
||||
WARNING: ord() argument inf is not of type string.
|
||||
ECHO: undef
|
||||
WARNING: asc() argument -inf is not of type string.
|
||||
WARNING: ord() argument -inf is not of type string.
|
||||
ECHO: undef
|
||||
WARNING: asc() argument nan is not of type string.
|
||||
WARNING: ord() argument nan is not of type string.
|
||||
ECHO: undef
|
||||
WARNING: asc() argument [2 : 1 : 4] is not of type string.
|
||||
WARNING: ord() argument [2 : 1 : 4] is not of type string.
|
||||
ECHO: undef
|
||||
WARNING: asc() argument [] is not of type string.
|
||||
WARNING: ord() argument [] is not of type string.
|
||||
ECHO: undef
|
||||
WARNING: asc() argument [1, 2, 3] is not of type string.
|
||||
WARNING: ord() argument [1, 2, 3] is not of type string.
|
||||
ECHO: undef
|
||||
WARNING: asc() argument ["a", "b"] is not of type string.
|
||||
WARNING: ord() argument ["a", "b"] is not of type string.
|
||||
ECHO: undef
|
||||
WARNING: asc() argument '¤ÄÖÜß' is not valid utf8 string.
|
||||
WARNING: ord() argument '¤ÄÖÜß' is not valid utf8 string.
|
||||
ECHO: undef
|
||||
Loading…
Reference in a new issue