summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2015-05-04 17:25:54 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2015-05-04 17:25:54 -0400
commit18a80cee75a8bf0dc8fca71238b1e404e6651151 (patch)
treebba47a53ce302a9da1250bb7abaaa37d3f75fcc3
parent95b4e7db6068ab73600aea44671c412ed496bab9 (diff)
rewrite urlencode in C
-rw-r--r--urlencode.c20
-rw-r--r--urlencode.php6
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);