summaryrefslogtreecommitdiff
path: root/gnulib/lib/unistr/u-strcoll.h
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2012-01-17 14:43:55 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2012-01-17 14:43:55 +0000
commit2de9abc5c9d40b3c716307d67d16146f823fd554 (patch)
tree6979db67934ddc8b564150b465846a383b428ff8 /gnulib/lib/unistr/u-strcoll.h
parent33cc1c6fda6e72a7bae1401e9b2cec495a4d3ff1 (diff)
downloadpatch-baserock/bootstrap-pass2.tar.gz
Diffstat (limited to 'gnulib/lib/unistr/u-strcoll.h')
m---------gnulib0
-rw-r--r--gnulib/lib/unistr/u-strcoll.h92
2 files changed, 92 insertions, 0 deletions
diff --git a/gnulib b/gnulib
deleted file mode 160000
-Subproject 443bc5ffcf7429e557f4a371b0661abe98ddbc1
diff --git a/gnulib/lib/unistr/u-strcoll.h b/gnulib/lib/unistr/u-strcoll.h
new file mode 100644
index 0000000..2a1b553
--- /dev/null
+++ b/gnulib/lib/unistr/u-strcoll.h
@@ -0,0 +1,92 @@
+/* Compare UTF-8/UTF-16/UTF-32 strings using the collation rules of the current
+ locale.
+ Copyright (C) 2009-2011 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2009.
+
+ This program is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+int
+FUNC (const UNIT *s1, const UNIT *s2)
+{
+ /* When this function succeeds, it sets errno back to its original value.
+ When it fails, it sets errno, but also returns a meaningful return value,
+ for the sake of callers which ignore errno. */
+ int final_errno = errno;
+ const char *encoding = locale_charset ();
+ char *sl1;
+ char *sl2;
+ int result;
+
+ /* Pass iconveh_error here, not iconveh_question_mark. Otherwise the
+ conversion to locale encoding can do transliteration or map some
+ characters to question marks, leading to results that depend on the
+ iconv() implementation and are not obvious. */
+ sl1 = U_STRCONV_TO_ENCODING (s1, encoding, iconveh_error);
+ if (sl1 != NULL)
+ {
+ sl2 = U_STRCONV_TO_ENCODING (s2, encoding, iconveh_error);
+ if (sl2 != NULL)
+ {
+ /* Compare sl1 and sl2. */
+ errno = 0;
+ result = strcoll (sl1, sl2);
+ if (errno == 0)
+ {
+ /* strcoll succeeded. */
+ free (sl1);
+ free (sl2);
+ /* The conversion to locale encoding can drop Unicode TAG
+ characters. Therefore sl1 and sl2 may be equal when s1
+ and s2 were in fact different. Return a nonzero result
+ in this case. */
+ if (result == 0)
+ result = U_STRCMP (s1, s2);
+ }
+ else
+ {
+ /* strcoll failed. */
+ final_errno = errno;
+ free (sl1);
+ free (sl2);
+ result = U_STRCMP (s1, s2);
+ }
+ }
+ else
+ {
+ /* s1 could be converted to locale encoding, s2 not. */
+ final_errno = errno;
+ free (sl1);
+ result = -1;
+ }
+ }
+ else
+ {
+ final_errno = errno;
+ sl2 = U_STRCONV_TO_ENCODING (s2, encoding, iconveh_error);
+ if (sl2 != NULL)
+ {
+ /* s2 could be converted to locale encoding, s1 not. */
+ free (sl2);
+ result = 1;
+ }
+ else
+ {
+ /* Neither s1 nor s2 could be converted to locale encoding. */
+ result = U_STRCMP (s1, s2);
+ }
+ }
+
+ errno = final_errno;
+ return result;
+}