5
5
*
6
6
* Joe Conway <mail@joeconway.com>
7
7
*
8
- * $PostgreSQL: pgsql/contrib/fuzzystrmatch/fuzzystrmatch.c,v 1.32 2010/01/02 16:57:32 momjian Exp $
8
+ * $PostgreSQL: pgsql/contrib/fuzzystrmatch/fuzzystrmatch.c,v 1.33 2010/07/29 20:11:48 rhaas Exp $
9
9
* Copyright (c) 2001-2010, PostgreSQL Global Development Group
10
10
* ALL RIGHTS RESERVED;
11
11
*
@@ -90,7 +90,7 @@ soundex_code(char letter)
90
90
*/
91
91
#define MAX_LEVENSHTEIN_STRLEN 255
92
92
93
- static int levenshtein_internal (const char * s , const char * t ,
93
+ static int levenshtein_internal (text * s , text * t ,
94
94
int ins_c , int del_c , int sub_c );
95
95
96
96
@@ -191,7 +191,7 @@ getcode(char c)
191
191
* cases, but your mileage may vary.
192
192
*/
193
193
static int
194
- levenshtein_internal (const char * s , const char * t ,
194
+ levenshtein_internal (text * s , text * t ,
195
195
int ins_c , int del_c , int sub_c )
196
196
{
197
197
int m ,
@@ -203,8 +203,8 @@ levenshtein_internal(const char *s, const char *t,
203
203
const char * x ;
204
204
const char * y ;
205
205
206
- m = strlen (s );
207
- n = strlen (t );
206
+ m = VARSIZE_ANY_EXHDR (s );
207
+ n = VARSIZE_ANY_EXHDR (t );
208
208
209
209
/*
210
210
* We can transform an empty s into t with n insertions, or a non-empty t
@@ -244,7 +244,7 @@ levenshtein_internal(const char *s, const char *t,
244
244
prev [i ] = i * del_c ;
245
245
246
246
/* Loop through rows of the notional array */
247
- for (y = t , j = 1 ; j < n ; y ++ , j ++ )
247
+ for (y = VARDATA_ANY ( t ) , j = 1 ; j < n ; y ++ , j ++ )
248
248
{
249
249
int * temp ;
250
250
@@ -254,7 +254,7 @@ levenshtein_internal(const char *s, const char *t,
254
254
*/
255
255
curr [0 ] = j * ins_c ;
256
256
257
- for (x = s , i = 1 ; i < m ; x ++ , i ++ )
257
+ for (x = VARDATA_ANY ( s ) , i = 1 ; i < m ; x ++ , i ++ )
258
258
{
259
259
int ins ;
260
260
int del ;
@@ -288,8 +288,8 @@ PG_FUNCTION_INFO_V1(levenshtein_with_costs);
288
288
Datum
289
289
levenshtein_with_costs (PG_FUNCTION_ARGS )
290
290
{
291
- char * src = TextDatumGetCString ( PG_GETARG_DATUM ( 0 ) );
292
- char * dst = TextDatumGetCString ( PG_GETARG_DATUM ( 1 ) );
291
+ text * src = PG_GETARG_TEXT_PP ( 0 );
292
+ text * dst = PG_GETARG_TEXT_PP ( 1 );
293
293
int ins_c = PG_GETARG_INT32 (2 );
294
294
int del_c = PG_GETARG_INT32 (3 );
295
295
int sub_c = PG_GETARG_INT32 (4 );
@@ -302,8 +302,8 @@ PG_FUNCTION_INFO_V1(levenshtein);
302
302
Datum
303
303
levenshtein (PG_FUNCTION_ARGS )
304
304
{
305
- char * src = TextDatumGetCString ( PG_GETARG_DATUM ( 0 ) );
306
- char * dst = TextDatumGetCString ( PG_GETARG_DATUM ( 1 ) );
305
+ text * src = PG_GETARG_TEXT_PP ( 0 );
306
+ text * dst = PG_GETARG_TEXT_PP ( 1 );
307
307
308
308
PG_RETURN_INT32 (levenshtein_internal (src , dst , 1 , 1 , 1 ));
309
309
}
0 commit comments