FROM_CHAR_DATE_ISOWEEK /* ISO 8601 week date */
} FromCharDateMode;
-typedef struct FormatNode FormatNode;
-
typedef struct
{
const char *name;
FromCharDateMode date_mode;
} KeyWord;
-struct FormatNode
+typedef struct
{
- int type; /* node type */
- const KeyWord *key; /* if node type is KEYWORD */
- char character; /* if node type is CHAR */
- int suffix; /* keyword suffix */
-};
+ int type; /* NODE_TYPE_XXX, see below */
+ const KeyWord *key; /* if type is ACTION */
+ char character[MAX_MULTIBYTE_CHAR_LEN + 1]; /* if type is CHAR */
+ int suffix; /* keyword prefix/suffix code, if any */
+} FormatNode;
#define NODE_TYPE_END 1
#define NODE_TYPE_ACTION 2
}
else if (*str)
{
+ int chlen;
+
/*
* Process double-quoted literal string, if any
*/
if (*str == '"')
{
- while (*(++str))
+ str++;
+ while (*str)
{
if (*str == '"')
{
/* backslash quotes the next character, if any */
if (*str == '\\' && *(str + 1))
str++;
+ chlen = pg_mblen(str);
n->type = NODE_TYPE_CHAR;
- n->character = *str;
+ memcpy(n->character, str, chlen);
+ n->character[chlen] = '\0';
n->key = NULL;
n->suffix = 0;
n++;
+ str += chlen;
}
}
else
*/
if (*str == '\\' && *(str + 1) == '"')
str++;
+ chlen = pg_mblen(str);
n->type = NODE_TYPE_CHAR;
- n->character = *str;
+ memcpy(n->character, str, chlen);
+ n->character[chlen] = '\0';
n->key = NULL;
n->suffix = 0;
n++;
- str++;
+ str += chlen;
}
}
}
elog(DEBUG_elog_output, "%d:\t NODE_TYPE_ACTION '%s'\t(%s,%s)",
a, n->key->name, DUMP_THth(n->suffix), DUMP_FM(n->suffix));
else if (n->type == NODE_TYPE_CHAR)
- elog(DEBUG_elog_output, "%d:\t NODE_TYPE_CHAR '%c'", a, n->character);
+ elog(DEBUG_elog_output, "%d:\t NODE_TYPE_CHAR '%s'",
+ a, n->character);
else if (n->type == NODE_TYPE_END)
{
elog(DEBUG_elog_output, "%d:\t NODE_TYPE_END", a);
do { \
if (S_THth(_suf)) \
{ \
- if (*(ptr)) (ptr)++; \
- if (*(ptr)) (ptr)++; \
+ if (*(ptr)) (ptr) += pg_mblen(ptr); \
+ if (*(ptr)) (ptr) += pg_mblen(ptr); \
} \
} while (0)
return true;
}
- else if (isdigit((unsigned char) n->character))
+ else if (n->character[1] == '\0' &&
+ isdigit((unsigned char) n->character[0]))
return false;
return true; /* some non-digit input (separator) */
{
if (n->type != NODE_TYPE_ACTION)
{
- *s = n->character;
- s++;
+ strcpy(s, n->character);
+ s += strlen(s);
continue;
}
* we don't insist that the consumed character match the format's
* character.
*/
- s++;
+ s += pg_mblen(s);
continue;
}
/*
* These macros are used in NUM_processor() and its subsidiary routines.
* OVERLOAD_TEST: true if we've reached end of input string
- * AMOUNT_TEST(s): true if at least s characters remain in string
+ * AMOUNT_TEST(s): true if at least s bytes remain in string
*/
#define OVERLOAD_TEST (Np->inout_p >= Np->inout + input_len)
#define AMOUNT_TEST(s) (Np->inout_p <= Np->inout + (input_len - (s)))
if (!Np->is_to_char)
{
/*
- * Check at least one character remains to be scanned. (In
- * actions below, must use AMOUNT_TEST if we want to read more
- * characters than that.)
+ * Check at least one byte remains to be scanned. (In actions
+ * below, must use AMOUNT_TEST if we want to read more bytes than
+ * that.)
*/
if (OVERLOAD_TEST)
break;
* In TO_CHAR, non-pattern characters in the format are copied to
* the output. In TO_NUMBER, we skip one input character for each
* non-pattern format character, whether or not it matches the
- * format character. (Currently, that's actually implemented as
- * skipping one input byte per non-pattern format byte, which is
- * wrong...)
+ * format character.
*/
if (Np->is_to_char)
- *Np->inout_p = n->character;
+ {
+ strcpy(Np->inout_p, n->character);
+ Np->inout_p += strlen(Np->inout_p);
+ }
+ else
+ {
+ Np->inout_p += pg_mblen(Np->inout_p);
+ }
+ continue;
}
Np->inout_p++;
}