String buffer

v1
Brett 2023-07-10 18:45:43 -04:00
parent 2ad00c8895
commit d06c7ebeb6
48 changed files with 56 additions and 2 deletions

4
CMakeLists.txt Normal file → Executable file
View File

@ -9,6 +9,8 @@ option(BUILD_NBT "Build the BLT NBT + eNBT extension" ON)
option(BUILD_TESTS "Build the BLT test set" OFF)
option(BLT_ENABLE_LOGGING "Enable blt::logging" ON)
configure_file(include/blt/config.h.in config/blt/config.h @ONLY)
if(${BUILD_STD} OR ${BUILD_PROFILING})
file(GLOB_RECURSE STD_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/blt/std/*.cpp")
else()
@ -44,8 +46,6 @@ message("Profiler Files ${PROFILING_FILES}")
message("Source: ${CMAKE_SOURCE_DIR}")
message("Current Source: ${CMAKE_CURRENT_SOURCE_DIR}")
configure_file(include/blt/config.h.in config/blt/config.h @ONLY)
add_library(BLT ${STD_FILES} ${PROFILING_FILES} ${NBT_FILES})
target_include_directories(BLT PUBLIC include/)

0
CMakeSettings.json Normal file → Executable file
View File

0
LICENSE Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

0
design.txt Normal file → Executable file
View File

0
icon.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 39 KiB

0
icon_large.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 118 KiB

After

Width:  |  Height:  |  Size: 118 KiB

0
icon_small.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

0
include/blt/config.h.in Normal file → Executable file
View File

0
include/blt/math/averages.h Normal file → Executable file
View File

0
include/blt/math/log_util.h Normal file → Executable file
View File

0
include/blt/math/math.h Normal file → Executable file
View File

0
include/blt/math/matrix.h Normal file → Executable file
View File

0
include/blt/math/vectors.h Normal file → Executable file
View File

0
include/blt/nbt/nbt.h Normal file → Executable file
View File

0
include/blt/nbt/nbt_block.h Normal file → Executable file
View File

0
include/blt/profiling/profiler.h Normal file → Executable file
View File

0
include/blt/std/binary_tree.h Normal file → Executable file
View File

0
include/blt/std/filesystem.h Normal file → Executable file
View File

0
include/blt/std/format.h Normal file → Executable file
View File

0
include/blt/std/hash_map.h Normal file → Executable file
View File

0
include/blt/std/loader.h Normal file → Executable file
View File

0
include/blt/std/logging.h Normal file → Executable file
View File

0
include/blt/std/map.h Normal file → Executable file
View File

0
include/blt/std/memory.h Normal file → Executable file
View File

0
include/blt/std/queue.h Normal file → Executable file
View File

0
include/blt/std/random.h Normal file → Executable file
View File

25
include/blt/std/string.h Normal file → Executable file
View File

@ -16,6 +16,30 @@
namespace blt::string {
class StringBuffer {
private:
const size_t BLOCK_SIZE = 4096;
size_t front = 0;
size_t size = 0;
char* characterBuffer = nullptr;
void expand();
public:
void trim();
std::string toString();
StringBuffer(){
characterBuffer = static_cast<char*>(malloc(BLOCK_SIZE));
size = BLOCK_SIZE;
}
StringBuffer& operator<<(char c);
~StringBuffer() {
free(characterBuffer);
}
};
static inline bool starts_with(const std::string& string, const std::string& search){
if (search.length() > string.length())
return false;
@ -153,6 +177,7 @@ namespace blt::string {
trim(s);
return s;
}
}
#endif //BLT_STRING_H

0
include/blt/std/system.h Normal file → Executable file
View File

0
include/blt/std/time.h Normal file → Executable file
View File

0
include/blt/window/window.h Normal file → Executable file
View File

0
src/blt/nbt/nbt.cpp Normal file → Executable file
View File

0
src/blt/nbt/nbt_block.cpp Normal file → Executable file
View File

0
src/blt/profiling/profiler.cpp Normal file → Executable file
View File

0
src/blt/std/filesystem.cpp Normal file → Executable file
View File

0
src/blt/std/format.cpp Normal file → Executable file
View File

0
src/blt/std/loader.cpp Normal file → Executable file
View File

0
src/blt/std/logging.cpp Normal file → Executable file
View File

29
src/blt/std/string.cpp Executable file
View File

@ -0,0 +1,29 @@
//
// Created by brett on 7/9/23.
//
#include <blt/std/string.h>
void blt::string::StringBuffer::expand() {
size_t multiplier = size / BLOCK_SIZE;
auto newSize = BLOCK_SIZE * (multiplier * 2);
characterBuffer = static_cast<char*>(realloc(characterBuffer, newSize));
size = newSize;
}
void blt::string::StringBuffer::trim() {
characterBuffer = static_cast<char*>(realloc(characterBuffer, front+1));
size = front+1;
characterBuffer[front] = '\0';
}
blt::string::StringBuffer& blt::string::StringBuffer::operator<<(char c) {
characterBuffer[front++] = c;
if (front > size)
expand();
return *this;
}
std::string blt::string::StringBuffer::toString() {
trim();
return std::string{characterBuffer};
}

0
src/blt/std/system.cpp Normal file → Executable file
View File

0
src/blt/window/window.cpp Normal file → Executable file
View File

0
src/tests/binary_trees.h Normal file → Executable file
View File

0
src/tests/hashmap_tests.h Normal file → Executable file
View File

0
src/tests/logging.h Normal file → Executable file
View File

0
src/tests/main.cpp Normal file → Executable file
View File

0
src/tests/nbt_tests.h Normal file → Executable file
View File

0
src/tests/profiling_tests.h Normal file → Executable file
View File

0
src/tests/queue_tests.h Normal file → Executable file
View File