]> granicus.if.org Git - postgresql/blobdiff - src/backend/utils/adt/varlena.c
Message style improvements
[postgresql] / src / backend / utils / adt / varlena.c
index c2119edcecc4504501389b7616dfa70ef47d8d7e..33f40b685c76bbaa87e05476229e47793b01e227 100644 (file)
@@ -3,12 +3,12 @@
  * varlena.c
  *       Functions for the variable-length built-in types.
  *
- * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.143 2006/02/26 02:23:41 neilc Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.151 2006/10/04 00:30:00 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
 
 #include <ctype.h>
 
+#include "access/tupmacs.h"
 #include "access/tuptoaster.h"
 #include "catalog/pg_type.h"
-#include "lib/stringinfo.h"
-#include "libpq/crypt.h"
+#include "libpq/md5.h"
 #include "libpq/pqformat.h"
-#include "mb/pg_wchar.h"
-#include "miscadmin.h"
 #include "parser/scansup.h"
 #include "regex/regex.h"
-#include "utils/array.h"
 #include "utils/builtins.h"
 #include "utils/lsyscache.h"
 #include "utils/pg_locale.h"
@@ -256,10 +253,7 @@ textin(PG_FUNCTION_ARGS)
        text       *result;
        int                     len;
 
-       /* verify encoding */
        len = strlen(inputText);
-       pg_verifymbstr(inputText, len, false);
-
        result = (text *) palloc(len + VARHDRSZ);
        VARATT_SIZEP(result) = len + VARHDRSZ;
 
@@ -299,9 +293,6 @@ textrecv(PG_FUNCTION_ARGS)
 
        str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
 
-       /* verify encoding */
-       pg_verifymbstr(str, nbytes, false);
-
        result = (text *) palloc(nbytes + VARHDRSZ);
        VARATT_SIZEP(result) = nbytes + VARHDRSZ;
        memcpy(VARDATA(result), str, nbytes);
@@ -994,8 +985,8 @@ texteq(PG_FUNCTION_ARGS)
        bool            result;
 
        /*
-        * Since we only care about equality or not-equality, we can avoid all
-        * the expense of strcoll() here, and just do bitwise comparison.
+        * Since we only care about equality or not-equality, we can avoid all the
+        * expense of strcoll() here, and just do bitwise comparison.
         */
        if (VARSIZE(arg1) != VARSIZE(arg2))
                result = false;
@@ -1017,8 +1008,8 @@ textne(PG_FUNCTION_ARGS)
        bool            result;
 
        /*
-        * Since we only care about equality or not-equality, we can avoid all
-        * the expense of strcoll() here, and just do bitwise comparison.
+        * Since we only care about equality or not-equality, we can avoid all the
+        * expense of strcoll() here, and just do bitwise comparison.
         */
        if (VARSIZE(arg1) != VARSIZE(arg2))
                result = true;
@@ -2038,7 +2029,7 @@ replace_text(PG_FUNCTION_ARGS)
        text       *buf_text;
        text       *ret_text;
        int                     curr_posn;
-       StringInfo      str;
+       StringInfoData str;
 
        if (src_text_len == 0 || from_sub_text_len == 0)
                PG_RETURN_TEXT_P(src_text);
@@ -2049,7 +2040,7 @@ replace_text(PG_FUNCTION_ARGS)
        if (curr_posn == 0)
                PG_RETURN_TEXT_P(src_text);
 
-       str = makeStringInfo();
+       initStringInfo(&str);
        buf_text = src_text;
 
        while (curr_posn > 0)
@@ -2059,8 +2050,8 @@ replace_text(PG_FUNCTION_ARGS)
                right_text = text_substring(PointerGetDatum(buf_text),
                                                                        curr_posn + from_sub_text_len, -1, true);
 
-               appendStringInfoText(str, left_text);
-               appendStringInfoText(str, to_sub_text);
+               appendStringInfoText(&str, left_text);
+               appendStringInfoText(&str, to_sub_text);
 
                if (buf_text != src_text)
                        pfree(buf_text);
@@ -2069,13 +2060,12 @@ replace_text(PG_FUNCTION_ARGS)
                curr_posn = TEXTPOS(buf_text, from_sub_text);
        }
 
-       appendStringInfoText(str, buf_text);
+       appendStringInfoText(&str, buf_text);
        if (buf_text != src_text)
                pfree(buf_text);
 
-       ret_text = PG_STR_GET_TEXT(str->data);
-       pfree(str->data);
-       pfree(str);
+       ret_text = PG_STR_GET_TEXT(str.data);
+       pfree(str.data);
 
        PG_RETURN_TEXT_P(ret_text);
 }
@@ -2227,8 +2217,7 @@ replace_text_regexp(text *src_text, void *regexp,
        text       *ret_text;
        regex_t    *re = (regex_t *) regexp;
        int                     src_text_len = VARSIZE(src_text) - VARHDRSZ;
-       StringInfo      str = makeStringInfo();
-       int                     regexec_result;
+       StringInfoData buf;
        regmatch_t      pmatch[REGEXP_REPLACE_BACKREF_CNT];
        pg_wchar   *data;
        size_t          data_len;
@@ -2236,6 +2225,8 @@ replace_text_regexp(text *src_text, void *regexp,
        int                     data_pos;
        bool            have_escape;
 
+       initStringInfo(&buf);
+
        /* Convert data string to wide characters. */
        data = (pg_wchar *) palloc((src_text_len + 1) * sizeof(pg_wchar));
        data_len = pg_mb2wchar_with_len(VARDATA(src_text), data, src_text_len);
@@ -2245,6 +2236,8 @@ replace_text_regexp(text *src_text, void *regexp,
 
        for (search_start = data_pos = 0; search_start <= data_len;)
        {
+               int                     regexec_result;
+
                regexec_result = pg_regexec(re,
                                                                        data,
                                                                        data_len,
@@ -2254,20 +2247,19 @@ replace_text_regexp(text *src_text, void *regexp,
                                                                        pmatch,
                                                                        0);
 
-               if (regexec_result != REG_OKAY && regexec_result != REG_NOMATCH)
+               if (regexec_result == REG_NOMATCH)
+                       break;
+
+               if (regexec_result != REG_OKAY)
                {
                        char            errMsg[100];
 
-                       /* re failed??? */
                        pg_regerror(regexec_result, re, errMsg, sizeof(errMsg));
                        ereport(ERROR,
                                        (errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
                                         errmsg("regular expression failed: %s", errMsg)));
                }
 
-               if (regexec_result == REG_NOMATCH)
-                       break;
-
                /*
                 * Copy the text to the left of the match position.  Because we are
                 * working with character not byte indexes, it's easiest to use
@@ -2281,7 +2273,7 @@ replace_text_regexp(text *src_text, void *regexp,
                                                                           data_pos + 1,
                                                                           pmatch[0].rm_so - data_pos,
                                                                           false);
-                       appendStringInfoText(str, left_text);
+                       appendStringInfoText(&buf, left_text);
                        pfree(left_text);
                }
 
@@ -2290,9 +2282,9 @@ replace_text_regexp(text *src_text, void *regexp,
                 * replace_text has escape characters.
                 */
                if (have_escape)
-                       appendStringInfoRegexpSubstr(str, replace_text, pmatch, src_text);
+                       appendStringInfoRegexpSubstr(&buf, replace_text, pmatch, src_text);
                else
-                       appendStringInfoText(str, replace_text);
+                       appendStringInfoText(&buf, replace_text);
 
                search_start = data_pos = pmatch[0].rm_eo;
 
@@ -2318,13 +2310,12 @@ replace_text_regexp(text *src_text, void *regexp,
 
                right_text = text_substring(PointerGetDatum(src_text),
                                                                        data_pos + 1, -1, true);
-               appendStringInfoText(str, right_text);
+               appendStringInfoText(&buf, right_text);
                pfree(right_text);
        }
 
-       ret_text = PG_STR_GET_TEXT(str->data);
-       pfree(str->data);
-       pfree(str);
+       ret_text = PG_STR_GET_TEXT(buf.data);
+       pfree(buf.data);
        pfree(data);
 
        return ret_text;
@@ -2512,7 +2503,7 @@ array_to_text(PG_FUNCTION_ARGS)
        int                     typlen;
        bool            typbyval;
        char            typalign;
-       StringInfo      result_str = makeStringInfo();
+       StringInfoData buf;
        bool            printed = false;
        char       *p;
        bits8      *bitmap;
@@ -2529,6 +2520,7 @@ array_to_text(PG_FUNCTION_ARGS)
                PG_RETURN_TEXT_P(PG_STR_GET_TEXT(""));
 
        element_type = ARR_ELEMTYPE(v);
+       initStringInfo(&buf);
 
        /*
         * We arrange to look up info about element type, including its output
@@ -2579,13 +2571,12 @@ array_to_text(PG_FUNCTION_ARGS)
                {
                        itemvalue = fetch_att(p, typbyval, typlen);
 
-                       value = DatumGetCString(FunctionCall1(&my_extra->proc,
-                                                                                                 itemvalue));
+                       value = OutputFunctionCall(&my_extra->proc, itemvalue);
 
                        if (printed)
-                               appendStringInfo(result_str, "%s%s", fldsep, value);
+                               appendStringInfo(&buf, "%s%s", fldsep, value);
                        else
-                               appendStringInfoString(result_str, value);
+                               appendStringInfoString(&buf, value);
                        printed = true;
 
                        p = att_addlength(p, typlen, PointerGetDatum(p));
@@ -2604,7 +2595,7 @@ array_to_text(PG_FUNCTION_ARGS)
                }
        }
 
-       PG_RETURN_TEXT_P(PG_STR_GET_TEXT(result_str->data));
+       PG_RETURN_TEXT_P(PG_STR_GET_TEXT(buf.data));
 }
 
 #define HEXBASE 16