mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +03:00
formatting.c cleanup: Change several int fields to enums
This makes their purpose more self-documenting. Reviewed-by: Chao Li <li.evan.chao@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/6dd9d208-a3ed-49b5-b03d-8617261da973%40eisentraut.org
This commit is contained in:
@@ -115,12 +115,19 @@
|
|||||||
/*
|
/*
|
||||||
* Format parser structs
|
* Format parser structs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
enum KeySuffixType
|
||||||
|
{
|
||||||
|
SUFFTYPE_PREFIX = 1,
|
||||||
|
SUFFTYPE_POSTFIX = 2,
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
const char *name; /* suffix string */
|
const char *name; /* suffix string */
|
||||||
size_t len; /* suffix length */
|
size_t len; /* suffix length */
|
||||||
int id; /* used in node->suffix */
|
int id; /* used in node->suffix */
|
||||||
int type; /* prefix / postfix */
|
enum KeySuffixType type; /* prefix / postfix */
|
||||||
} KeySuffix;
|
} KeySuffix;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -145,23 +152,23 @@ typedef struct
|
|||||||
FromCharDateMode date_mode;
|
FromCharDateMode date_mode;
|
||||||
} KeyWord;
|
} KeyWord;
|
||||||
|
|
||||||
|
enum FormatNodeType
|
||||||
|
{
|
||||||
|
NODE_TYPE_END = 1,
|
||||||
|
NODE_TYPE_ACTION = 2,
|
||||||
|
NODE_TYPE_CHAR = 3,
|
||||||
|
NODE_TYPE_SEPARATOR = 4,
|
||||||
|
NODE_TYPE_SPACE = 5,
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8 type; /* NODE_TYPE_XXX, see below */
|
enum FormatNodeType type;
|
||||||
char character[MAX_MULTIBYTE_CHAR_LEN + 1]; /* if type is CHAR */
|
char character[MAX_MULTIBYTE_CHAR_LEN + 1]; /* if type is CHAR */
|
||||||
uint8 suffix; /* keyword prefix/suffix code, if any */
|
uint8 suffix; /* keyword prefix/suffix code, if any (DCH_S_*) */
|
||||||
const KeyWord *key; /* if type is ACTION */
|
const KeyWord *key; /* if type is ACTION */
|
||||||
} FormatNode;
|
} FormatNode;
|
||||||
|
|
||||||
#define NODE_TYPE_END 1
|
|
||||||
#define NODE_TYPE_ACTION 2
|
|
||||||
#define NODE_TYPE_CHAR 3
|
|
||||||
#define NODE_TYPE_SEPARATOR 4
|
|
||||||
#define NODE_TYPE_SPACE 5
|
|
||||||
|
|
||||||
#define SUFFTYPE_PREFIX 1
|
|
||||||
#define SUFFTYPE_POSTFIX 2
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Full months
|
* Full months
|
||||||
@@ -286,8 +293,18 @@ static const char *const numth[] = {"st", "nd", "rd", "th", NULL};
|
|||||||
/*
|
/*
|
||||||
* Flags & Options:
|
* Flags & Options:
|
||||||
*/
|
*/
|
||||||
#define TH_UPPER 1
|
enum TH_Case
|
||||||
#define TH_LOWER 2
|
{
|
||||||
|
TH_UPPER = 1,
|
||||||
|
TH_LOWER = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum NUMDesc_lsign
|
||||||
|
{
|
||||||
|
NUM_LSIGN_PRE = -1,
|
||||||
|
NUM_LSIGN_POST = 1,
|
||||||
|
NUM_LSIGN_NONE = 0,
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Number description struct
|
* Number description struct
|
||||||
@@ -296,13 +313,13 @@ typedef struct
|
|||||||
{
|
{
|
||||||
int pre; /* (count) numbers before decimal */
|
int pre; /* (count) numbers before decimal */
|
||||||
int post; /* (count) numbers after decimal */
|
int post; /* (count) numbers after decimal */
|
||||||
int lsign; /* want locales sign */
|
enum NUMDesc_lsign lsign; /* want locales sign */
|
||||||
int flag; /* number parameters */
|
int flag; /* number parameters (NUM_F_*) */
|
||||||
int pre_lsign_num; /* tmp value for lsign */
|
int pre_lsign_num; /* tmp value for lsign */
|
||||||
int multi; /* multiplier for 'V' */
|
int multi; /* multiplier for 'V' */
|
||||||
int zero_start; /* position of first zero */
|
int zero_start; /* position of first zero */
|
||||||
int zero_end; /* position of last zero */
|
int zero_end; /* position of last zero */
|
||||||
int need_locale; /* needs it locale */
|
bool need_locale; /* needs it locale */
|
||||||
} NUMDesc;
|
} NUMDesc;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -323,10 +340,6 @@ typedef struct
|
|||||||
#define NUM_F_MINUS_POST (1 << 13)
|
#define NUM_F_MINUS_POST (1 << 13)
|
||||||
#define NUM_F_EEEE (1 << 14)
|
#define NUM_F_EEEE (1 << 14)
|
||||||
|
|
||||||
#define NUM_LSIGN_PRE (-1)
|
|
||||||
#define NUM_LSIGN_POST 1
|
|
||||||
#define NUM_LSIGN_NONE 0
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tests
|
* Tests
|
||||||
*/
|
*/
|
||||||
@@ -553,7 +566,12 @@ do { \
|
|||||||
#define S_THth(_s) ((((_s) & DCH_S_TH) || ((_s) & DCH_S_th)) ? 1 : 0)
|
#define S_THth(_s) ((((_s) & DCH_S_TH) || ((_s) & DCH_S_th)) ? 1 : 0)
|
||||||
#define S_TH(_s) (((_s) & DCH_S_TH) ? 1 : 0)
|
#define S_TH(_s) (((_s) & DCH_S_TH) ? 1 : 0)
|
||||||
#define S_th(_s) (((_s) & DCH_S_th) ? 1 : 0)
|
#define S_th(_s) (((_s) & DCH_S_th) ? 1 : 0)
|
||||||
#define S_TH_TYPE(_s) (((_s) & DCH_S_TH) ? TH_UPPER : TH_LOWER)
|
|
||||||
|
static inline enum TH_Case
|
||||||
|
S_TH_TYPE(uint8 _s)
|
||||||
|
{
|
||||||
|
return _s & DCH_S_TH ? TH_UPPER : TH_LOWER;
|
||||||
|
}
|
||||||
|
|
||||||
/* Oracle toggles FM behavior, we don't; see docs. */
|
/* Oracle toggles FM behavior, we don't; see docs. */
|
||||||
#define S_FM(_s) (((_s) & DCH_S_FM) ? 1 : 0)
|
#define S_FM(_s) (((_s) & DCH_S_FM) ? 1 : 0)
|
||||||
@@ -1034,7 +1052,7 @@ typedef struct NUMProc
|
|||||||
*/
|
*/
|
||||||
static const KeyWord *index_seq_search(const char *str, const KeyWord *kw,
|
static const KeyWord *index_seq_search(const char *str, const KeyWord *kw,
|
||||||
const int *index);
|
const int *index);
|
||||||
static const KeySuffix *suff_search(const char *str, const KeySuffix *suf, int type);
|
static const KeySuffix *suff_search(const char *str, const KeySuffix *suf, enum KeySuffixType type);
|
||||||
static bool is_separator_char(const char *str);
|
static bool is_separator_char(const char *str);
|
||||||
static void NUMDesc_prepare(NUMDesc *num, FormatNode *n);
|
static void NUMDesc_prepare(NUMDesc *num, FormatNode *n);
|
||||||
static void parse_format(FormatNode *node, const char *str, const KeyWord *kw,
|
static void parse_format(FormatNode *node, const char *str, const KeyWord *kw,
|
||||||
@@ -1050,8 +1068,8 @@ static void dump_index(const KeyWord *k, const int *index);
|
|||||||
static void dump_node(FormatNode *node, int max);
|
static void dump_node(FormatNode *node, int max);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char *get_th(const char *num, int type);
|
static const char *get_th(const char *num, enum TH_Case type);
|
||||||
static char *str_numth(char *dest, const char *num, int type);
|
static char *str_numth(char *dest, const char *num, enum TH_Case type);
|
||||||
static int adjust_partial_year_to_2020(int year);
|
static int adjust_partial_year_to_2020(int year);
|
||||||
static size_t strspace_len(const char *str);
|
static size_t strspace_len(const char *str);
|
||||||
static bool from_char_set_mode(TmFromChar *tmfc, const FromCharDateMode mode,
|
static bool from_char_set_mode(TmFromChar *tmfc, const FromCharDateMode mode,
|
||||||
@@ -1121,7 +1139,7 @@ index_seq_search(const char *str, const KeyWord *kw, const int *index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const KeySuffix *
|
static const KeySuffix *
|
||||||
suff_search(const char *str, const KeySuffix *suf, int type)
|
suff_search(const char *str, const KeySuffix *suf, enum KeySuffixType type)
|
||||||
{
|
{
|
||||||
for (const KeySuffix *s = suf; s->name != NULL; s++)
|
for (const KeySuffix *s = suf; s->name != NULL; s++)
|
||||||
{
|
{
|
||||||
@@ -1516,10 +1534,9 @@ dump_node(FormatNode *node, int max)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Return ST/ND/RD/TH for simple (1..9) numbers
|
* Return ST/ND/RD/TH for simple (1..9) numbers
|
||||||
* type --> 0 upper, 1 lower
|
|
||||||
*/
|
*/
|
||||||
static const char *
|
static const char *
|
||||||
get_th(const char *num, int type)
|
get_th(const char *num, enum TH_Case type)
|
||||||
{
|
{
|
||||||
size_t len = strlen(num);
|
size_t len = strlen(num);
|
||||||
char last;
|
char last;
|
||||||
@@ -1562,10 +1579,9 @@ get_th(const char *num, int type)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Convert string-number to ordinal string-number
|
* Convert string-number to ordinal string-number
|
||||||
* type --> 0 upper, 1 lower
|
|
||||||
*/
|
*/
|
||||||
static char *
|
static char *
|
||||||
str_numth(char *dest, const char *num, int type)
|
str_numth(char *dest, const char *num, enum TH_Case type)
|
||||||
{
|
{
|
||||||
if (dest != num)
|
if (dest != num)
|
||||||
strcpy(dest, num);
|
strcpy(dest, num);
|
||||||
|
|||||||
Reference in New Issue
Block a user