mirror of
https://github.com/RubyMetric/chsrc
synced 2025-10-19 09:01:29 +08:00
避免API使用消极用语
This commit is contained in:
33
lib/xy.h
33
lib/xy.h
@@ -9,7 +9,7 @@
|
||||
* | BingChunMoLi <bingchunmoli@bingchunmoli.com>
|
||||
* |
|
||||
* Created On : <2023-08-28>
|
||||
* Last Modified : <2025-10-06>
|
||||
* Last Modified : <2025-10-15>
|
||||
*
|
||||
*
|
||||
* xy: 襄阳、咸阳
|
||||
@@ -122,15 +122,24 @@ xy =
|
||||
|
||||
#define assert_str(a, b) assert (xy_streql ((a), (b)))
|
||||
|
||||
#define xy_panic(reason) assert(!reason)
|
||||
#define xy_throw(reason) assert(!reason)
|
||||
|
||||
// @flavor Perl, PHP, Raku
|
||||
#define die xy_panic
|
||||
/**
|
||||
* @depreacated 避免消极用语
|
||||
*
|
||||
* @flavor Perl, PHP, Raku
|
||||
*/
|
||||
// #define die xy_throw
|
||||
|
||||
#define xy_unsupported() xy_panic("Unsuppoted")
|
||||
#define xy_unimplemented() xy_panic("Unimplemented temporarily")
|
||||
#define xy_unreached() xy_panic("This code shouldn't be reached")
|
||||
#define xy_cant_be_null(p) if(!p) xy_panic("This pointer can't be null")
|
||||
/**
|
||||
* @depreacated 避免消极用语
|
||||
*/
|
||||
// #define xy_panic xy_throw
|
||||
|
||||
#define xy_unsupported() xy_throw("Unsuppoted")
|
||||
#define xy_unimplemented() xy_throw("Unimplemented temporarily")
|
||||
#define xy_unreached() xy_throw("This code shouldn't be reached")
|
||||
#define xy_cant_be_null(p) if(!p) xy_throw("This pointer can't be null")
|
||||
|
||||
|
||||
|
||||
@@ -164,7 +173,7 @@ static void _xy_println_const_str (const char *str) {printf ("%s\n", str);}
|
||||
bool: _xy_print_bool, \
|
||||
char *: _xy_print_str, \
|
||||
const char *: _xy_print_const_str, \
|
||||
default: xy_panic("Unsupported type for print()!") \
|
||||
default: xy_throw("Unsupported type for print()!") \
|
||||
)(x)
|
||||
|
||||
/**
|
||||
@@ -179,7 +188,7 @@ static void _xy_println_const_str (const char *str) {printf ("%s\n", str);}
|
||||
bool: _xy_println_bool, \
|
||||
char *: _xy_println_str, \
|
||||
const char *: _xy_println_const_str, \
|
||||
default: xy_panic("Unsupported type for println()/say()!") \
|
||||
default: xy_throw("Unsupported type for println()/say()!") \
|
||||
)(x)
|
||||
/* @flavor Raku, Perl */
|
||||
#define say println
|
||||
@@ -1341,7 +1350,7 @@ xy_detect_os ()
|
||||
}
|
||||
|
||||
if (!(xy.on_windows || xy.on_linux || xy.on_android || xy.on_macos || xy.on_bsd))
|
||||
xy_panic ("Unknown operating system");
|
||||
xy_throw ("Unknown operating system");
|
||||
}
|
||||
|
||||
|
||||
@@ -1450,7 +1459,7 @@ xy_seq_at (XySeq_t *seq, int n)
|
||||
{
|
||||
xy_cant_be_null (seq);
|
||||
|
||||
if (0 == n) xy_panic ("The index must begin from 1, not 0");
|
||||
if (0 == n) xy_throw ("The index must begin from 1, not 0");
|
||||
|
||||
if (1 == n) return seq->first_item ? seq->first_item->data : NULL;
|
||||
|
||||
|
Reference in New Issue
Block a user