Add CString utilities to kstd

This commit is contained in:
Eryn Wells 2016-03-13 13:51:13 -04:00
parent 0027a8adb7
commit af8a3c379e
2 changed files with 56 additions and 0 deletions

35
src/kstd/CString.cc Normal file
View file

@ -0,0 +1,35 @@
/* CString.cc
* vim: set tw=80:
* Eryn Wells <eryn@erynwells.me>
*/
/**
* 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 */

21
src/kstd/CString.hh Normal file
View file

@ -0,0 +1,21 @@
/* CString.hh
* vim: set tw=80:
* Eryn Wells <eryn@erynwells.me>
*/
/**
* Utilities for dealing with C strings.
*/
#include <stddef.h>
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 */