Skip to content

Commit

Permalink
Modulus instead of mask; CMake config changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingcitaldo125 committed Nov 22, 2021
1 parent feded33 commit 081b5eb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
cmake_minimum_required(VERSION 3.16)

project(base64 VERSION 0.0.2 LANGUAGES CXX)
project(base64 VERSION 0.2.0 LANGUAGES CXX)

option(BUILD_STATIC "" ON)
option(BUILD_STATIC "Build a static library" ON)

set(LIBRARY_NAME "base64")

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/)

message("CMAKE_SOURCE_DIR = ${CMAKE_SOURCE_DIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/)

add_executable(app ${CMAKE_SOURCE_DIR}/src/main.cpp)
target_compile_options(app PRIVATE "-Wall")

if(BUILD_STATIC)
add_library(${LIBRARY_NAME} STATIC ${CMAKE_SOURCE_DIR}/src/base64.cpp)
elseif(BUILD_SHARED)
else()
set(LIBRARY_NAME "${LIBRARY_NAME}_shared")
add_library(${LIBRARY_NAME} SHARED ${CMAKE_SOURCE_DIR}/src/base64.cpp)
endif()
Expand Down Expand Up @@ -85,3 +84,4 @@ install(FILES
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}-${PROJECT_VERSION}
)

4 changes: 2 additions & 2 deletions src/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ std::string base64decode(const std::string& conv)
std::string holdr(1, conv.at(encoded_idx));
std::string encoded_bytes = holdr == "=" ? "000000" : mmap_decode[holdr];

// Take the chunk string and trnasfer the bits into the chunk bitset
// Take the chunk string and transfer the bits into the chunk bitset
std::bitset<6> chunk;
for(short i = 0; i < 6; ++i)
{
Expand Down Expand Up @@ -191,7 +191,7 @@ std::string base64decode(const std::string& conv)
// Actually write out the bytes to the stream
for(auto& byte : bytes)
{
ss << static_cast<char>(byte.to_ulong() & 0x100);
ss << static_cast<char>(byte.to_ulong() % 0x100);
}

return ss.str();
Expand Down
8 changes: 5 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10)

project(CppEarleyTest VERSION 1.0)
project(CppEarleyTest VERSION 1.1)

set(CMAKE_CXX_STANDARD 11)

Expand All @@ -24,9 +24,10 @@ if(${debug})
message("TEST_GRAMMAR_DIRECTORY: ${TEST_GRAMMAR_DIRECTORY}")
endif()

find_library(BASE_LIB base_six_four
find_library(BASE_LIB base64 base64_shared
HINTS ${PROJECT_ROOT_DIRECTORY}
PATH_SUFFIXES /bin /bin/lib /build /build/lib)
PATH_SUFFIXES /bin /bin/lib /build /build/lib
REQUIRED)

add_executable(app-test test.cpp)

Expand All @@ -35,3 +36,4 @@ target_link_libraries(app-test ${CPP_EARLEY} ${GTEST_LIBRARIES} ${GTEST_MAIN_LIB
target_include_directories(app-test PUBLIC ${PROJECT_ROOT_DIRECTORY}/include ${PROJECT_ROOT_DIRECTORY}/src)

add_test(NAME app-test-test COMMAND app-test ${TEST_GRAMMAR_DIRECTORY})

0 comments on commit 081b5eb

Please sign in to comment.