zero_start, /* position of first zero */
zero_end, /* position of last zero */
need_locale; /* needs it locale */
-} NUMDesc;
+} FmtDesc;
/* ----------
* Flags for NUMBER version
FormatNode format[NUM_CACHE_SIZE + 1];
char str[NUM_CACHE_SIZE + 1];
int age;
- NUMDesc Num;
+ FmtDesc Fmt;
} NUMCacheEntry;
/* global cache for --- date/time part */
typedef struct NUMProc
{
bool is_to_char;
- NUMDesc *Num; /* number description */
+ FmtDesc *Fmt; /* number description */
int sign, /* '-' or '+' */
sign_wrote, /* was sign write */
read_post, /* to_number - number of dec. digit */
read_pre; /* to_number - number non-dec. digit */
- char *number, /* string with number */
- *number_p, /* pointer to current number position */
+ char *numstr, /* string with number */
+ *numstr_p, /* pointer to current number position */
*inout, /* in / out buffer */
*inout_p, /* pointer to current inout position */
*last_relevant, /* last relevant number after decimal point */
static const KeyWord *index_seq_search(char *str, const KeyWord *kw,
const int *index);
static const KeySuffix *suff_search(char *str, const KeySuffix *suf, int type);
-static void NUMDesc_prepare(NUMDesc *num, FormatNode *n);
+static void FmtDesc_prepare(FmtDesc *Fmt, FormatNode *n);
static void parse_format(FormatNode *node, char *str, const KeyWord *kw,
- const KeySuffix *suf, const int *index, int ver, NUMDesc *Num);
+ const KeySuffix *suf, const int *index, int ver, FmtDesc *Fmt);
static void DCH_to_char(FormatNode *node, bool is_interval,
TmToChar *in, char *out, Oid collid);
static void do_to_timestamp(text *date_txt, text *fmt,
struct pg_tm * tm, fsec_t *fsec);
static char *fill_str(char *str, int c, int max);
-static FormatNode *NUM_cache(int len, NUMDesc *Num, text *pars_str, bool *shouldFree);
+static FormatNode *NUM_cache(int len, FmtDesc *Fmt, text *pars_str, bool *shouldFree);
static char *int_to_roman(int number);
static void NUM_prepare_locale(NUMProc *Np);
static char *get_last_relevant_decnum(char *num);
static void NUM_numpart_from_char(NUMProc *Np, int id, int input_len);
static void NUM_numpart_to_char(NUMProc *Np, int id);
-static char *NUM_processor(FormatNode *node, NUMDesc *Num, char *inout,
- char *number, int from_char_input_len, int to_char_out_pre_spaces,
+static char *NUM_processor(FormatNode *node, FmtDesc *Fmt, char *inout,
+ char *numstr, int from_char_input_len, int to_char_out_pre_spaces,
int sign, bool is_to_char, Oid collid);
static DCHCacheEntry *DCH_cache_search(char *str);
static DCHCacheEntry *DCH_cache_getnew(char *str);
}
/* ----------
- * Prepare NUMDesc (number description struct) via FormatNode struct
+ * Prepare FmtDesc (number description struct) via FormatNode struct
* ----------
*/
static void
-NUMDesc_prepare(NUMDesc *num, FormatNode *n)
+FmtDesc_prepare(FmtDesc *Fmt, FormatNode *n)
{
if (n->type != NODE_TYPE_ACTION)
return;
*/
PG_TRY();
{
- if (IS_EEEE(num) && n->key->id != NUM_E)
+ if (IS_EEEE(Fmt) && n->key->id != NUM_E)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("\"EEEE\" must be the last pattern used")));
switch (n->key->id)
{
case NUM_9:
- if (IS_BRACKET(num))
+ if (IS_BRACKET(Fmt))
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("\"9\" must be ahead of \"PR\"")));
- if (IS_MULTI(num))
+ if (IS_MULTI(Fmt))
{
- ++num->multi;
+ ++Fmt->multi;
break;
}
- if (IS_DECIMAL(num))
- ++num->post;
+ if (IS_DECIMAL(Fmt))
+ ++Fmt->post;
else
- ++num->pre;
+ ++Fmt->pre;
break;
case NUM_0:
- if (IS_BRACKET(num))
+ if (IS_BRACKET(Fmt))
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("\"0\" must be ahead of \"PR\"")));
- if (!IS_ZERO(num) && !IS_DECIMAL(num))
+ if (!IS_ZERO(Fmt) && !IS_DECIMAL(Fmt))
{
- num->flag |= NUM_F_ZERO;
- num->zero_start = num->pre + 1;
+ Fmt->flag |= NUM_F_ZERO;
+ Fmt->zero_start = Fmt->pre + 1;
}
- if (!IS_DECIMAL(num))
- ++num->pre;
+ if (!IS_DECIMAL(Fmt))
+ ++Fmt->pre;
else
- ++num->post;
+ ++Fmt->post;
- num->zero_end = num->pre + num->post;
+ Fmt->zero_end = Fmt->pre + Fmt->post;
break;
case NUM_B:
- if (num->pre == 0 && num->post == 0 && (!IS_ZERO(num)))
- num->flag |= NUM_F_BLANK;
+ if (Fmt->pre == 0 && Fmt->post == 0 && (!IS_ZERO(Fmt)))
+ Fmt->flag |= NUM_F_BLANK;
break;
case NUM_D:
- num->flag |= NUM_F_LDECIMAL;
- num->need_locale = TRUE;
+ Fmt->flag |= NUM_F_LDECIMAL;
+ Fmt->need_locale = TRUE;
/* FALLTHROUGH */
case NUM_DEC:
- if (IS_DECIMAL(num))
+ if (IS_DECIMAL(Fmt))
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("multiple decimal points")));
- if (IS_MULTI(num))
+ if (IS_MULTI(Fmt))
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"V\" and decimal point together")));
- num->flag |= NUM_F_DECIMAL;
+ Fmt->flag |= NUM_F_DECIMAL;
break;
case NUM_FM:
- num->flag |= NUM_F_FILLMODE;
+ Fmt->flag |= NUM_F_FILLMODE;
break;
case NUM_S:
- if (IS_LSIGN(num))
+ if (IS_LSIGN(Fmt))
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"S\" twice")));
- if (IS_PLUS(num) || IS_MINUS(num) || IS_BRACKET(num))
+ if (IS_PLUS(Fmt) || IS_MINUS(Fmt) || IS_BRACKET(Fmt))
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"S\" and \"PL\"/\"MI\"/\"SG\"/\"PR\" together")));
- if (!IS_DECIMAL(num))
+ if (!IS_DECIMAL(Fmt))
{
- num->lsign = NUM_LSIGN_PRE;
- num->pre_lsign_num = num->pre;
- num->need_locale = TRUE;
- num->flag |= NUM_F_LSIGN;
+ Fmt->lsign = NUM_LSIGN_PRE;
+ Fmt->pre_lsign_num = Fmt->pre;
+ Fmt->need_locale = TRUE;
+ Fmt->flag |= NUM_F_LSIGN;
}
- else if (num->lsign == NUM_LSIGN_NONE)
+ else if (Fmt->lsign == NUM_LSIGN_NONE)
{
- num->lsign = NUM_LSIGN_POST;
- num->need_locale = TRUE;
- num->flag |= NUM_F_LSIGN;
+ Fmt->lsign = NUM_LSIGN_POST;
+ Fmt->need_locale = TRUE;
+ Fmt->flag |= NUM_F_LSIGN;
}
break;
case NUM_MI:
- if (IS_LSIGN(num))
+ if (IS_LSIGN(Fmt))
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"S\" and \"MI\" together")));
- num->flag |= NUM_F_MINUS;
- if (IS_DECIMAL(num))
- num->flag |= NUM_F_MINUS_POST;
+ Fmt->flag |= NUM_F_MINUS;
+ if (IS_DECIMAL(Fmt))
+ Fmt->flag |= NUM_F_MINUS_POST;
break;
case NUM_PL:
- if (IS_LSIGN(num))
+ if (IS_LSIGN(Fmt))
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"S\" and \"PL\" together")));
- num->flag |= NUM_F_PLUS;
- if (IS_DECIMAL(num))
- num->flag |= NUM_F_PLUS_POST;
+ Fmt->flag |= NUM_F_PLUS;
+ if (IS_DECIMAL(Fmt))
+ Fmt->flag |= NUM_F_PLUS_POST;
break;
case NUM_SG:
- if (IS_LSIGN(num))
+ if (IS_LSIGN(Fmt))
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"S\" and \"SG\" together")));
- num->flag |= NUM_F_MINUS;
- num->flag |= NUM_F_PLUS;
+ Fmt->flag |= NUM_F_MINUS;
+ Fmt->flag |= NUM_F_PLUS;
break;
case NUM_PR:
- if (IS_LSIGN(num) || IS_PLUS(num) || IS_MINUS(num))
+ if (IS_LSIGN(Fmt) || IS_PLUS(Fmt) || IS_MINUS(Fmt))
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"PR\" and \"S\"/\"PL\"/\"MI\"/\"SG\" together")));
- num->flag |= NUM_F_BRACKET;
+ Fmt->flag |= NUM_F_BRACKET;
break;
case NUM_rn:
case NUM_RN:
- num->flag |= NUM_F_ROMAN;
+ Fmt->flag |= NUM_F_ROMAN;
break;
case NUM_L:
case NUM_G:
- num->need_locale = TRUE;
+ Fmt->need_locale = TRUE;
break;
case NUM_V:
- if (IS_DECIMAL(num))
+ if (IS_DECIMAL(Fmt))
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"V\" and decimal point together")));
- num->flag |= NUM_F_MULTI;
+ Fmt->flag |= NUM_F_MULTI;
break;
case NUM_E:
- if (IS_EEEE(num))
+ if (IS_EEEE(Fmt))
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"EEEE\" twice")));
- if (IS_BLANK(num) || IS_FILLMODE(num) || IS_LSIGN(num) ||
- IS_BRACKET(num) || IS_MINUS(num) || IS_PLUS(num) ||
- IS_ROMAN(num) || IS_MULTI(num))
+ if (IS_BLANK(Fmt) || IS_FILLMODE(Fmt) || IS_LSIGN(Fmt) ||
+ IS_BRACKET(Fmt) || IS_MINUS(Fmt) || IS_PLUS(Fmt) ||
+ IS_ROMAN(Fmt) || IS_MULTI(Fmt))
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("\"EEEE\" is incompatible with other formats"),
errdetail("\"EEEE\" may only be used together with digit and decimal point patterns.")));
- num->flag |= NUM_F_EEEE;
+ Fmt->flag |= NUM_F_EEEE;
break;
}
}
*/
static void
parse_format(FormatNode *node, char *str, const KeyWord *kw,
- const KeySuffix *suf, const int *index, int ver, NUMDesc *Num)
+ const KeySuffix *suf, const int *index, int ver, FmtDesc *Fmt)
{
const KeySuffix *s;
FormatNode *n;
str += n->key->len;
/*
- * NUM version: Prepare global NUMDesc struct
+ * NUM version: Prepare global FmtDesc struct
*/
if (ver == NUM_TYPE)
- NUMDesc_prepare(Num, n);
+ FmtDesc_prepare(Fmt, n);
/*
* Postfix
++n_NUMCache;
}
- zeroize_NUM(&ent->Num);
+ zeroize_NUM(&ent->Fmt);
last_NUMCacheEntry = ent;
return ent;
* ----------
*/
static FormatNode *
-NUM_cache(int len, NUMDesc *Num, text *pars_str, bool *shouldFree)
+NUM_cache(int len, FmtDesc *Fmt, text *pars_str, bool *shouldFree)
{
FormatNode *format = NULL;
char *str;
*shouldFree = true;
- zeroize_NUM(Num);
+ zeroize_NUM(Fmt);
parse_format(format, str, NUM_keywords,
- NULL, NUM_index, NUM_TYPE, Num);
+ NULL, NUM_index, NUM_TYPE, Fmt);
(format + len)->type = NODE_TYPE_END; /* Paranoia? */
}
* to the cache.
*/
parse_format(ent->format, str, NUM_keywords,
- NULL, NUM_index, NUM_TYPE, &ent->Num);
+ NULL, NUM_index, NUM_TYPE, &ent->Fmt);
(ent->format + len)->type = NODE_TYPE_END; /* Paranoia? */
}
/*
* Copy cache to used struct
*/
- Num->flag = ent->Num.flag;
- Num->lsign = ent->Num.lsign;
- Num->pre = ent->Num.pre;
- Num->post = ent->Num.post;
- Num->pre_lsign_num = ent->Num.pre_lsign_num;
- Num->need_locale = ent->Num.need_locale;
- Num->multi = ent->Num.multi;
- Num->zero_start = ent->Num.zero_start;
- Num->zero_end = ent->Num.zero_end;
+ Fmt->flag = ent->Fmt.flag;
+ Fmt->lsign = ent->Fmt.lsign;
+ Fmt->pre = ent->Fmt.pre;
+ Fmt->post = ent->Fmt.post;
+ Fmt->pre_lsign_num = ent->Fmt.pre_lsign_num;
+ Fmt->need_locale = ent->Fmt.need_locale;
+ Fmt->multi = ent->Fmt.multi;
+ Fmt->zero_start = ent->Fmt.zero_start;
+ Fmt->zero_end = ent->Fmt.zero_end;
}
#ifdef DEBUG_TO_FROM_CHAR
static void
NUM_prepare_locale(NUMProc *Np)
{
- if (Np->Num->need_locale)
+ if (Np->Fmt->need_locale)
{
struct lconv *lconv;
else
Np->decimal = ".";
- if (!IS_LDECIMAL(Np->Num))
+ if (!IS_LDECIMAL(Np->Fmt))
Np->decimal = ".";
/*
/*
* read sign before number
*/
- if (*Np->number == ' ' && (id == NUM_0 || id == NUM_9) &&
+ if (*Np->numstr == ' ' && (id == NUM_0 || id == NUM_9) &&
(Np->read_pre + Np->read_post) == 0)
{
#ifdef DEBUG_TO_FROM_CHAR
/*
* locale sign
*/
- if (IS_LSIGN(Np->Num) && Np->Num->lsign == NUM_LSIGN_PRE)
+ if (IS_LSIGN(Np->Fmt) && Np->Fmt->lsign == NUM_LSIGN_PRE)
{
int x = 0;
strncmp(Np->inout_p, Np->L_negative_sign, x) == 0)
{
Np->inout_p += x;
- *Np->number = '-';
+ *Np->numstr = '-';
}
else if ((x = strlen(Np->L_positive_sign)) &&
AMOUNT_TEST(x) &&
strncmp(Np->inout_p, Np->L_positive_sign, x) == 0)
{
Np->inout_p += x;
- *Np->number = '+';
+ *Np->numstr = '+';
}
}
else
/*
* simple + - < >
*/
- if (*Np->inout_p == '-' || (IS_BRACKET(Np->Num) &&
+ if (*Np->inout_p == '-' || (IS_BRACKET(Np->Fmt) &&
*Np->inout_p == '<'))
{
- *Np->number = '-'; /* set - */
+ *Np->numstr = '-'; /* set - */
Np->inout_p++;
}
else if (*Np->inout_p == '+')
{
- *Np->number = '+'; /* set + */
+ *Np->numstr = '+'; /* set + */
Np->inout_p++;
}
}
return;
#ifdef DEBUG_TO_FROM_CHAR
- elog(DEBUG_elog_output, "Scan for numbers (%c), current number: '%s'", *Np->inout_p, Np->number);
+ elog(DEBUG_elog_output, "Scan for numbers (%c), current number: '%s'", *Np->inout_p, Np->numstr);
#endif
/*
*/
if (isdigit((unsigned char) *Np->inout_p))
{
- if (Np->read_dec && Np->read_post == Np->Num->post)
+ if (Np->read_dec && Np->read_post == Np->Fmt->post)
return;
- *Np->number_p = *Np->inout_p;
- Np->number_p++;
+ *Np->numstr_p = *Np->inout_p;
+ Np->numstr_p++;
if (Np->read_dec)
Np->read_post++;
elog(DEBUG_elog_output, "Read digit (%c)", *Np->inout_p);
#endif
}
- else if (IS_DECIMAL(Np->Num) && Np->read_dec == FALSE)
+ else if (IS_DECIMAL(Np->Fmt) && Np->read_dec == FALSE)
{
/*
- * We need not test IS_LDECIMAL(Np->Num) explicitly here, because
+ * We need not test IS_LDECIMAL(Np->Fmt) explicitly here, because
* Np->decimal is always just "." if we don't have a D format token.
* So we just unconditionally match to Np->decimal.
*/
if (x && AMOUNT_TEST(x) && strncmp(Np->inout_p, Np->decimal, x) == 0)
{
Np->inout_p += x - 1;
- *Np->number_p = '.';
- Np->number_p++;
+ *Np->numstr_p = '.';
+ Np->numstr_p++;
Np->read_dec = TRUE;
isread = TRUE;
}
* FM9999.9999999S -> 123.001- 9.9S -> .5- FM9.999999MI ->
* 5.01-
*/
- if (*Np->number == ' ' && Np->read_pre + Np->read_post > 0)
+ if (*Np->numstr == ' ' && Np->read_pre + Np->read_post > 0)
{
/*
* locale sign (NUM_S) is always anchored behind a last number, if: -
* locale sign expected - last read char was NUM_0/9 or NUM_DEC - and
* next char is not digit
*/
- if (IS_LSIGN(Np->Num) && isread &&
+ if (IS_LSIGN(Np->Fmt) && isread &&
(Np->inout_p + 1) <= Np->inout + input_len &&
!isdigit((unsigned char) *(Np->inout_p + 1)))
{
strncmp(Np->inout_p, Np->L_negative_sign, x) == 0)
{
Np->inout_p += x - 1; /* -1 .. NUM_processor() do inout_p++ */
- *Np->number = '-';
+ *Np->numstr = '-';
}
else if ((x = strlen(Np->L_positive_sign)) &&
AMOUNT_TEST(x) &&
strncmp(Np->inout_p, Np->L_positive_sign, x) == 0)
{
Np->inout_p += x - 1; /* -1 .. NUM_processor() do inout_p++ */
- *Np->number = '+';
+ *Np->numstr = '+';
}
- if (*Np->number == ' ')
+ if (*Np->numstr == ' ')
/* no sign read */
Np->inout_p = tmp;
}
*
* FM9.999999MI -> 5.01-
*
- * if (.... && IS_LSIGN(Np->Num)==FALSE) prevents read wrong formats
+ * if (.... && IS_LSIGN(Np->Fmt)==FALSE) prevents read wrong formats
* like to_number('1 -', '9S') where sign is not anchored to last
* number.
*/
- else if (isread == FALSE && IS_LSIGN(Np->Num) == FALSE &&
- (IS_PLUS(Np->Num) || IS_MINUS(Np->Num)))
+ else if (isread == FALSE && IS_LSIGN(Np->Fmt) == FALSE &&
+ (IS_PLUS(Np->Fmt) || IS_MINUS(Np->Fmt)))
{
#ifdef DEBUG_TO_FROM_CHAR
elog(DEBUG_elog_output, "Try read simple post-sign (%c)", *Np->inout_p);
*/
if (*Np->inout_p == '-' || *Np->inout_p == '+')
/* NUM_processor() do inout_p++ */
- *Np->number = *Np->inout_p;
+ *Np->numstr = *Np->inout_p;
}
}
}
#define IS_PREDEC_SPACE(_n) \
- (IS_ZERO((_n)->Num)==FALSE && \
- (_n)->number == (_n)->number_p && \
- *(_n)->number == '0' && \
- (_n)->Num->post != 0)
+ (IS_ZERO((_n)->Fmt)==FALSE && \
+ (_n)->numstr == (_n)->numstr_p && \
+ *(_n)->numstr == '0' && \
+ (_n)->Fmt->post != 0)
/* ----------
* Add digit or sign to number-string
{
int end;
- if (IS_ROMAN(Np->Num))
+ if (IS_ROMAN(Np->Fmt))
return;
/* Note: in this elog() output not set '\0' in 'inout' */
"SIGN_WROTE: %d, CURRENT: %d, NUMBER_P: \"%s\", INOUT: \"%s\"",
Np->sign_wrote,
Np->num_curr,
- Np->number_p,
+ Np->numstr_p,
Np->inout);
#endif
Np->num_in = FALSE;
* handle "9.9" --> " .1"
*/
if (Np->sign_wrote == FALSE &&
- (Np->num_curr >= Np->out_pre_spaces || (IS_ZERO(Np->Num) && Np->Num->zero_start == Np->num_curr)) &&
+ (Np->num_curr >= Np->out_pre_spaces || (IS_ZERO(Np->Fmt) && Np->Fmt->zero_start == Np->num_curr)) &&
(IS_PREDEC_SPACE(Np) == FALSE || (Np->last_relevant && *Np->last_relevant == '.')))
{
- if (IS_LSIGN(Np->Num))
+ if (IS_LSIGN(Np->Fmt))
{
- if (Np->Num->lsign == NUM_LSIGN_PRE)
+ if (Np->Fmt->lsign == NUM_LSIGN_PRE)
{
if (Np->sign == '-')
strcpy(Np->inout_p, Np->L_negative_sign);
Np->sign_wrote = TRUE;
}
}
- else if (IS_BRACKET(Np->Num))
+ else if (IS_BRACKET(Np->Fmt))
{
*Np->inout_p = Np->sign == '+' ? ' ' : '<';
++Np->inout_p;
}
else if (Np->sign == '+')
{
- if (!IS_FILLMODE(Np->Num))
+ if (!IS_FILLMODE(Np->Fmt))
{
*Np->inout_p = ' '; /* Write + */
++Np->inout_p;
if (id == NUM_9 || id == NUM_0 || id == NUM_D || id == NUM_DEC)
{
if (Np->num_curr < Np->out_pre_spaces &&
- (Np->Num->zero_start > Np->num_curr || !IS_ZERO(Np->Num)))
+ (Np->Fmt->zero_start > Np->num_curr || !IS_ZERO(Np->Fmt)))
{
/*
* Write blank space
*/
- if (!IS_FILLMODE(Np->Num))
+ if (!IS_FILLMODE(Np->Fmt))
{
*Np->inout_p = ' '; /* Write ' ' */
++Np->inout_p;
}
}
- else if (IS_ZERO(Np->Num) &&
+ else if (IS_ZERO(Np->Fmt) &&
Np->num_curr < Np->out_pre_spaces &&
- Np->Num->zero_start <= Np->num_curr)
+ Np->Fmt->zero_start <= Np->num_curr)
{
/*
* Write ZERO
/*
* Write Decimal point
*/
- if (*Np->number_p == '.')
+ if (*Np->numstr_p == '.')
{
if (!Np->last_relevant || *Np->last_relevant != '.')
{
/*
* Ora 'n' -- FM9.9 --> 'n.'
*/
- else if (IS_FILLMODE(Np->Num) &&
+ else if (IS_FILLMODE(Np->Fmt) &&
Np->last_relevant && *Np->last_relevant == '.')
{
strcpy(Np->inout_p, Np->decimal); /* Write DEC/D */
/*
* Write Digits
*/
- if (Np->last_relevant && Np->number_p > Np->last_relevant &&
+ if (Np->last_relevant && Np->numstr_p > Np->last_relevant &&
id != NUM_0)
;
*/
else if (IS_PREDEC_SPACE(Np))
{
- if (!IS_FILLMODE(Np->Num))
+ if (!IS_FILLMODE(Np->Fmt))
{
*Np->inout_p = ' ';
++Np->inout_p;
}
else
{
- *Np->inout_p = *Np->number_p; /* Write DIGIT */
+ *Np->inout_p = *Np->numstr_p; /* Write DIGIT */
++Np->inout_p;
Np->num_in = TRUE;
}
}
- ++Np->number_p;
+ ++Np->numstr_p;
}
- end = Np->num_count + (Np->out_pre_spaces ? 1 : 0) + (IS_DECIMAL(Np->Num) ? 1 : 0);
+ end = Np->num_count + (Np->out_pre_spaces ? 1 : 0) + (IS_DECIMAL(Np->Fmt) ? 1 : 0);
- if (Np->last_relevant && Np->last_relevant == Np->number_p)
+ if (Np->last_relevant && Np->last_relevant == Np->numstr_p)
end = Np->num_curr;
if (Np->num_curr + 1 == end)
{
- if (Np->sign_wrote == TRUE && IS_BRACKET(Np->Num))
+ if (Np->sign_wrote == TRUE && IS_BRACKET(Np->Fmt))
{
*Np->inout_p = Np->sign == '+' ? ' ' : '>';
++Np->inout_p;
}
- else if (IS_LSIGN(Np->Num) && Np->Num->lsign == NUM_LSIGN_POST)
+ else if (IS_LSIGN(Np->Fmt) && Np->Fmt->lsign == NUM_LSIGN_POST)
{
if (Np->sign == '-')
strcpy(Np->inout_p, Np->L_negative_sign);
}
static char *
-NUM_processor(FormatNode *node, NUMDesc *Num, char *inout,
- char *number, int from_char_input_len, int to_char_out_pre_spaces,
+NUM_processor(FormatNode *node, FmtDesc *Fmt, char *inout,
+ char *numstr, int from_char_input_len, int to_char_out_pre_spaces,
int sign, bool is_to_char, Oid collid)
{
FormatNode *n;
MemSet(Np, 0, sizeof(NUMProc));
- Np->Num = Num;
+ Np->Fmt = Fmt;
Np->is_to_char = is_to_char;
- Np->number = number;
+ Np->numstr = numstr;
Np->inout = inout;
Np->last_relevant = NULL;
Np->read_post = 0;
Np->read_pre = 0;
Np->read_dec = FALSE;
- if (Np->Num->zero_start)
- --Np->Num->zero_start;
+ if (Np->Fmt->zero_start)
+ --Np->Fmt->zero_start;
- if (IS_EEEE(Np->Num))
+ if (IS_EEEE(Np->Fmt))
{
if (!Np->is_to_char)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("\"EEEE\" not supported for input")));
- return strcpy(inout, number);
+ return strcpy(inout, numstr);
}
/*
* Roman correction
*/
- if (IS_ROMAN(Np->Num))
+ if (IS_ROMAN(Np->Fmt))
{
if (!Np->is_to_char)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("\"RN\" not supported for input")));
- Np->Num->lsign = Np->Num->pre_lsign_num = Np->Num->post =
- Np->Num->pre = Np->out_pre_spaces = Np->sign = 0;
+ Np->Fmt->lsign = Np->Fmt->pre_lsign_num = Np->Fmt->post =
+ Np->Fmt->pre = Np->out_pre_spaces = Np->sign = 0;
- if (IS_FILLMODE(Np->Num))
+ if (IS_FILLMODE(Np->Fmt))
{
- Np->Num->flag = 0;
- Np->Num->flag |= NUM_F_FILLMODE;
+ Np->Fmt->flag = 0;
+ Np->Fmt->flag |= NUM_F_FILLMODE;
}
else
- Np->Num->flag = 0;
- Np->Num->flag |= NUM_F_ROMAN;
+ Np->Fmt->flag = 0;
+ Np->Fmt->flag |= NUM_F_ROMAN;
}
/*
Np->sign = sign;
/* MI/PL/SG - write sign itself and not in number */
- if (IS_PLUS(Np->Num) || IS_MINUS(Np->Num))
+ if (IS_PLUS(Np->Fmt) || IS_MINUS(Np->Fmt))
{
- if (IS_PLUS(Np->Num) && IS_MINUS(Np->Num) == FALSE)
+ if (IS_PLUS(Np->Fmt) && IS_MINUS(Np->Fmt) == FALSE)
Np->sign_wrote = FALSE; /* need sign */
else
Np->sign_wrote = TRUE; /* needn't sign */
{
if (Np->sign != '-')
{
- if (IS_BRACKET(Np->Num) && IS_FILLMODE(Np->Num))
- Np->Num->flag &= ~NUM_F_BRACKET;
- if (IS_MINUS(Np->Num))
- Np->Num->flag &= ~NUM_F_MINUS;
+ if (IS_BRACKET(Np->Fmt) && IS_FILLMODE(Np->Fmt))
+ Np->Fmt->flag &= ~NUM_F_BRACKET;
+ if (IS_MINUS(Np->Fmt))
+ Np->Fmt->flag &= ~NUM_F_MINUS;
}
- else if (Np->sign != '+' && IS_PLUS(Np->Num))
- Np->Num->flag &= ~NUM_F_PLUS;
+ else if (Np->sign != '+' && IS_PLUS(Np->Fmt))
+ Np->Fmt->flag &= ~NUM_F_PLUS;
- if (Np->sign == '+' && IS_FILLMODE(Np->Num) && IS_LSIGN(Np->Num) == FALSE)
+ if (Np->sign == '+' && IS_FILLMODE(Np->Fmt) && IS_LSIGN(Np->Fmt) == FALSE)
Np->sign_wrote = TRUE; /* needn't sign */
else
Np->sign_wrote = FALSE; /* need sign */
- if (Np->Num->lsign == NUM_LSIGN_PRE && Np->Num->pre == Np->Num->pre_lsign_num)
- Np->Num->lsign = NUM_LSIGN_POST;
+ if (Np->Fmt->lsign == NUM_LSIGN_PRE && Np->Fmt->pre == Np->Fmt->pre_lsign_num)
+ Np->Fmt->lsign = NUM_LSIGN_POST;
}
}
else
/*
* Count
*/
- Np->num_count = Np->Num->post + Np->Num->pre - 1;
+ Np->num_count = Np->Fmt->post + Np->Fmt->pre - 1;
if (is_to_char)
{
Np->out_pre_spaces = to_char_out_pre_spaces;
- if (IS_FILLMODE(Np->Num) && IS_DECIMAL(Np->Num))
+ if (IS_FILLMODE(Np->Fmt) && IS_DECIMAL(Np->Fmt))
{
- Np->last_relevant = get_last_relevant_decnum(Np->number);
+ Np->last_relevant = get_last_relevant_decnum(Np->numstr);
/*
* If any '0' specifiers are present, make sure we don't strip
* those digits.
*/
- if (Np->last_relevant && Np->Num->zero_end > Np->out_pre_spaces)
+ if (Np->last_relevant && Np->Fmt->zero_end > Np->out_pre_spaces)
{
char *last_zero;
- last_zero = Np->number + (Np->Num->zero_end - Np->out_pre_spaces);
+ last_zero = Np->numstr + (Np->Fmt->zero_end - Np->out_pre_spaces);
if (Np->last_relevant < last_zero)
Np->last_relevant = last_zero;
}
else
{
Np->out_pre_spaces = 0;
- *Np->number = ' '; /* sign space */
- *(Np->number + 1) = '\0';
+ *Np->numstr = ' '; /* sign space */
+ *(Np->numstr + 1) = '\0';
}
Np->num_in = 0;
elog(DEBUG_elog_output,
"\n\tSIGN: '%c'\n\tNUM: '%s'\n\tPRE: %d\n\tPOST: %d\n\tNUM_COUNT: %d\n\tNUM_PRE: %d\n\tSIGN_WROTE: %s\n\tZERO: %s\n\tZERO_START: %d\n\tZERO_END: %d\n\tLAST_RELEVANT: %s\n\tBRACKET: %s\n\tPLUS: %s\n\tMINUS: %s\n\tFILLMODE: %s\n\tROMAN: %s\n\tEEEE: %s",
Np->sign,
- Np->number,
- Np->Num->pre,
- Np->Num->post,
+ Np->numstr,
+ Np->Fmt->pre,
+ Np->Fmt->post,
Np->num_count,
Np->out_pre_spaces,
Np->sign_wrote ? "Yes" : "No",
- IS_ZERO(Np->Num) ? "Yes" : "No",
- Np->Num->zero_start,
- Np->Num->zero_end,
+ IS_ZERO(Np->Fmt) ? "Yes" : "No",
+ Np->Fmt->zero_start,
+ Np->Fmt->zero_end,
Np->last_relevant ? Np->last_relevant : "<not set>",
- IS_BRACKET(Np->Num) ? "Yes" : "No",
- IS_PLUS(Np->Num) ? "Yes" : "No",
- IS_MINUS(Np->Num) ? "Yes" : "No",
- IS_FILLMODE(Np->Num) ? "Yes" : "No",
- IS_ROMAN(Np->Num) ? "Yes" : "No",
- IS_EEEE(Np->Num) ? "Yes" : "No"
+ IS_BRACKET(Np->Fmt) ? "Yes" : "No",
+ IS_PLUS(Np->Fmt) ? "Yes" : "No",
+ IS_MINUS(Np->Fmt) ? "Yes" : "No",
+ IS_FILLMODE(Np->Fmt) ? "Yes" : "No",
+ IS_ROMAN(Np->Fmt) ? "Yes" : "No",
+ IS_EEEE(Np->Fmt) ? "Yes" : "No"
);
#endif
* Processor direct cycle
*/
if (Np->is_to_char)
- Np->number_p = Np->number;
+ Np->numstr_p = Np->numstr;
else
- Np->number_p = Np->number + 1; /* first char is space for sign */
+ Np->numstr_p = Np->numstr + 1; /* first char is space for sign */
for (n = node, Np->inout_p = Np->inout; n->type != NODE_TYPE_END; n++)
{
{
if (!Np->num_in)
{
- if (IS_FILLMODE(Np->Num))
+ if (IS_FILLMODE(Np->Fmt))
continue;
else
*Np->inout_p = ' ';
{
if (!Np->num_in)
{
- if (IS_FILLMODE(Np->Num))
+ if (IS_FILLMODE(Np->Fmt))
continue;
}
}
{
if (!Np->num_in)
{
- if (IS_FILLMODE(Np->Num))
+ if (IS_FILLMODE(Np->Fmt))
continue;
else
{
{
if (!Np->num_in)
{
- if (IS_FILLMODE(Np->Num))
+ if (IS_FILLMODE(Np->Fmt))
continue;
}
Np->inout_p += strlen(Np->L_thousands_sep) - 1;
break;
case NUM_RN:
- if (IS_FILLMODE(Np->Num))
+ if (IS_FILLMODE(Np->Fmt))
{
- strcpy(Np->inout_p, Np->number_p);
+ strcpy(Np->inout_p, Np->numstr_p);
Np->inout_p += strlen(Np->inout_p) - 1;
}
else
{
- sprintf(Np->inout_p, "%15s", Np->number_p);
+ sprintf(Np->inout_p, "%15s", Np->numstr_p);
Np->inout_p += strlen(Np->inout_p) - 1;
}
break;
case NUM_rn:
- if (IS_FILLMODE(Np->Num))
+ if (IS_FILLMODE(Np->Fmt))
{
- strcpy(Np->inout_p, asc_tolower_z(Np->number_p));
+ strcpy(Np->inout_p, asc_tolower_z(Np->numstr_p));
Np->inout_p += strlen(Np->inout_p) - 1;
}
else
{
- sprintf(Np->inout_p, "%15s", asc_tolower_z(Np->number_p));
+ sprintf(Np->inout_p, "%15s", asc_tolower_z(Np->numstr_p));
Np->inout_p += strlen(Np->inout_p) - 1;
}
break;
case NUM_th:
- if (IS_ROMAN(Np->Num) || *Np->number == '#' ||
- Np->sign == '-' || IS_DECIMAL(Np->Num))
+ if (IS_ROMAN(Np->Fmt) || *Np->numstr == '#' ||
+ Np->sign == '-' || IS_DECIMAL(Np->Fmt))
continue;
if (Np->is_to_char)
- strcpy(Np->inout_p, get_th(Np->number, TH_LOWER));
+ strcpy(Np->inout_p, get_th(Np->numstr, TH_LOWER));
Np->inout_p += 1;
break;
case NUM_TH:
- if (IS_ROMAN(Np->Num) || *Np->number == '#' ||
- Np->sign == '-' || IS_DECIMAL(Np->Num))
+ if (IS_ROMAN(Np->Fmt) || *Np->numstr == '#' ||
+ Np->sign == '-' || IS_DECIMAL(Np->Fmt))
continue;
if (Np->is_to_char)
- strcpy(Np->inout_p, get_th(Np->number, TH_UPPER));
+ strcpy(Np->inout_p, get_th(Np->numstr, TH_UPPER));
Np->inout_p += 1;
break;
{
if (Np->sign == '-')
*Np->inout_p = '-';
- else if (IS_FILLMODE(Np->Num))
+ else if (IS_FILLMODE(Np->Fmt))
continue;
else
*Np->inout_p = ' ';
else
{
if (*Np->inout_p == '-')
- *Np->number = '-';
+ *Np->numstr = '-';
}
break;
{
if (Np->sign == '+')
*Np->inout_p = '+';
- else if (IS_FILLMODE(Np->Num))
+ else if (IS_FILLMODE(Np->Fmt))
continue;
else
*Np->inout_p = ' ';
else
{
if (*Np->inout_p == '+')
- *Np->number = '+';
+ *Np->numstr = '+';
}
break;
else
{
if (*Np->inout_p == '-')
- *Np->number = '-';
+ *Np->numstr = '-';
else if (*Np->inout_p == '+')
- *Np->number = '+';
+ *Np->numstr = '+';
}
break;
}
else
{
- if (*(Np->number_p - 1) == '.')
- *(Np->number_p - 1) = '\0';
+ if (*(Np->numstr_p - 1) == '.')
+ *(Np->numstr_p - 1) = '\0';
else
- *Np->number_p = '\0';
+ *Np->numstr_p = '\0';
/*
* Correction - precision of dec. number
*/
- Np->Num->post = Np->read_post;
+ Np->Fmt->post = Np->read_post;
#ifdef DEBUG_TO_FROM_CHAR
- elog(DEBUG_elog_output, "TO_NUMBER (number): '%s'", Np->number);
+ elog(DEBUG_elog_output, "TO_NUMBER (numstr): '%s'", Np->numstr);
#endif
- return Np->number;
+ return Np->numstr;
}
}
if (len <= 0 || len >= (INT_MAX-VARHDRSZ)/NUM_MAX_ITEM_SIZ) \
PG_RETURN_TEXT_P(cstring_to_text("")); \
result = (text *) palloc0((len * NUM_MAX_ITEM_SIZ) + 1 + VARHDRSZ); \
- format = NUM_cache(len, &Num, fmt, &shouldFree); \
+ format = NUM_cache(len, &Fmt, fmt, &shouldFree); \
} while (0)
/* ----------
do { \
int len; \
\
- NUM_processor(format, &Num, VARDATA(result), numstr, 0, out_pre_spaces, sign, true, PG_GET_COLLATION()); \
+ NUM_processor(format, &Fmt, VARDATA(result), numstr, 0, out_pre_spaces, sign, true, PG_GET_COLLATION()); \
\
if (shouldFree) \
pfree(format); \
{
text *value = PG_GETARG_TEXT_P(0);
text *fmt = PG_GETARG_TEXT_P(1);
- NUMDesc Num;
+ FmtDesc Fmt;
Datum result;
FormatNode *format;
char *numstr;
if (len <= 0 || len >= INT_MAX / NUM_MAX_ITEM_SIZ)
PG_RETURN_NULL();
- format = NUM_cache(len, &Num, fmt, &shouldFree);
+ format = NUM_cache(len, &Fmt, fmt, &shouldFree);
numstr = (char *) palloc((len * NUM_MAX_ITEM_SIZ) + 1);
- NUM_processor(format, &Num, VARDATA(value), numstr,
+ NUM_processor(format, &Fmt, VARDATA(value), numstr,
VARSIZE(value) - VARHDRSZ, 0, 0, false, PG_GET_COLLATION());
- scale = Num.post;
- precision = Max(0, Num.pre) + scale;
+ scale = Fmt.post;
+ precision = Max(0, Fmt.pre) + scale;
if (shouldFree)
pfree(format);
{
Numeric value = PG_GETARG_NUMERIC(0);
text *fmt = PG_GETARG_TEXT_P(1);
- NUMDesc Num;
+ FmtDesc Fmt;
FormatNode *format;
text *result;
bool shouldFree;
/*
* On DateType depend part (numeric)
*/
- if (IS_ROMAN(&Num))
+ if (IS_ROMAN(&Fmt))
{
x = DatumGetNumeric(DirectFunctionCall2(numeric_round,
NumericGetDatum(value),
int_to_roman(DatumGetInt32(DirectFunctionCall1(numeric_int4,
NumericGetDatum(x))));
}
- else if (IS_EEEE(&Num))
+ else if (IS_EEEE(&Fmt))
{
- orgnum = numeric_out_sci(value, Num.post);
+ orgnum = numeric_out_sci(value, Fmt.post);
/*
* numeric_out_sci() does not emit a sign for positive numbers. We
* Allow 6 characters for the leading sign, the decimal point,
* "e", the exponent's sign and two exponent digits.
*/
- numstr = (char *) palloc(Num.pre + Num.post + 7);
- fill_str(numstr, '#', Num.pre + Num.post + 6);
+ numstr = (char *) palloc(Fmt.pre + Fmt.post + 7);
+ fill_str(numstr, '#', Fmt.pre + Fmt.post + 6);
*numstr = ' ';
- *(numstr + Num.pre + 1) = '.';
+ *(numstr + Fmt.pre + 1) = '.';
}
else if (*orgnum != '-')
{
int numstr_pre_len;
Numeric val = value;
- if (IS_MULTI(&Num))
+ if (IS_MULTI(&Fmt))
{
Numeric a = DatumGetNumeric(DirectFunctionCall1(int4_numeric,
Int32GetDatum(10)));
Numeric b = DatumGetNumeric(DirectFunctionCall1(int4_numeric,
- Int32GetDatum(Num.multi)));
+ Int32GetDatum(Fmt.multi)));
x = DatumGetNumeric(DirectFunctionCall2(numeric_power,
NumericGetDatum(a),
val = DatumGetNumeric(DirectFunctionCall2(numeric_mul,
NumericGetDatum(value),
NumericGetDatum(x)));
- Num.pre += Num.multi;
+ Fmt.pre += Fmt.multi;
}
x = DatumGetNumeric(DirectFunctionCall2(numeric_round,
NumericGetDatum(val),
- Int32GetDatum(Num.post)));
+ Int32GetDatum(Fmt.post)));
orgnum = DatumGetCString(DirectFunctionCall1(numeric_out,
NumericGetDatum(x)));
numstr_pre_len = strlen(numstr);
/* needs padding? */
- if (numstr_pre_len < Num.pre)
- out_pre_spaces = Num.pre - numstr_pre_len;
+ if (numstr_pre_len < Fmt.pre)
+ out_pre_spaces = Fmt.pre - numstr_pre_len;
/* overflowed prefix digit format? */
- else if (numstr_pre_len > Num.pre)
+ else if (numstr_pre_len > Fmt.pre)
{
- numstr = (char *) palloc(Num.pre + Num.post + 2);
- fill_str(numstr, '#', Num.pre + Num.post + 1);
- *(numstr + Num.pre) = '.';
+ numstr = (char *) palloc(Fmt.pre + Fmt.post + 2);
+ fill_str(numstr, '#', Fmt.pre + Fmt.post + 1);
+ *(numstr + Fmt.pre) = '.';
}
}
{
int32 value = PG_GETARG_INT32(0);
text *fmt = PG_GETARG_TEXT_P(1);
- NUMDesc Num;
+ FmtDesc Fmt;
FormatNode *format;
text *result;
bool shouldFree;
/*
* On DateType depend part (int32)
*/
- if (IS_ROMAN(&Num))
+ if (IS_ROMAN(&Fmt))
numstr = orgnum = int_to_roman(value);
- else if (IS_EEEE(&Num))
+ else if (IS_EEEE(&Fmt))
{
/* we can do it easily because float8 won't lose any precision */
float8 val = (float8) value;
orgnum = (char *) palloc(MAXDOUBLEWIDTH + 1);
- snprintf(orgnum, MAXDOUBLEWIDTH + 1, "%+.*e", Num.post, val);
+ snprintf(orgnum, MAXDOUBLEWIDTH + 1, "%+.*e", Fmt.post, val);
/*
* Swap a leading positive sign for a space.
{
int numstr_pre_len;
- if (IS_MULTI(&Num))
+ if (IS_MULTI(&Fmt))
{
orgnum = DatumGetCString(DirectFunctionCall1(int4out,
- Int32GetDatum(value * ((int32) pow((double) 10, (double) Num.multi)))));
- Num.pre += Num.multi;
+ Int32GetDatum(value * ((int32) pow((double) 10, (double) Fmt.multi)))));
+ Fmt.pre += Fmt.multi;
}
else
{
numstr_pre_len = strlen(orgnum);
/* post-decimal digits? Pad out with zeros. */
- if (Num.post)
+ if (Fmt.post)
{
- numstr = (char *) palloc(numstr_pre_len + Num.post + 2);
+ numstr = (char *) palloc(numstr_pre_len + Fmt.post + 2);
strcpy(numstr, orgnum);
*(numstr + numstr_pre_len) = '.';
- memset(numstr + numstr_pre_len + 1, '0', Num.post);
- *(numstr + numstr_pre_len + Num.post + 1) = '\0';
+ memset(numstr + numstr_pre_len + 1, '0', Fmt.post);
+ *(numstr + numstr_pre_len + Fmt.post + 1) = '\0';
}
else
numstr = orgnum;
/* needs padding? */
- if (numstr_pre_len < Num.pre)
- out_pre_spaces = Num.pre - numstr_pre_len;
+ if (numstr_pre_len < Fmt.pre)
+ out_pre_spaces = Fmt.pre - numstr_pre_len;
/* overflowed prefix digit format? */
- else if (numstr_pre_len > Num.pre)
+ else if (numstr_pre_len > Fmt.pre)
{
- numstr = (char *) palloc(Num.pre + Num.post + 2);
- fill_str(numstr, '#', Num.pre + Num.post + 1);
- *(numstr + Num.pre) = '.';
+ numstr = (char *) palloc(Fmt.pre + Fmt.post + 2);
+ fill_str(numstr, '#', Fmt.pre + Fmt.post + 1);
+ *(numstr + Fmt.pre) = '.';
}
}
{
int64 value = PG_GETARG_INT64(0);
text *fmt = PG_GETARG_TEXT_P(1);
- NUMDesc Num;
+ FmtDesc Fmt;
FormatNode *format;
text *result;
bool shouldFree;
/*
* On DateType depend part (int32)
*/
- if (IS_ROMAN(&Num))
+ if (IS_ROMAN(&Fmt))
{
/* Currently don't support int8 conversion to roman... */
numstr = orgnum = int_to_roman(DatumGetInt32(
DirectFunctionCall1(int84, Int64GetDatum(value))));
}
- else if (IS_EEEE(&Num))
+ else if (IS_EEEE(&Fmt))
{
/* to avoid loss of precision, must go via numeric not float8 */
Numeric val;
val = DatumGetNumeric(DirectFunctionCall1(int8_numeric,
Int64GetDatum(value)));
- orgnum = numeric_out_sci(val, Num.post);
+ orgnum = numeric_out_sci(val, Fmt.post);
/*
* numeric_out_sci() does not emit a sign for positive numbers. We
{
int numstr_pre_len;
- if (IS_MULTI(&Num))
+ if (IS_MULTI(&Fmt))
{
- double multi = pow((double) 10, (double) Num.multi);
+ double multi = pow((double) 10, (double) Fmt.multi);
value = DatumGetInt64(DirectFunctionCall2(int8mul,
Int64GetDatum(value),
DirectFunctionCall1(dtoi8,
Float8GetDatum(multi))));
- Num.pre += Num.multi;
+ Fmt.pre += Fmt.multi;
}
orgnum = DatumGetCString(DirectFunctionCall1(int8out,
numstr_pre_len = strlen(orgnum);
/* post-decimal digits? Pad out with zeros. */
- if (Num.post)
+ if (Fmt.post)
{
- numstr = (char *) palloc(numstr_pre_len + Num.post + 2);
+ numstr = (char *) palloc(numstr_pre_len + Fmt.post + 2);
strcpy(numstr, orgnum);
*(numstr + numstr_pre_len) = '.';
- memset(numstr + numstr_pre_len + 1, '0', Num.post);
- *(numstr + numstr_pre_len + Num.post + 1) = '\0';
+ memset(numstr + numstr_pre_len + 1, '0', Fmt.post);
+ *(numstr + numstr_pre_len + Fmt.post + 1) = '\0';
}
else
numstr = orgnum;
/* needs padding? */
- if (numstr_pre_len < Num.pre)
- out_pre_spaces = Num.pre - numstr_pre_len;
+ if (numstr_pre_len < Fmt.pre)
+ out_pre_spaces = Fmt.pre - numstr_pre_len;
/* overflowed prefix digit format? */
- else if (numstr_pre_len > Num.pre)
+ else if (numstr_pre_len > Fmt.pre)
{
- numstr = (char *) palloc(Num.pre + Num.post + 2);
- fill_str(numstr, '#', Num.pre + Num.post + 1);
- *(numstr + Num.pre) = '.';
+ numstr = (char *) palloc(Fmt.pre + Fmt.post + 2);
+ fill_str(numstr, '#', Fmt.pre + Fmt.post + 1);
+ *(numstr + Fmt.pre) = '.';
}
}
{
float4 value = PG_GETARG_FLOAT4(0);
text *fmt = PG_GETARG_TEXT_P(1);
- NUMDesc Num;
+ FmtDesc Fmt;
FormatNode *format;
text *result;
bool shouldFree;
NUM_TOCHAR_prepare;
- if (IS_ROMAN(&Num))
+ if (IS_ROMAN(&Fmt))
numstr = orgnum = int_to_roman((int) rint(value));
- else if (IS_EEEE(&Num))
+ else if (IS_EEEE(&Fmt))
{
numstr = orgnum = (char *) palloc(MAXDOUBLEWIDTH + 1);
if (isnan(value) || is_infinite(value))
* Allow 6 characters for the leading sign, the decimal point,
* "e", the exponent's sign and two exponent digits.
*/
- numstr = (char *) palloc(Num.pre + Num.post + 7);
- fill_str(numstr, '#', Num.pre + Num.post + 6);
+ numstr = (char *) palloc(Fmt.pre + Fmt.post + 7);
+ fill_str(numstr, '#', Fmt.pre + Fmt.post + 6);
*numstr = ' ';
- *(numstr + Num.pre + 1) = '.';
+ *(numstr + Fmt.pre + 1) = '.';
}
else
{
- snprintf(orgnum, MAXDOUBLEWIDTH + 1, "%+.*e", Num.post, value);
+ snprintf(orgnum, MAXDOUBLEWIDTH + 1, "%+.*e", Fmt.post, value);
/*
* Swap a leading positive sign for a space.
float4 val = value;
int numstr_pre_len;
- if (IS_MULTI(&Num))
+ if (IS_MULTI(&Fmt))
{
- float multi = pow((double) 10, (double) Num.multi);
+ float multi = pow((double) 10, (double) Fmt.multi);
val = value * multi;
- Num.pre += Num.multi;
+ Fmt.pre += Fmt.multi;
}
orgnum = (char *) palloc(MAXFLOATWIDTH + 1);
/* adjust post digits to fit max float digits */
if (numstr_pre_len >= FLT_DIG)
- Num.post = 0;
- else if (numstr_pre_len + Num.post > FLT_DIG)
- Num.post = FLT_DIG - numstr_pre_len;
- snprintf(orgnum, MAXFLOATWIDTH + 1, "%.*f", Num.post, val);
+ Fmt.post = 0;
+ else if (numstr_pre_len + Fmt.post > FLT_DIG)
+ Fmt.post = FLT_DIG - numstr_pre_len;
+ snprintf(orgnum, MAXFLOATWIDTH + 1, "%.*f", Fmt.post, val);
if (*orgnum == '-')
{ /* < 0 */
numstr_pre_len = strlen(numstr);
/* needs padding? */
- if (numstr_pre_len < Num.pre)
- out_pre_spaces = Num.pre - numstr_pre_len;
+ if (numstr_pre_len < Fmt.pre)
+ out_pre_spaces = Fmt.pre - numstr_pre_len;
/* overflowed prefix digit format? */
- else if (numstr_pre_len > Num.pre)
+ else if (numstr_pre_len > Fmt.pre)
{
- numstr = (char *) palloc(Num.pre + Num.post + 2);
- fill_str(numstr, '#', Num.pre + Num.post + 1);
- *(numstr + Num.pre) = '.';
+ numstr = (char *) palloc(Fmt.pre + Fmt.post + 2);
+ fill_str(numstr, '#', Fmt.pre + Fmt.post + 1);
+ *(numstr + Fmt.pre) = '.';
}
}
{
float8 value = PG_GETARG_FLOAT8(0);
text *fmt = PG_GETARG_TEXT_P(1);
- NUMDesc Num;
+ FmtDesc Fmt;
FormatNode *format;
text *result;
bool shouldFree;
NUM_TOCHAR_prepare;
- if (IS_ROMAN(&Num))
+ if (IS_ROMAN(&Fmt))
numstr = orgnum = int_to_roman((int) rint(value));
- else if (IS_EEEE(&Num))
+ else if (IS_EEEE(&Fmt))
{
numstr = orgnum = (char *) palloc(MAXDOUBLEWIDTH + 1);
if (isnan(value) || is_infinite(value))
* Allow 6 characters for the leading sign, the decimal point,
* "e", the exponent's sign and two exponent digits.
*/
- numstr = (char *) palloc(Num.pre + Num.post + 7);
- fill_str(numstr, '#', Num.pre + Num.post + 6);
+ numstr = (char *) palloc(Fmt.pre + Fmt.post + 7);
+ fill_str(numstr, '#', Fmt.pre + Fmt.post + 6);
*numstr = ' ';
- *(numstr + Num.pre + 1) = '.';
+ *(numstr + Fmt.pre + 1) = '.';
}
else
{
- snprintf(orgnum, MAXDOUBLEWIDTH + 1, "%+.*e", Num.post, value);
+ snprintf(orgnum, MAXDOUBLEWIDTH + 1, "%+.*e", Fmt.post, value);
/*
* Swap a leading positive sign for a space.
float8 val = value;
int numstr_pre_len;
- if (IS_MULTI(&Num))
+ if (IS_MULTI(&Fmt))
{
- double multi = pow((double) 10, (double) Num.multi);
+ double multi = pow((double) 10, (double) Fmt.multi);
val = value * multi;
- Num.pre += Num.multi;
+ Fmt.pre += Fmt.multi;
}
orgnum = (char *) palloc(MAXDOUBLEWIDTH + 1);
numstr_pre_len = snprintf(orgnum, MAXDOUBLEWIDTH + 1, "%.0f", fabs(val));
/* adjust post digits to fit max double digits */
if (numstr_pre_len >= DBL_DIG)
- Num.post = 0;
- else if (numstr_pre_len + Num.post > DBL_DIG)
- Num.post = DBL_DIG - numstr_pre_len;
- snprintf(orgnum, MAXDOUBLEWIDTH + 1, "%.*f", Num.post, val);
+ Fmt.post = 0;
+ else if (numstr_pre_len + Fmt.post > DBL_DIG)
+ Fmt.post = DBL_DIG - numstr_pre_len;
+ snprintf(orgnum, MAXDOUBLEWIDTH + 1, "%.*f", Fmt.post, val);
if (*orgnum == '-')
{ /* < 0 */
numstr_pre_len = strlen(numstr);
/* needs padding? */
- if (numstr_pre_len < Num.pre)
- out_pre_spaces = Num.pre - numstr_pre_len;
+ if (numstr_pre_len < Fmt.pre)
+ out_pre_spaces = Fmt.pre - numstr_pre_len;
/* overflowed prefix digit format? */
- else if (numstr_pre_len > Num.pre)
+ else if (numstr_pre_len > Fmt.pre)
{
- numstr = (char *) palloc(Num.pre + Num.post + 2);
- fill_str(numstr, '#', Num.pre + Num.post + 1);
- *(numstr + Num.pre) = '.';
+ numstr = (char *) palloc(Fmt.pre + Fmt.post + 2);
+ fill_str(numstr, '#', Fmt.pre + Fmt.post + 1);
+ *(numstr + Fmt.pre) = '.';
}
}