diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 5164019..9b9c7ed 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,3 +1,4 @@ +add_subdirectory(glacier) add_subdirectory(libc) add_subdirectory(libcxx) add_subdirectory(mammoth) diff --git a/lib/glacier/CMakeLists.txt b/lib/glacier/CMakeLists.txt new file mode 100644 index 0000000..9b96973 --- /dev/null +++ b/lib/glacier/CMakeLists.txt @@ -0,0 +1,6 @@ +add_library(glacier STATIC + string/string.cpp) + +target_include_directories(glacier + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..") diff --git a/lib/glacier/string/string.cpp b/lib/glacier/string/string.cpp new file mode 100644 index 0000000..c7d3a35 --- /dev/null +++ b/lib/glacier/string/string.cpp @@ -0,0 +1,37 @@ +#include "string/string.h" + +namespace glcr { +namespace { + +uint64_t cstrlen(const char* cstr) { + uint64_t len = 0; + while (*cstr != '\0') { + cstr++; + len++; + } + return len; +} + +} // namespace + +String::String(const char* str) { + length_ = cstrlen(str); + cstr_ = new char[length_ + 1]; + for (uint64_t i = 0; i <= length_; i++) { + cstr_[i] = str[i]; + } +} + +bool String::operator==(const String& other) { + if (other.length_ != length_) { + return false; + } + for (uint64_t i = 0; i < length_; i++) { + if (cstr_[i] != other.cstr_[i]) { + return false; + } + } + return true; +} + +} // namespace glcr diff --git a/lib/glacier/string/string.h b/lib/glacier/string/string.h new file mode 100644 index 0000000..839347e --- /dev/null +++ b/lib/glacier/string/string.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +namespace glcr { + +class String { + public: + String(const char* cstr); + + bool operator==(const String& str); + + private: + char* cstr_; + uint64_t length_; +}; + +} // namespace glcr