diff options
author | Bruce Momjian | 2005-12-25 02:14:19 +0000 |
---|---|---|
committer | Bruce Momjian | 2005-12-25 02:14:19 +0000 |
commit | c896eb61de7e51b9986bfb1469d02ea9b23471b1 (patch) | |
tree | 9313a081787cfc6af38926d5fc53348bf67bc736 | |
parent | 96967d72436eea3171b9bb1106dcb80d82d939de (diff) |
I have added these macros to c.h:
#define HIGHBIT (0x80)
#define IS_HIGHBIT_SET(ch) ((unsigned char)(ch) & HIGHBIT)
and removed CSIGNBIT and mapped it uses to HIGHBIT. I have also added
uses for IS_HIGHBIT_SET where appropriate. This change is
purely for code clarity.
-rw-r--r-- | src/backend/access/common/heaptuple.c | 8 | ||||
-rw-r--r-- | src/backend/parser/scansup.c | 2 | ||||
-rw-r--r-- | src/backend/utils/adt/network.c | 10 | ||||
-rw-r--r-- | src/backend/utils/adt/varbit.c | 12 | ||||
-rw-r--r-- | src/backend/utils/mb/conv.c | 2 | ||||
-rw-r--r-- | src/backend/utils/mb/conversion_procs/euc_cn_and_mic/euc_cn_and_mic.c | 2 | ||||
-rw-r--r-- | src/backend/utils/mb/conversion_procs/euc_kr_and_mic/euc_kr_and_mic.c | 2 | ||||
-rw-r--r-- | src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c | 2 | ||||
-rw-r--r-- | src/backend/utils/mb/conversion_procs/utf8_and_iso8859_1/utf8_and_iso8859_1.c | 4 | ||||
-rw-r--r-- | src/backend/utils/mb/wchar.c | 24 | ||||
-rw-r--r-- | src/include/c.h | 3 | ||||
-rw-r--r-- | src/include/utils/varbit.h | 1 | ||||
-rw-r--r-- | src/port/pgstrcasecmp.c | 12 |
13 files changed, 42 insertions, 42 deletions
diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c index 15debb642d..269db834b9 100644 --- a/src/backend/access/common/heaptuple.c +++ b/src/backend/access/common/heaptuple.c @@ -111,7 +111,7 @@ heap_fill_tuple(TupleDesc tupleDesc, if (bit != NULL) { bitP = &bit[-1]; - bitmask = CSIGNBIT; + bitmask = HIGHBIT; } else { @@ -128,7 +128,7 @@ heap_fill_tuple(TupleDesc tupleDesc, if (bit != NULL) { - if (bitmask != CSIGNBIT) + if (bitmask != HIGHBIT) bitmask <<= 1; else { @@ -210,7 +210,7 @@ DataFill(char *data, if (bit != NULL) { bitP = &bit[-1]; - bitmask = CSIGNBIT; + bitmask = HIGHBIT; } else { @@ -227,7 +227,7 @@ DataFill(char *data, if (bit != NULL) { - if (bitmask != CSIGNBIT) + if (bitmask != HIGHBIT) bitmask <<= 1; else { diff --git a/src/backend/parser/scansup.c b/src/backend/parser/scansup.c index 7efe565798..e46bca366d 100644 --- a/src/backend/parser/scansup.c +++ b/src/backend/parser/scansup.c @@ -149,7 +149,7 @@ downcase_truncate_identifier(const char *ident, int len, bool warn) if (ch >= 'A' && ch <= 'Z') ch += 'a' - 'A'; - else if (ch >= 0x80 && isupper(ch)) + else if (IS_HIGHBIT_SET(ch) && isupper(ch)) ch = tolower(ch); result[i] = (char) ch; } diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c index d5efd806cf..564a4aaa1e 100644 --- a/src/backend/utils/adt/network.c +++ b/src/backend/utils/adt/network.c @@ -904,16 +904,16 @@ bitncmp(void *l, void *r, int n) rb = ((const u_char *) r)[b]; for (b = n % 8; b > 0; b--) { - if ((lb & 0x80) != (rb & 0x80)) + if (IS_HIGHBIT_SET(lb) != IS_HIGHBIT_SET(rb)) { - if (lb & 0x80) - return (1); - return (-1); + if (IS_HIGHBIT_SET(lb)) + return 1; + return -1; } lb <<= 1; rb <<= 1; } - return (0); + return 0; } static bool diff --git a/src/backend/utils/adt/varbit.c b/src/backend/utils/adt/varbit.c index 22cab68903..f053832ce0 100644 --- a/src/backend/utils/adt/varbit.c +++ b/src/backend/utils/adt/varbit.c @@ -120,7 +120,7 @@ bit_in(PG_FUNCTION_ARGS) { /* Parse the bit representation of the string */ /* We know it fits, as bitlen was compared to atttypmod */ - x = BITHIGH; + x = HIGHBIT; for (; *sp; sp++) { if (*sp == '1') @@ -134,7 +134,7 @@ bit_in(PG_FUNCTION_ARGS) x >>= 1; if (x == 0) { - x = BITHIGH; + x = HIGHBIT; r++; } } @@ -401,7 +401,7 @@ varbit_in(PG_FUNCTION_ARGS) { /* Parse the bit representation of the string */ /* We know it fits, as bitlen was compared to atttypmod */ - x = BITHIGH; + x = HIGHBIT; for (; *sp; sp++) { if (*sp == '1') @@ -415,7 +415,7 @@ varbit_in(PG_FUNCTION_ARGS) x >>= 1; if (x == 0) { - x = BITHIGH; + x = HIGHBIT; r++; } } @@ -477,14 +477,14 @@ varbit_out(PG_FUNCTION_ARGS) x = *sp; for (k = 0; k < BITS_PER_BYTE; k++) { - *r++ = (x & BITHIGH) ? '1' : '0'; + *r++ = IS_HIGHBIT_SET(x) ? '1' : '0'; x <<= 1; } } x = *sp; for (k = i; k < len; k++) { - *r++ = (x & BITHIGH) ? '1' : '0'; + *r++ = IS_HIGHBIT_SET(x) ? '1' : '0'; x <<= 1; } *r = '\0'; diff --git a/src/backend/utils/mb/conv.c b/src/backend/utils/mb/conv.c index ff871780f1..c05e9d30b7 100644 --- a/src/backend/utils/mb/conv.c +++ b/src/backend/utils/mb/conv.c @@ -413,7 +413,7 @@ LocalToUtf(unsigned char *iso, unsigned char *utf, for (; len > 0 && *iso; len -= l) { - if (*iso < 0x80) + if (!IS_HIGHBIT_SET(*iso)) { *utf++ = *iso++; l = 1; diff --git a/src/backend/utils/mb/conversion_procs/euc_cn_and_mic/euc_cn_and_mic.c b/src/backend/utils/mb/conversion_procs/euc_cn_and_mic/euc_cn_and_mic.c index 72d70e8531..c280e2a63b 100644 --- a/src/backend/utils/mb/conversion_procs/euc_cn_and_mic/euc_cn_and_mic.c +++ b/src/backend/utils/mb/conversion_procs/euc_cn_and_mic/euc_cn_and_mic.c @@ -77,7 +77,7 @@ euc_cn2mic(unsigned char *euc, unsigned char *p, int len) while (len >= 0 && (c1 = *euc++)) { - if (c1 & 0x80) + if (IS_HIGHBIT_SET(c1)) { len -= 2; *p++ = LC_GB2312_80; diff --git a/src/backend/utils/mb/conversion_procs/euc_kr_and_mic/euc_kr_and_mic.c b/src/backend/utils/mb/conversion_procs/euc_kr_and_mic/euc_kr_and_mic.c index e4f70b66a5..648936377d 100644 --- a/src/backend/utils/mb/conversion_procs/euc_kr_and_mic/euc_kr_and_mic.c +++ b/src/backend/utils/mb/conversion_procs/euc_kr_and_mic/euc_kr_and_mic.c @@ -77,7 +77,7 @@ euc_kr2mic(unsigned char *euc, unsigned char *p, int len) while (len >= 0 && (c1 = *euc++)) { - if (c1 & 0x80) + if (IS_HIGHBIT_SET(c1)) { len -= 2; *p++ = LC_KS5601; diff --git a/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c b/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c index 3063bdfd85..8278d11a6c 100644 --- a/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c +++ b/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c @@ -177,7 +177,7 @@ euc_tw2mic(unsigned char *euc, unsigned char *p, int len) *p++ = *euc++; *p++ = *euc++; } - else if (c1 & 0x80) + else if (IS_HIGHBIT_SET(c1)) { /* CNS11643-1 */ len -= 2; *p++ = LC_CNS11643_1; diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_iso8859_1/utf8_and_iso8859_1.c b/src/backend/utils/mb/conversion_procs/utf8_and_iso8859_1/utf8_and_iso8859_1.c index 034b657055..0019f95bd1 100644 --- a/src/backend/utils/mb/conversion_procs/utf8_and_iso8859_1/utf8_and_iso8859_1.c +++ b/src/backend/utils/mb/conversion_procs/utf8_and_iso8859_1/utf8_and_iso8859_1.c @@ -46,12 +46,12 @@ iso8859_1_to_utf8(PG_FUNCTION_ARGS) while (len-- > 0 && (c = *src++)) { - if (c < 0x80) + if (!IS_HIGHBIT_SET(c)) *dest++ = c; else { *dest++ = (c >> 6) | 0xc0; - *dest++ = (c & 0x003f) | 0x80; + *dest++ = (c & 0x003f) | HIGHBIT; } } *dest = '\0'; diff --git a/src/backend/utils/mb/wchar.c b/src/backend/utils/mb/wchar.c index 2d891b5d67..d7d03a0b9e 100644 --- a/src/backend/utils/mb/wchar.c +++ b/src/backend/utils/mb/wchar.c @@ -79,7 +79,7 @@ static int pg_euc2wchar_with_len *to |= *from++; len -= 3; } - else if ((*from & 0x80) && len >= 2) /* JIS X 0208 KANJI */ + else if (IS_HIGHBIT_SET(*from) && len >= 2) /* JIS X 0208 KANJI */ { *to = *from++ << 8; *to |= *from++; @@ -106,7 +106,7 @@ pg_euc_mblen(const unsigned char *s) len = 2; else if (*s == SS3) len = 3; - else if (*s & 0x80) + else if (IS_HIGHBIT_SET(*s)) len = 2; else len = 1; @@ -122,7 +122,7 @@ pg_euc_dsplen(const unsigned char *s) len = 2; else if (*s == SS3) len = 2; - else if (*s & 0x80) + else if (IS_HIGHBIT_SET(*s)) len = 2; else len = 1; @@ -153,7 +153,7 @@ pg_eucjp_dsplen(const unsigned char *s) len = 1; else if (*s == SS3) len = 2; - else if (*s & 0x80) + else if (IS_HIGHBIT_SET(*s)) len = 2; else len = 1; @@ -206,7 +206,7 @@ static int pg_euccn2wchar_with_len *to |= *from++; len -= 3; } - else if ((*from & 0x80) && len >= 2) /* code set 1 */ + else if (IS_HIGHBIT_SET(*from) && len >= 2) /* code set 1 */ { *to = *from++ << 8; *to |= *from++; @@ -229,7 +229,7 @@ pg_euccn_mblen(const unsigned char *s) { int len; - if (*s & 0x80) + if (IS_HIGHBIT_SET(*s)) len = 2; else len = 1; @@ -241,7 +241,7 @@ pg_euccn_dsplen(const unsigned char *s) { int len; - if (*s & 0x80) + if (IS_HIGHBIT_SET(*s)) len = 2; else len = 1; @@ -274,7 +274,7 @@ static int pg_euctw2wchar_with_len *to |= *from++; len -= 3; } - else if ((*from & 0x80) && len >= 2) /* code set 2 */ + else if (IS_HIGHBIT_SET(*from) && len >= 2) /* code set 2 */ { *to = *from++ << 8; *to |= *from++; @@ -301,7 +301,7 @@ pg_euctw_mblen(const unsigned char *s) len = 4; else if (*s == SS3) len = 3; - else if (*s & 0x80) + else if (IS_HIGHBIT_SET(*s)) len = 2; else len = 1; @@ -317,7 +317,7 @@ pg_euctw_dsplen(const unsigned char *s) len = 2; else if (*s == SS3) len = 2; - else if (*s & 0x80) + else if (IS_HIGHBIT_SET(*s)) len = 2; else len = 1; @@ -361,7 +361,7 @@ pg_utf2wchar_with_len(const unsigned char *from, pg_wchar *to, int len) while (len > 0 && *from) { - if ((*from & 0x80) == 0) + if (!IS_HIGHBIT_SET(*from)) { *to = *from++; len--; @@ -866,7 +866,7 @@ pg_verifymbstr(const char *mbstr, int len, bool noError) * we expect that every multibyte char consists of bytes * having the 8th bit set */ - if (i >= len || (mbstr[i] & 0x80) == 0) + if (i >= len || !IS_HIGHBIT_SET(mbstr[i])) { char buf[8 * 2 + 1]; char *p = buf; diff --git a/src/include/c.h b/src/include/c.h index e40557bad5..49207f02a6 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -704,7 +704,8 @@ typedef NameData *Name; */ /* msb for char */ -#define CSIGNBIT (0x80) +#define HIGHBIT (0x80) +#define IS_HIGHBIT_SET(ch) ((unsigned char)(ch) & HIGHBIT) #define STATUS_OK (0) #define STATUS_ERROR (-1) diff --git a/src/include/utils/varbit.h b/src/include/utils/varbit.h index e4ea974c74..e2c0c12dbf 100644 --- a/src/include/utils/varbit.h +++ b/src/include/utils/varbit.h @@ -58,7 +58,6 @@ typedef struct #define VARBITEND(PTR) (((bits8 *) (PTR)) + VARSIZE(PTR)) /* Mask that will cover exactly one byte, i.e. BITS_PER_BYTE bits */ #define BITMASK 0xFF -#define BITHIGH 0x80 extern Datum bit_in(PG_FUNCTION_ARGS); diff --git a/src/port/pgstrcasecmp.c b/src/port/pgstrcasecmp.c index 8eb3857d4c..2be4cf6be8 100644 --- a/src/port/pgstrcasecmp.c +++ b/src/port/pgstrcasecmp.c @@ -40,12 +40,12 @@ pg_strcasecmp(const char *s1, const char *s2) { if (ch1 >= 'A' && ch1 <= 'Z') ch1 += 'a' - 'A'; - else if (ch1 >= 0x80 && isupper(ch1)) + else if (IS_HIGHBIT_SET(ch1) && isupper(ch1)) ch1 = tolower(ch1); if (ch2 >= 'A' && ch2 <= 'Z') ch2 += 'a' - 'A'; - else if (ch2 >= 0x80 && isupper(ch2)) + else if (IS_HIGHBIT_SET(ch2) && isupper(ch2)) ch2 = tolower(ch2); if (ch1 != ch2) @@ -73,12 +73,12 @@ pg_strncasecmp(const char *s1, const char *s2, size_t n) { if (ch1 >= 'A' && ch1 <= 'Z') ch1 += 'a' - 'A'; - else if (ch1 >= 0x80 && isupper(ch1)) + else if (IS_HIGHBIT_SET(ch1) && isupper(ch1)) ch1 = tolower(ch1); if (ch2 >= 'A' && ch2 <= 'Z') ch2 += 'a' - 'A'; - else if (ch2 >= 0x80 && isupper(ch2)) + else if (IS_HIGHBIT_SET(ch2) && isupper(ch2)) ch2 = tolower(ch2); if (ch1 != ch2) @@ -102,7 +102,7 @@ pg_toupper(unsigned char ch) { if (ch >= 'a' && ch <= 'z') ch += 'A' - 'a'; - else if (ch >= 0x80 && islower(ch)) + else if (IS_HIGHBIT_SET(ch) && islower(ch)) ch = toupper(ch); return ch; } @@ -119,7 +119,7 @@ pg_tolower(unsigned char ch) { if (ch >= 'A' && ch <= 'Z') ch += 'a' - 'A'; - else if (ch >= 0x80 && isupper(ch)) + else if (IS_HIGHBIT_SET(ch) && isupper(ch)) ch = tolower(ch); return ch; } |