Exploring C++ 20
|
Listing 28-1. More...
#include <algorithm>
#include <iostream>
#include <ranges>
#include <locale>
#include <string>
#include <string_view>
Go to the source code of this file.
Functions | |
bool | non_letter (char ch) |
Tests for non-letter. More... | |
char | lowercase (char ch) |
Converts to lowercase. More... | |
bool | is_same_char (char a, char b) |
Compares two characters without regard to case. More... | |
bool | is_palindrome (std::string_view str) |
Determines whether str is a palindrome. More... | |
int | main () |
Main program. More... | |
Listing 28-1.
Documenting Your Code with Doxygen
Tests strings to see whether they are palindromes.
Reads lines from the input, strip non-letters, and checks whether the result is a palindrome. Ignores case differences when checking. Echoes palindromes to the standard output.
Definition in file list2801.cpp.
bool is_palindrome | ( | std::string_view | str | ) |
Determines whether str
is a palindrome.
Only letter characters are tested. Spaces and punctuation don't count. Empty strings are not palindromes because that's just too easy.
str | the string to test |
true
if str
is the same forward and backward and not str.empty()
Definition at line 79 of file list2801.cpp.
bool is_same_char | ( | char | a, |
char | b | ||
) |
Compares two characters without regard to case.
a | one character to compare |
b | the other character to compare |
true
if the characters are the same in lowercase, false
if they are different. Definition at line 66 of file list2801.cpp.
char lowercase | ( | char | ch | ) |
Converts to lowercase.
All conversions use the global locale.
ch | the character to test |
Definition at line 54 of file list2801.cpp.
int main | ( | ) |
Main program.
Sets the global locale to the user's native locale. Then imbues the I/O streams with the native locale.
Definition at line 90 of file list2801.cpp.
bool non_letter | ( | char | ch | ) |
Tests for non-letter.
Tests the character ch
in the global locale.
ch | the character to test |
ch
is not a letter Definition at line 42 of file list2801.cpp.