MCPcopy Create free account
hub / github.com/ElementsProject/lightning / breakup

Function breakup

common/amount.c:91–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89REGISTER_TYPE_TO_STRING(amount_sat, fmt_amount_sat_ptr);
90
91static bool breakup(const char *str, size_t slen,
92 /* Length of first numeric part. */
93 size_t *whole_number_len,
94 /* Pointer to post-decimal part, or NULL */
95 const char **post_decimal_ptr,
96 size_t *post_decimal_len,
97 /* Pointer to suffix, or NULL */
98 const char **suffix_ptr,
99 size_t *suffix_len)
100{
101 size_t i;
102
103 *whole_number_len = 0;
104 *post_decimal_len = 0;
105 *post_decimal_ptr = NULL;
106 *suffix_ptr = NULL;
107 *suffix_len = 0;
108
109 for (i = 0;; i++) {
110 /* The string may be null-terminated. */
111 if (i >= slen || str[i] == '\0')
112 return i != 0;
113 if (cisdigit(str[i]))
114 (*whole_number_len)++;
115 else
116 break;
117 }
118
119 if (str[i] == '.') {
120 i++;
121 *post_decimal_ptr = str + i;
122 for (;; i++) {
123 /* True if > 0 decimals. */
124 if (i >= slen || str[i] == '\0')
125 return str + i != *post_decimal_ptr;
126 if (cisdigit(str[i]))
127 (*post_decimal_len)++;
128 else
129 break;
130 }
131 }
132
133 *suffix_ptr = str + i;
134 *suffix_len = slen - i;
135 return true;
136}
137
138static bool from_number(u64 *res, const char *s, size_t len, int tens_factor)
139{

Callers 2

parse_amount_msatFunction · 0.85
parse_amount_satFunction · 0.85

Calls 1

cisdigitFunction · 0.85

Tested by

no test coverage detected