mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1005 B
35 lines
1005 B
=proto
|
|
void duk_map_string(duk_context *ctx, int index, duk_map_char_function callback, void *udata);
|
|
|
|
=stack
|
|
[ ... val! ... ] -> [ ... val! ... ]
|
|
|
|
=summary
|
|
<p>Process string at <code>index</code>, calling <code>callback</code> for each codepoint
|
|
of the string. The callback is given the <code>udata</code> argument and a codepoint
|
|
and returns a replacement codepoint. If successful, a new string consisting of
|
|
the replacement codepoints replaces the original. If the value is not a string or
|
|
the index is invalid, throws an error.</p>
|
|
|
|
=example
|
|
static int map_char(void *udata, int codepoint) {
|
|
/* Convert ASCII to uppercase. */
|
|
if (codepoint >= (int) 'a' && codepoint <= (int) 'z') {
|
|
return codepoint - (int) 'a' + (int) 'A';
|
|
}
|
|
return codepoint;
|
|
}
|
|
|
|
duk_push_string(ctx, "test_string");
|
|
duk_map_string(ctx, -1, map_char, NULL);
|
|
printf("result: '%s'\n", duk_to_string(ctx, -1));
|
|
duk_pop(ctx);
|
|
|
|
=tags
|
|
string
|
|
|
|
=seealso
|
|
duk_decode_string
|
|
|
|
=fixme
|
|
Currently implemented. Necessary?
|
|
|