7
7
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
8
8
* Portions Copyright (c) 1994, Regents of the University of California
9
9
*
10
- * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.8 2006/12/29 10:50:22 petere Exp $
10
+ * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.9 2006/12/29 16:44:28 tgl Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -862,8 +862,7 @@ xml_ereport_by_code(int level, int sqlcode,
862
862
863
863
864
864
/*
865
- * Convert one char in the current server encoding to a Unicode
866
- * codepoint.
865
+ * Convert one char in the current server encoding to a Unicode codepoint.
867
866
*/
868
867
static pg_wchar
869
868
sqlchar_to_unicode (char * s )
@@ -882,42 +881,6 @@ sqlchar_to_unicode(char *s)
882
881
}
883
882
884
883
885
- static char *
886
- unicode_to_sqlchar (pg_wchar c )
887
- {
888
- char utf8string [4 ] = { '\0' , '\0' , '\0' , '\0' };
889
-
890
- if (c <= 0x7F )
891
- {
892
- utf8string [0 ] = c ;
893
- }
894
- else if (c <= 0x7FF )
895
- {
896
- utf8string [0 ] = 0xC0 | ((c >> 6 ) & 0x1F );
897
- utf8string [1 ] = 0x80 | (c & 0x3F );
898
- }
899
- else if (c <= 0xFFFF )
900
- {
901
- utf8string [0 ] = 0xE0 | ((c >> 12 ) & 0x0F );
902
- utf8string [1 ] = 0x80 | ((c >> 6 ) & 0x3F );
903
- utf8string [2 ] = 0x80 | (c & 0x3F );
904
- }
905
- else
906
- {
907
- utf8string [0 ] = 0xF0 | ((c >> 18 ) & 0x07 );
908
- utf8string [1 ] = 0x80 | ((c >> 12 ) & 0x3F );
909
- utf8string [2 ] = 0x80 | ((c >> 6 ) & 0x3F );
910
- utf8string [3 ] = 0x80 | (c & 0x3F );
911
-
912
- }
913
-
914
- return (char * ) pg_do_encoding_conversion ((unsigned char * ) utf8string ,
915
- pg_mblen (utf8string ),
916
- PG_UTF8 ,
917
- GetDatabaseEncoding ());
918
- }
919
-
920
-
921
884
static bool
922
885
is_valid_xml_namefirst (pg_wchar c )
923
886
{
@@ -988,7 +951,45 @@ map_sql_identifier_to_xml_name(char *ident, bool fully_escaped)
988
951
989
952
990
953
/*
991
- * The inverse; see SQL/XML:2003 section 9.17.
954
+ * Map a Unicode codepoint into the current server encoding.
955
+ */
956
+ static char *
957
+ unicode_to_sqlchar (pg_wchar c )
958
+ {
959
+ static unsigned char utf8string [4 ];
960
+
961
+ if (c <= 0x7F )
962
+ {
963
+ utf8string [0 ] = c ;
964
+ }
965
+ else if (c <= 0x7FF )
966
+ {
967
+ utf8string [0 ] = 0xC0 | ((c >> 6 ) & 0x1F );
968
+ utf8string [1 ] = 0x80 | (c & 0x3F );
969
+ }
970
+ else if (c <= 0xFFFF )
971
+ {
972
+ utf8string [0 ] = 0xE0 | ((c >> 12 ) & 0x0F );
973
+ utf8string [1 ] = 0x80 | ((c >> 6 ) & 0x3F );
974
+ utf8string [2 ] = 0x80 | (c & 0x3F );
975
+ }
976
+ else
977
+ {
978
+ utf8string [0 ] = 0xF0 | ((c >> 18 ) & 0x07 );
979
+ utf8string [1 ] = 0x80 | ((c >> 12 ) & 0x3F );
980
+ utf8string [2 ] = 0x80 | ((c >> 6 ) & 0x3F );
981
+ utf8string [3 ] = 0x80 | (c & 0x3F );
982
+ }
983
+
984
+ return (char * ) pg_do_encoding_conversion (utf8string ,
985
+ pg_mblen ((char * ) utf8string ),
986
+ PG_UTF8 ,
987
+ GetDatabaseEncoding ());
988
+ }
989
+
990
+
991
+ /*
992
+ * Map XML name to SQL identifier; see SQL/XML:2003 section 9.17.
992
993
*/
993
994
char *
994
995
map_xml_name_to_sql_identifier (char * name )
0 commit comments