Skip to content

Commit

Permalink
fix unpackaging
Browse files Browse the repository at this point in the history
  • Loading branch information
okbob committed Apr 29, 2012
1 parent 6a473d8 commit 7e679d1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ url_encode, url_decode functions for PostgreSQL
Ahoj Světe │ Hello World
(1 row)

postgres=# with x as (select url_encode(unnest(string_to_array('http://hu.wikipedia.org/wiki/São_Paulo','/'))))
select string_agg(url_encode, '/') from x;
string_agg
───────────────────────────────────────────────
http%3A//hu.wikipedia.org/wiki/S%C3%A3o_Paulo

postgres=# select url_encode('http://hu.wikipedia.org/wiki/São_Paulo');
url_encode
───────────────────────────────────────────────────────
http%3A%2F%2Fhu.wikipedia.org%2Fwiki%2FS%C3%A3o_Paulo
22 changes: 19 additions & 3 deletions src/url_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ PG_MODULE_MAGIC;

PG_FUNCTION_INFO_V1(url_encode);
PG_FUNCTION_INFO_V1(url_decode);
PG_FUNCTION_INFO_V1(uri_encode);
PG_FUNCTION_INFO_V1(uri_decode);

Datum url_encode(PG_FUNCTION_ARGS);
Datum url_decode(PG_FUNCTION_ARGS);
Datum uri_encode(PG_FUNCTION_ARGS);
Datum uri_decode(PG_FUNCTION_ARGS);


static const char *hex_chars = "0123456789ABCDEF";

Expand Down Expand Up @@ -63,7 +68,7 @@ get_hex(char c)
Datum
url_encode(PG_FUNCTION_ARGS)
{
text *text_data = PG_GETARG_TEXT_PP(0);
text *text_data = PG_GETARG_TEXT_P(0);
char *read_ptr = VARDATA(text_data);
int len = VARSIZE(text_data) - VARHDRSZ;
text *result;
Expand All @@ -75,7 +80,6 @@ url_encode(PG_FUNCTION_ARGS)
/* preallocation max 3 times of size */
result = (text *) palloc(sizeof(3 * len) + VARHDRSZ);
write_ptr = VARDATA(result);

processed = 0;
real_len = 0;
while (processed < len)
Expand Down Expand Up @@ -125,7 +129,7 @@ url_encode(PG_FUNCTION_ARGS)
Datum
url_decode(PG_FUNCTION_ARGS)
{
text *text_data = PG_GETARG_TEXT_PP(0);
text *text_data = PG_GETARG_TEXT_P(0);
text *result;
char *read_ptr = VARDATA(text_data);
char *write_ptr;
Expand Down Expand Up @@ -174,3 +178,15 @@ url_decode(PG_FUNCTION_ARGS)

PG_RETURN_TEXT_P(result);
}

Datum
uri_encode(PG_FUNCTION_ARGS)
{
PG_RETURN_NULL();
}

Datum
uri_decode(PG_FUNCTION_ARGS)
{
PG_RETURN_NULL();
}

0 comments on commit 7e679d1

Please sign in to comment.