Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion homework/insensitive-palindrom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ FetchContent_MakeAvailable(googletest)
project(insensitivePalindrom)
enable_testing()

add_executable(${PROJECT_NAME}-ut test.cpp) # add your cpp file here after test.cpp
add_executable(${PROJECT_NAME}-ut
test.cpp
palindrome.cpp) # add your cpp file here after test.cpp
# if this is problematic take a look into CMakeLists.txt files in other exercises

add_compile_options(${PROJECT_NAME}-ut -Wall -Wextra -Wconversion -pedantic -Werror)
Expand Down
19 changes: 19 additions & 0 deletions homework/insensitive-palindrom/palindrome.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "palindrome.h"

bool isItLetter(char c) {
if (int(c) >= 97 && int(c) <= 122)
return true;

return false;
}

bool is_palindrome(std::string input) {
std::for_each(begin(input), end(input), [](char& c) { c = std::tolower(c); });
input.erase(std::remove_if(begin(input), end(input), [](char c) { return !isItLetter(c); }), input.end());

for (int i = 0, j = input.size() - 1; i++, j--; i < j) {
if (input[i] != input[j])
return false;
}
return true;
}
6 changes: 6 additions & 0 deletions homework/insensitive-palindrom/palindrome.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once
#include <algorithm>
#include <string>

bool isItLetter(char c);
bool is_palindrome(std::string input);
2 changes: 1 addition & 1 deletion homework/insensitive-palindrom/test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "gtest/gtest.h"

#include "palindrome.h"
// TODO: Includes

class InsensitivePalindromFixture : public ::testing::TestWithParam<std::pair<std::string, bool>> {
Expand Down
Loading