mirror of
https://github.com/janet-lang/janet
synced 2026-10-09 09:11:40 +00:00
Align slice-related docstrings (#1887)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
This commit is contained in:
+1
-5
@@ -237,11 +237,7 @@ JANET_CORE_FN(cfun_array_ensure,
|
||||
|
||||
JANET_CORE_FN(cfun_array_slice,
|
||||
"(array/slice arrtup &opt start end)",
|
||||
"Takes a slice of array or tuple from `start` to `end`. The range is half open, "
|
||||
"[start, end). Indexes can also be negative, indicating indexing from the "
|
||||
"end of the array. By default, `start` is 0 and `end` is the length of the array. "
|
||||
"Note that if the range is negative, it is taken as (start, end] to allow a full "
|
||||
"negative slice range. Returns a new array.") {
|
||||
"Same as `tuple/slice`, but returns an array.") {
|
||||
JanetView view = janet_getindexed(argv, 0);
|
||||
JanetRange range = janet_getslice(argc, argv);
|
||||
JanetArray *array = janet_array(range.end - range.start);
|
||||
|
||||
+1
-4
@@ -531,10 +531,7 @@ JANET_CORE_FN(cfun_buffer_popn,
|
||||
|
||||
JANET_CORE_FN(cfun_buffer_slice,
|
||||
"(buffer/slice bytes &opt start end)",
|
||||
"Takes a slice of a byte sequence from `start` to `end`. The range is half open, "
|
||||
"[start, end). Indexes can also be negative, indicating indexing from the end of the "
|
||||
"end of the array. By default, `start` is 0 and `end` is the length of the buffer. "
|
||||
"Returns a new buffer.") {
|
||||
"Same as `string/slice`, but returns a buffer.") {
|
||||
JanetByteView view = janet_getbytes(argv, 0);
|
||||
JanetRange range = janet_getslice(argc, argv);
|
||||
JanetBuffer *buffer = janet_buffer(range.end - range.start);
|
||||
|
||||
+8
-1
@@ -416,7 +416,14 @@ JANET_CORE_FN(janet_core_array,
|
||||
|
||||
JANET_CORE_FN(janet_core_slice,
|
||||
"(slice x &opt start end)",
|
||||
"Extract a sub-range of an indexed data structure or byte sequence.") {
|
||||
"Extract a sub-range of `x`. Sub-ranges may be "
|
||||
"specified via optional arguments `start` and "
|
||||
"`end` as in `string/slice`.\n"
|
||||
"\n"
|
||||
"If `x` is a bytes or abstract type with a suitable "
|
||||
"`bytes` method, returns a string.\n"
|
||||
"\n"
|
||||
"If `x` is an indexed type, returns a tuple.") {
|
||||
JanetRange range;
|
||||
JanetByteView bview;
|
||||
JanetView iview;
|
||||
|
||||
+15
-8
@@ -172,12 +172,19 @@ static int32_t kmp_next(struct kmp_state *state) {
|
||||
|
||||
JANET_CORE_FN(cfun_string_slice,
|
||||
"(string/slice bytes &opt start end)",
|
||||
"Returns a substring from a byte sequence. The substring is from "
|
||||
"index `start` inclusive to index `end`, exclusive. All indexing "
|
||||
"is from 0. `start` and `end` can also be negative to indicate indexing "
|
||||
"from the end of the string. Note that if `start` is negative it is "
|
||||
"exclusive, and if `end` is negative it is inclusive, to allow a full "
|
||||
"negative slice range.") {
|
||||
"Returns a string based on a range of a byte "
|
||||
"sequence `bytes`. The range is specified by "
|
||||
"optional index arguments `start` and `end` "
|
||||
"defaulting to 0 and the length of `bytes` "
|
||||
"respectively. When non-negative, `start` is "
|
||||
"inclusive and `end` is exclusive, i.e. [`start`, "
|
||||
"`end`), and their values can range from 0 through "
|
||||
"the length of `bytes`. When negative, `start` is "
|
||||
"exclusive and `end` is inclusive, i.e. (`start`, "
|
||||
"`end`], and their values can range from the "
|
||||
"negative of one more than the length of `bytes` "
|
||||
"through -1. If `start` or `end` is out of range, "
|
||||
"an error is raised.") {
|
||||
JanetByteView view = janet_getbytes(argv, 0);
|
||||
JanetRange range = janet_getslice(argc, argv);
|
||||
return janet_stringv(view.bytes + range.start, range.end - range.start);
|
||||
@@ -185,7 +192,7 @@ JANET_CORE_FN(cfun_string_slice,
|
||||
|
||||
JANET_CORE_FN(cfun_symbol_slice,
|
||||
"(symbol/slice bytes &opt start end)",
|
||||
"Same as string/slice, but returns a symbol.") {
|
||||
"Same as `string/slice`, but returns a symbol.") {
|
||||
JanetByteView view = janet_getbytes(argv, 0);
|
||||
JanetRange range = janet_getslice(argc, argv);
|
||||
return janet_symbolv(view.bytes + range.start, range.end - range.start);
|
||||
@@ -193,7 +200,7 @@ JANET_CORE_FN(cfun_symbol_slice,
|
||||
|
||||
JANET_CORE_FN(cfun_keyword_slice,
|
||||
"(keyword/slice bytes &opt start end)",
|
||||
"Same as string/slice, but returns a keyword.") {
|
||||
"Same as `string/slice`, but returns a keyword.") {
|
||||
JanetByteView view = janet_getbytes(argv, 0);
|
||||
JanetRange range = janet_getslice(argc, argv);
|
||||
return janet_keywordv(view.bytes + range.start, range.end - range.start);
|
||||
|
||||
+14
-8
@@ -64,14 +64,20 @@ JANET_CORE_FN(cfun_tuple_brackets,
|
||||
}
|
||||
|
||||
JANET_CORE_FN(cfun_tuple_slice,
|
||||
"(tuple/slice arrtup [,start=0 [,end=(length arrtup)]])",
|
||||
"Take a sub-sequence of an array or tuple from index `start` "
|
||||
"inclusive to index `end` exclusive. If `start` or `end` are not provided, "
|
||||
"they default to 0 and the length of `arrtup`, respectively. "
|
||||
"`start` and `end` can also be negative to indicate indexing "
|
||||
"from the end of the input. Note that if `start` is negative it is "
|
||||
"exclusive, and if `end` is negative it is inclusive, to allow a full "
|
||||
"negative slice range. Returns the new tuple.") {
|
||||
"(tuple/slice ind &opt start end)",
|
||||
"Returns a tuple based on a range of an indexed "
|
||||
"type `ind`. The range is specified by optional "
|
||||
"index arguments `start` and `end` defaulting to 0 "
|
||||
"and the length of `ind` respectively. When "
|
||||
"non-negative, `start` is inclusive and `end` is "
|
||||
"exclusive, i.e. [`start`, `end`), and their "
|
||||
"values can range from 0 through the length of "
|
||||
"`ind`. When negative, `start` is exclusive and "
|
||||
"`end` is inclusive, i.e. (`start`, `end`], and "
|
||||
"their values can range from the negative of one "
|
||||
"more than the length of `ind` through -1. If "
|
||||
"`start` or `end` is out of range, an error is "
|
||||
"raised.") {
|
||||
JanetView view = janet_getindexed(argv, 0);
|
||||
JanetRange range = janet_getslice(argc, argv);
|
||||
return janet_wrap_tuple(janet_tuple_n(view.items + range.start, range.end - range.start));
|
||||
|
||||
Reference in New Issue
Block a user