[glacier] Create lib with scaffolding string class.
This commit is contained in:
parent
172bf51db7
commit
859fbf66da
4 changed files with 62 additions and 0 deletions
37
lib/glacier/string/string.cpp
Normal file
37
lib/glacier/string/string.cpp
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue