Debian Codegraph @

include/ruby/internal/intern/range.h

raw
1 #ifndef RBIMPL_INTERN_RANGE_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RBIMPL_INTERN_RANGE_H
3 /**
4 * @file
5 * @author Ruby developers <[email protected]>
6 * @copyright This file is a part of the programming language Ruby.
7 * Permission is hereby granted, to either redistribute and/or
8 * modify this file, provided that the conditions mentioned in the
9 * file COPYING are met. Consult the file for details.
10 * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
11 * implementation details. Don't take them as canon. They could
12 * rapidly appear then vanish. The name (path) of this header file
13 * is also an implementation detail. Do not expect it to persist
14 * at the place it is now. Developers are free to move it anywhere
15 * anytime at will.
16 * @note To ruby-core: remember that this header can be possibly
17 * recursively included from extension libraries written in C++.
18 * Do not expect for instance `__VA_ARGS__` is always available.
19 * We assume C99 for ruby itself but we don't assume languages of
20 * extension libraries. They could be written in C++98.
21 * @brief Public APIs related to ::rb_cRange.
22 */
23 #include "ruby/internal/attr/nonnull.h"
24 #include "ruby/internal/dllexport.h"
25 #include "ruby/internal/value.h"
26
27 RBIMPL_SYMBOL_EXPORT_BEGIN()
28
29 /* range.c */
30
31 /**
32 * Creates a new Range.
33 *
34 * @param[in] beg "Left" or "lowest" endpoint of the range.
35 * @param[in] end "Right" or "highest" endpoint of the range.
36 * @param[in] excl Whether the range is open-ended.
37 * @exception rb_eArgError `beg` and `end` are not comparable.
38 * @note These days both endpoints can be ::RUBY_Qnil, which means that
39 * endpoint is unbound.
40 */
41 VALUE rb_range_new(VALUE beg, VALUE end, int excl);
42
43 RBIMPL_ATTR_NONNULL(())
44 /**
45 * Deconstructs a numerical range. As the arguments are `long` based, it
46 * expects everything are in the `long` domain.
47 *
48 * @param[in] range A range of numerical endpoints.
49 * @param[out] begp Return value buffer.
50 * @param[out] lenp Return value buffer.
51 * @param[in] len Updated length.
52 * @param[in] err In case `len` is out of range...
53 * - `0`: returns ::RUBY_Qnil.
54 * - `1`: raises ::rb_eRangeError.
55 * - `2`: `beg` and `len` expanded accordingly.
56 * @exception rb_eTypeError `range` is not a numerical range.
57 * @exception rb_eRangeError `range` cannot fit into `long`.
58 * @retval RUBY_Qfalse `range` is not an ::rb_cRange.
59 * @retval RUBY_Qnil `len` is out of `range` but `err` is zero.
60 * @retval RUBY_Qtrue Otherwise.
61 * @post `beg` is the (possibly updated) left endpoint.
62 * @post `len` is the (possibly updated) length of the range.
63 *
64 * @internal
65 *
66 * The complex error handling switch reflects the fact that `Array#[]=` and
67 * `String#[]=` behave differently when they take ranges.
68 */
69 VALUE rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err);
70
71 RBIMPL_ATTR_NONNULL(())
72 /**
73 * Deconstructs a range into its components.
74 *
75 * @param[in] range Range or range-ish object.
76 * @param[out] begp Return value buffer.
77 * @param[out] endp Return value buffer.
78 * @param[out] exclp Return value buffer.
79 * @retval RUBY_Qfalse `range` is not an instance of ::rb_cRange.
80 * @retval RUBY_Qtrue Argument pointers are updated.
81 * @post `*begp` is the left endpoint of the range.
82 * @post `*endp` is the right endpoint of the range.
83 * @post `*exclp` is whether the range is open-ended or not.
84 */
85 int rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp);
86
87 RBIMPL_SYMBOL_EXPORT_END()
88
89 #endif /* RBIMPL_INTERN_RANGE_H */