Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2011-03-20 16:43:39 +0000
committerTom Lane2011-03-20 16:44:13 +0000
commit176d5bae1d636fc1e91840b12cbd04c96d638b7e (patch)
treef861d3f9d9eb2bead0cd932e7825271fb1fbc1e1 /src/port/pgstrcasecmp.c
parentc2f4ea469b52e6f7fedff651a4aa0acced873a5f (diff)
Fix up handling of C/POSIX collations.
Install just one instance of the "C" and "POSIX" collations into pg_collation, rather than one per encoding. Make these instances exist and do something useful even in machines without locale_t support: to wit, it's now possible to force comparisons and case-folding functions to use C locale in an otherwise non-C database, whether or not the platform has support for using any additional collations. Fix up severely broken upper/lower/initcap functions, too: the C/POSIX fastpath now does what it is supposed to, and non-default collations are handled correctly in single-byte database encodings. Merge the two separate collation hashtables that were being maintained in pg_locale.c, and be more wary of the possibility that we fail partway through filling a cache entry.
Diffstat (limited to 'src/port/pgstrcasecmp.c')
-rw-r--r--src/port/pgstrcasecmp.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/port/pgstrcasecmp.c b/src/port/pgstrcasecmp.c
index 1680124df0d..f6e226f0f2c 100644
--- a/src/port/pgstrcasecmp.c
+++ b/src/port/pgstrcasecmp.c
@@ -13,6 +13,10 @@
*
* NB: this code should match downcase_truncate_identifier() in scansup.c.
*
+ * We also provide strict ASCII-only case conversion functions, which can
+ * be used to implement C/POSIX case folding semantics no matter what the
+ * C library thinks the locale is.
+ *
*
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
*
@@ -123,3 +127,25 @@ pg_tolower(unsigned char ch)
ch = tolower(ch);
return ch;
}
+
+/*
+ * Fold a character to upper case, following C/POSIX locale rules.
+ */
+unsigned char
+pg_ascii_toupper(unsigned char ch)
+{
+ if (ch >= 'a' && ch <= 'z')
+ ch += 'A' - 'a';
+ return ch;
+}
+
+/*
+ * Fold a character to lower case, following C/POSIX locale rules.
+ */
+unsigned char
+pg_ascii_tolower(unsigned char ch)
+{
+ if (ch >= 'A' && ch <= 'Z')
+ ch += 'a' - 'A';
+ return ch;
+}