diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-05-04 17:25:54 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-05-04 17:25:54 -0400 |
commit | 18a80cee75a8bf0dc8fca71238b1e404e6651151 (patch) | |
tree | bba47a53ce302a9da1250bb7abaaa37d3f75fcc3 | |
parent | 95b4e7db6068ab73600aea44671c412ed496bab9 (diff) |
rewrite urlencode in C
-rw-r--r-- | urlencode.c | 20 | ||||
-rw-r--r-- | urlencode.php | 6 |
2 files changed, 20 insertions, 6 deletions
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 <lukeshu@sbcglobal.net> */ +#include <stdio.h> + +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 -<?php -# Copyright (C) 2011, 2014 Luke Shumaker <lukeshu@sbcglobal.net> - -$contents = file_get_contents('php://stdin'); -echo urlencode($contents); |