Nigel
b07b4f0d38
Problem: As our kernel grows we need more complex datastructures and functions these would come from the standard C/C++ library with normal programs. The kernel is a freestanding programme and has no access to standard libraries. Solution: We build a mini version of the standard C/C++ library which will contain the datastructures and functions we want. This library can then be statically linked into our kernel binary. Making it a statically linked library also gives more structure to the project. Keeping these random functions and datastructures in the kernel just clutters the kernel source code with less relevant source code.
40 lines
551 B
C++
40 lines
551 B
C++
#include "String.h"
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
|
|
|
|
String::String(char* characters)
|
|
: chars(characters)
|
|
{
|
|
|
|
}
|
|
|
|
char* String::str(){
|
|
return chars;
|
|
}
|
|
|
|
unsigned int String::length ()
|
|
{
|
|
int i = 0;
|
|
|
|
while ( chars[i] != '\0'){
|
|
i++;
|
|
}
|
|
|
|
return i;
|
|
}
|
|
|
|
// Returns a null character if size exceeds limits
|
|
char String::operator[] (size_t idx)
|
|
{
|
|
if( idx > this->length())
|
|
return '\0';
|
|
|
|
return chars[idx];
|
|
}
|
|
|
|
const char String::operator[](size_t idx) const {
|
|
return (const char) chars[idx];
|
|
}
|
|
|