77 * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
88 * Portions Copyright (c) 1994, Regents of the University of California
99 *
10- * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.8 2006/12/2910:50:22 petere Exp $
10+ * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.9 2006/12/2916:44:28 tgl Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -862,8 +862,7 @@ xml_ereport_by_code(int level, int sqlcode,
862862
863863
864864/*
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.
867866 */
868867static pg_wchar
869868sqlchar_to_unicode (char * s )
@@ -882,42 +881,6 @@ sqlchar_to_unicode(char *s)
882881}
883882
884883
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 ((unsignedchar * )utf8string ,
915- pg_mblen (utf8string ),
916- PG_UTF8 ,
917- GetDatabaseEncoding ());
918- }
919-
920-
921884static bool
922885is_valid_xml_namefirst (pg_wchar c )
923886{
@@ -988,7 +951,45 @@ map_sql_identifier_to_xml_name(char *ident, bool fully_escaped)
988951
989952
990953/*
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 unsignedchar 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.
992993 */
993994char *
994995map_xml_name_to_sql_identifier (char * name )