about summary refs log tree commit homepage
path: root/ext/unicorn_http/c_util.h
diff options
context:
space:
mode:
Diffstat (limited to 'ext/unicorn_http/c_util.h')
-rw-r--r--ext/unicorn_http/c_util.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/ext/unicorn_http/c_util.h b/ext/unicorn_http/c_util.h
new file mode 100644
index 0000000..30e7ae2
--- /dev/null
+++ b/ext/unicorn_http/c_util.h
@@ -0,0 +1,28 @@
+/*
+ * Generic C functions and macros go here, there are no dependencies
+ * on Unicorn internal structures or the Ruby C API in here.
+ */
+
+#ifndef UH_util_h
+#define UH_util_h
+
+/*
+ * capitalizes all lower-case ASCII characters and converts dashes
+ * to underscores for HTTP headers.  Locale-agnostic.
+ */
+static void snake_upcase_char(char *c)
+{
+  if (*c >= 'a' && *c <= 'z')
+    *c &= ~0x20;
+  else if (*c == '-')
+    *c = '_';
+}
+
+/* Downcases a single ASCII character.  Locale-agnostic. */
+static void downcase_char(char *c)
+{
+  if (*c >= 'A' && *c <= 'Z')
+    *c |= 0x20;
+}
+
+#endif /* UH_util_h */