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 kstd {
|
||||||
namespace CString {
|
namespace CString {
|
||||||
|
|
||||||
size_t
|
usize
|
||||||
length(char* str)
|
length(char* str)
|
||||||
{
|
{
|
||||||
size_t i;
|
usize i;
|
||||||
for (i = 0; str[i] != '\0'; i++) { }
|
for (i = 0; str[i] != '\0'; i++);
|
||||||
return 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
|
void
|
||||||
uppercase(char *str)
|
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 CString */
|
||||||
} /* namespace kernel */
|
} /* namespace kernel */
|
||||||
|
|
|
@ -6,16 +6,31 @@
|
||||||
* Utilities for dealing with C strings.
|
* Utilities for dealing with C strings.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stddef.h>
|
#include "Types.hh"
|
||||||
|
|
||||||
namespace kstd {
|
namespace kstd {
|
||||||
namespace CString {
|
namespace CString {
|
||||||
|
|
||||||
/** Find the length of a C string. */
|
/** 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. */
|
/** Destructively convert an ASCII C String to uppercase. */
|
||||||
void uppercase(char *str);
|
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 CString */
|
||||||
} /* namespace kstd */
|
} /* namespace kstd */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue