MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / AR_RIGHT

Function AR_RIGHT

src/arithmetic/string_funcs/string_funcs.c:72–99  ·  view source on GitHub ↗

returns a string containing the specified number of rightmost characters of the original string.

Source from the content-addressed store, hash-verified

70
71// returns a string containing the specified number of rightmost characters of the original string.
72SIValue AR_RIGHT(SIValue *argv, int argc, void *private_data) {
73 if(SIValue_IsNull(argv[0])) return SI_NullVal();
74
75 int64_t newlen = -1;
76 if(SI_TYPE(argv[1]) == T_INT64) {
77 newlen = argv[1].longval;
78 }
79 if(newlen < 0) {
80 ErrorCtx_SetError("length must be a non-negative integer");
81 return SI_NullVal();
82 }
83
84 const char *str = argv[0].stringval;
85 int64_t start = str_length(str) - newlen;
86
87 if(start <= 0) {
88 // No need to truncate this string based on the requested length
89 return SI_DuplicateStringVal(str);
90 }
91
92 utf8proc_int32_t c;
93 int64_t start_bytes = 0;
94 for (int i = 0; i < start; i++) {
95 start_bytes += utf8proc_iterate((const utf8proc_uint8_t *)(str+start_bytes), -1, &c);
96 }
97
98 return SI_DuplicateStringVal(str + start_bytes);
99}
100
101// returns the original string with trailing whitespace removed.
102SIValue AR_RTRIM(SIValue *argv, int argc, void *private_data) {

Callers

nothing calls this directly

Calls 5

SIValue_IsNullFunction · 0.85
SI_NullValFunction · 0.85
ErrorCtx_SetErrorFunction · 0.85
str_lengthFunction · 0.85
SI_DuplicateStringValFunction · 0.85

Tested by

no test coverage detected