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.
37 lines
1.3 KiB
37 lines
1.3 KiB
=proto
|
|
void duk_substring(duk_context *ctx, int index, size_t start_offset, size_t end_offset);
|
|
|
|
=stack
|
|
[ ... str! ... ] -> [ ... substr! ... ]
|
|
|
|
=summary
|
|
<p>Replace a string at <code>index</code> with a substring [<code>start_offset</code>,
|
|
<code>end_offset</code>[ of the string itself. If the value at <code>index</code> is
|
|
not a string or the index is invalid, throws an error.</p>
|
|
|
|
<p>The substring operation works with characters, not bytes, and the offsets
|
|
are character offsets. The semantics of this call are similar to
|
|
<a href="http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4.15">String.prototype.substring (start, end)</a>.
|
|
Offset values are clamped to string length (there is no need to clamp negative
|
|
values because <code>size_t</code> is unsigned) and if start offset is larger than
|
|
end offset, the result is an empty string.</p>
|
|
|
|
<div class="note">
|
|
To get a byte-oriented substring, use
|
|
<code><a href="#duk_get_lstring">duk_get_lstring()</a></code> to get a string data
|
|
pointer and length, and
|
|
<code><a href="#duk_push_lstring">duk_push_lstring()</a></code> to push a slice of
|
|
bytes.
|
|
</div>
|
|
|
|
=example
|
|
/* String at index -3 is 'foobar'. Substring [2,5[ is "oba". */
|
|
|
|
duk_substring(ctx, -3, 2, 5);
|
|
printf("substring: %s\n", duk_get_string(ctx, -3));
|
|
|
|
=tags
|
|
string
|
|
|
|
=fixme
|
|
Return const char *?
|
|
|