summaryrefslogtreecommitdiffhomepage
path: root/src/fmt_fp.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-05-22 14:16:55 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-05-22 14:16:55 +0900
commit5c7fe225a6d675f3e213f8792f116035a35c63a4 (patch)
treedffa11b3f82bb6d516b7f0eb710e9b97e08d07bc /src/fmt_fp.c
parent328563995f7c817fc4ec1e92ffcadfde101ced06 (diff)
downloadmruby-5c7fe225a6d675f3e213f8792f116035a35c63a4.tar.gz
mruby-5c7fe225a6d675f3e213f8792f116035a35c63a4.zip
fp_fmt.c: remove `mrb_float_to_cstr()`.
The function was intended to be a utility function for `mruby-sprintf`. The functionality was integrated into `sprintf.c`.
Diffstat (limited to 'src/fmt_fp.c')
-rw-r--r--src/fmt_fp.c79
1 files changed, 0 insertions, 79 deletions
diff --git a/src/fmt_fp.c b/src/fmt_fp.c
index 50abe3747..bfc0c82a6 100644
--- a/src/fmt_fp.c
+++ b/src/fmt_fp.c
@@ -365,85 +365,6 @@ mrb_format_float(mrb_float f, char *buf, size_t buf_size, char fmt, int prec, ch
}
-int
-mrb_float_to_cstr(mrb_state *mrb, char *buf, size_t buf_size, const char *fmt, mrb_float f)
-{
- const char *s = fmt;
- char sign = '\0';
- int alt_form = 0;
- int left_align = 0;
- int zero_pad = 0;
- int width = -1;
- int prec = 6;
-
- s++; // skip %
-
- while (*s) {
- if (*s == '-') {
- left_align = 1;
- } else if (*s == '+') {
- sign = '+';
- } else if (*s == ' ') {
- sign = ' ';
- } else if (*s == '0') {
- zero_pad = 1;
- } else if (*s == '#') {
- alt_form = 1;
- } else {
- break;
- }
- s++;
- }
- if (ISDIGIT(*s)) {
- char *endptr;
- width = strtoul(s, &endptr, 10);
- s = endptr;
- }
- if (*s == '.') {
- s++;
- if (ISDIGIT(*s)) {
- char *endptr;
- prec = strtoul(s, &endptr, 10);
- s = endptr;
- }
- else {
- prec = 0;
- }
- }
- char c = *s;
- if (alt_form) {
- c |= 0x80;
- }
- int len = mrb_format_float(f, buf, buf_size, c, prec, sign);
-
- // buf[0] < '0' returns true if the first character is space, + or -
- // buf[1] < '9' matches a digit, and doesn't match when we get back +nan or +inf
- if (buf[0] < '0' && buf[1] <= '9' && zero_pad) {
- buf++;
- width--;
- len--;
- }
- if (*buf < '0' || *buf >= '9') {
- // For inf or nan, we don't want to zero pad.
- zero_pad = 0;
- }
- if (len >= width) {
- return len;
- }
- buf[width] = '\0';
- if (left_align) {
- memset(&buf[len], ' ', width - len);
- return width;
- }
- memmove(&buf[width - len], buf, len);
- if (zero_pad) {
- memset(buf, '0', width - len);
- } else {
- memset(buf, ' ', width - len);
- }
- return width;
-}
-
MRB_API mrb_value
mrb_float_to_str(mrb_state *mrb, mrb_value flo)
{