#include "postgres.h"
#include "utils/builtins.h"
+#include "utils/formatting.h"
/* turn off assertions for embedded function */
#define NDEBUG
#include <ctype.h>
/* prototype for the main function we got from the perl module */
-static void DoubleMetaphone(char *str, char **codes);
+static void DoubleMetaphone(const char *str, Oid collid, char **codes);
#ifndef DMETAPHONE_MAIN
arg = PG_GETARG_TEXT_PP(0);
aptr = text_to_cstring(arg);
- DoubleMetaphone(aptr, codes);
+ DoubleMetaphone(aptr, PG_GET_COLLATION(), codes);
code = codes[0];
if (!code)
code = "";
arg = PG_GETARG_TEXT_PP(0);
aptr = text_to_cstring(arg);
- DoubleMetaphone(aptr, codes);
+ DoubleMetaphone(aptr, PG_GET_COLLATION(), codes);
code = codes[1];
if (!code)
code = "";
}
-static void
-MakeUpper(metastring *s)
+static metastring *
+MakeUpper(metastring *s, Oid collid)
{
- char *i;
+ char *newstr;
+ metastring *newms;
+
+ newstr = str_toupper(s->str, s->length, collid);
+ newms = NewMetaString(newstr);
+ DestroyMetaString(s);
- for (i = s->str; *i; i++)
- *i = toupper((unsigned char) *i);
+ return newms;
}
static void
-DoubleMetaphone(char *str, char **codes)
+DoubleMetaphone(const char *str, Oid collid, char **codes)
{
int length;
metastring *original;
primary->free_string_on_destroy = 0;
secondary->free_string_on_destroy = 0;
- MakeUpper(original);
+ original = MakeUpper(original, collid);
/* skip these when at start of word */
if (StringAt(original, 0, 2, "GN", "KN", "PN", "WR", "PS", ""))
if (argc > 1)
{
- DoubleMetaphone(argv[1], codes);
+ DoubleMetaphone(argv[1], DEFAULT_COLLATION_OID, codes);
printf("%s|%s\n", codes[0], codes[1]);
}
}