std::islower(3)
πΈ std::islower(3) πΈ
okay bestie, welcome to std::islower β that's the C++ Standard Library version, page 3 of the manual, and she is literally the lowercase detector of your dreams π
β¨ NAME β¨
std::islower β std::islower (yes she's named after herself, main character energy π)
β¨ Synopsis β¨
so first thing, she lives here:
Defined in header <cctype>
and her whole signature is just:
int islower( int ch );
what she does: she checks if the character you hand her is classified as a lowercase character according to the current C locale. π
in the default "C" locale, std::islower returns a nonzero value only for the lowercase letters β and those are, exactly:
abcdefghijklmnopqrstuvwxyz
and here's a slay little guarantee for you: if islower returns a nonzero value, then std::iscntrl, std::isdigit, std::ispunct, and std::isspace are all guaranteed to return zero for that same character in that same C locale. no cap. π«Ά
β οΈ and now the scary part, bestie: the behavior is undefined if the value ofchis not representable asunsigned charand is not equal toEOF. like, undefined-undefined. don't do it. π
β¨ Parameters β¨
chβ the character to classify π¦
β¨ Return value β¨
Non-zero value if the character is a lowercase letter, zero otherwise. that's it, that's the whole vibe check β
β¨ Notes β¨
like all the other functions from <cctype>, the behavior of std::islower is undefined if the argument's value is neither representable as unsigned char nor equal to EOF. π
so to use these functions safely with plain chars (or signed chars), convert the argument to unsigned char first, like this:
bool my_islower(char ch)
{
return std::islower(static_cast<unsigned char>(ch));
}
same energy with standard algorithms β do not use them directly when the iterator's value type is char or signed char. convert the value to unsigned char first instead:
int count_lowers(const std::string& s)
{
return std::count_if(s.begin(), s.end(),
// static_cast<int(*)(int)>(std::islower) // wrong
// [](int c){ return std::islower(c); } // wrong
// [](char c){ return std::islower(c); } // wrong
[](unsigned char c){ return std::islower(c); } // correct
);
}
see how she left receipts? the wrong ones are commented out and labeled // wrong and the correct one is labeled // correct. iconic. π₯
β¨ Example β¨
// Run this code
#include <cctype>
#include <clocale>
#include <iostream>
int main()
{
unsigned char c = '\xe5'; // letter Γ₯ in ISO-8859-1
std::cout << "islower(\'\\xe5\', default C locale) returned "
<< std::boolalpha << (bool)std::islower(c) << '\n';
std::setlocale(LC_ALL, "en_GB.iso88591");
std::cout << "islower(\'\\xe5\', ISO-8859-1 locale) returned "
<< std::boolalpha << (bool)std::islower(c) << '\n';
}
π Possible output π
islower('\xe5', default C locale) returned false
islower('\xe5', ISO-8859-1 locale) returned true
see, locale changes everything. she contains multitudes. β¨
β¨ See also β¨
islower(std::locale)β checks if a character is classified as lowercase by a locale (function template) πiswlowerβ checks if a wide character is lowercase (function) π§- C documentation for
islowerπ
π the ASCII values chart (she's long but she's thorough)
ASCII values characters iscntrl isprint isspace isblank isgraph ispunct isalnum isalpha isupper islower isdigit isxdigit iswcntrl iswprint iswspace iswblank iswgraph iswpunct iswalnum iswalpha iswupper iswlower iswdigit iswxdigit
0β8 \x0β\x8 \0β\10 control codes (NUL, etc.) β 0 0 0 0 0 0 0 0 0 0 0
9 \x9 \11 tab (\t) β 0 0 β 0 β 0 0 0 0 0 0 0 0
10β13 \xAβ\xD \12β\15 whitespaces (\n, \v, \f, \r) β 0 0 β 0 0 0 0 0 0 0 0 0
14β31 \xEβ\x1F \16β\37 control codes β 0 0 0 0 0 0 0 0 0 0 0
32 \x20 \40 space 0 β 0 β 0 β 0 0 0 0 0 0 0 0
33β47 \x21β\x2F \41β\57 !"#$%&'()*+,-./ 0 β 0 0 0 β 0 β 0 0 0 0 0 0
48β57 \x30β\x39 \60β\71 0123456789 0 β 0 0 0 β 0 0 β 0 0 0 0 β 0 β 0
58β64 \x3Aβ\x40 \72β\100 :;<=>?@ 0 β 0 0 0 β 0 β 0 0 0 0 0 0
65β70 \x41β\x46 \101β\106 ABCDEF 0 β 0 0 0 β 0 0 β 0 β 0 β 0 0 0 β 0
71β90 \x47β\x5A \107β\132 GHIJKLMNOPQRSTUVWXYZ 0 β 0 0 0 β 0 0 β 0 β 0 β 0 0 0 0
91β96 \x5Bβ\x60 \133β\140 [\]^_` 0 β 0 0 0 β 0 β 0 0 0 0 0 0
97β102 \x61β\x66 \141β\146 abcdef 0 β 0 0 0 β 0 0 β 0 β 0 0 β 0 0 β 0
103β122 \x67β\x7A \147β\172 ghijklmnopqrstuvwxyz 0 β 0 0 0 β 0 0 β 0 β 0 0 β 0 0 0
123β126 \x7Bβ\x7E \172β\176 {|}~ 0 β 0 0 0 β 0 β 0 0 0 0 0 0
127 \x7F \177 backspace character (DEL) β 0 0 0 0 0 0 0 0 0 0 0
and that's the whole page, bestie π«Ά this adorable little reference came from http://cppreference.com, dated 2024.06.10, and it's page std::islower(3). go forth and classify your lowercase letters correctly, and please cast to unsigned char. for me. πππ¦
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms