From 18a80cee75a8bf0dc8fca71238b1e404e6651151 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 4 May 2015 17:25:54 -0400 Subject: rewrite urlencode in C --- urlencode.c | 20 ++++++++++++++++++++ urlencode.php | 6 ------ 2 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 urlencode.c delete mode 100644 urlencode.php diff --git a/urlencode.c b/urlencode.c new file mode 100644 index 0000000..a8c61ad --- /dev/null +++ b/urlencode.c @@ -0,0 +1,20 @@ +/* Copyright (C) 2015 Luke Shumaker */ +#include + +int +main () { + int c; + while ((c = getchar()) != EOF) { + if (('0' <= c && c <= '9') + || ('A' <= c && c <= 'Z') + || ('a' <= c && c <= 'z') + ){ + putchar(c); + } else if (c == ' ') { + putchar('+'); + } else { + printf("%%%02X", c); + } + } + return 0; +} diff --git a/urlencode.php b/urlencode.php deleted file mode 100644 index c40263d..0000000 --- a/urlencode.php +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/php -n - - -$contents = file_get_contents('php://stdin'); -echo urlencode($contents); -- cgit v1.2.3-2-g168b