From af8a3c379ec54578d90ec65d9ca49e1afba95104 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 13 Mar 2016 13:51:13 -0400 Subject: [PATCH] Add CString utilities to kstd --- src/kstd/CString.cc | 35 +++++++++++++++++++++++++++++++++++ src/kstd/CString.hh | 21 +++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/kstd/CString.cc create mode 100644 src/kstd/CString.hh diff --git a/src/kstd/CString.cc b/src/kstd/CString.cc new file mode 100644 index 0000000..8732f59 --- /dev/null +++ b/src/kstd/CString.cc @@ -0,0 +1,35 @@ +/* CString.cc + * vim: set tw=80: + * Eryn Wells + */ +/** + * Implementation of some utilities for dealing with C strings. + */ + +#include "CString.hh" +#include "ASCII.hh" + +namespace kstd { +namespace CString { + +size_t +length(char *str) +{ + char *end = str; + while (end++ != '\0') { } + return end - str; +} + + +void +uppercase(char *str) +{ + for (char *p = str; *p != '\0'; p++) { + if (Char::isLower(*p)) { + *p = Char::toUpper(*p); + } + } +} + +} /* namespace CString */ +} /* namespace kernel */ diff --git a/src/kstd/CString.hh b/src/kstd/CString.hh new file mode 100644 index 0000000..79f6660 --- /dev/null +++ b/src/kstd/CString.hh @@ -0,0 +1,21 @@ +/* CString.hh + * vim: set tw=80: + * Eryn Wells + */ +/** + * Utilities for dealing with C strings. + */ + +#include + +namespace kstd { +namespace CString { + +/** Find the length of a C string. */ +size_t length(char *str); + +/** Destructively convert an ASCII C String to uppercase. */ +void uppercase(char *str); + +} /* namespace CString */ +} /* namespace kstd */