Implement kstd::CString::copy()
Clean up the rest of the CString stuff
This commit is contained in:
parent
a22cec7930
commit
2b39ac909e
2 changed files with 58 additions and 6 deletions
|
@ -12,15 +12,30 @@
|
|||
namespace kstd {
|
||||
namespace CString {
|
||||
|
||||
size_t
|
||||
length(char *str)
|
||||
usize
|
||||
length(char* str)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; str[i] != '\0'; i++) { }
|
||||
usize i;
|
||||
for (i = 0; str[i] != '\0'; i++);
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
copy(char* dst,
|
||||
const char* src,
|
||||
usize length)
|
||||
{
|
||||
for (usize i = 0; i < length; i++) {
|
||||
dst[i] = src[i];
|
||||
if (src[i] == '\0') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
uppercase(char *str)
|
||||
{
|
||||
|
@ -31,5 +46,27 @@ uppercase(char *str)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Converters
|
||||
*/
|
||||
|
||||
char*
|
||||
fromInteger(int value,
|
||||
char* str,
|
||||
usize length)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
fromBool(bool value,
|
||||
char* str,
|
||||
usize length)
|
||||
{
|
||||
copy(str, value ? "true" : "false", length);
|
||||
return str;
|
||||
}
|
||||
|
||||
} /* namespace CString */
|
||||
} /* namespace kernel */
|
||||
|
|
|
@ -6,16 +6,31 @@
|
|||
* Utilities for dealing with C strings.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include "Types.hh"
|
||||
|
||||
namespace kstd {
|
||||
namespace CString {
|
||||
|
||||
/** Find the length of a C string. */
|
||||
size_t length(char *str);
|
||||
usize length(char *str);
|
||||
|
||||
/** Copy a string. */
|
||||
char* copy(char* dst, const char* src, usize length);
|
||||
|
||||
/** Destructively convert an ASCII C String to uppercase. */
|
||||
void uppercase(char *str);
|
||||
|
||||
/**
|
||||
* @defgroup To-String Converters
|
||||
*/
|
||||
|
||||
/** Convert an integer to a string. */
|
||||
char* fromInteger(int value, char *str, usize length);
|
||||
|
||||
/** Convert a bool to a string. */
|
||||
char* fromBool(bool value, char *str, usize length);
|
||||
|
||||
/** @} */
|
||||
|
||||
} /* namespace CString */
|
||||
} /* namespace kstd */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue