tlx
to_lower.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/string/to_lower.cpp
3  *
4  * Part of tlx - http://panthema.net/tlx
5  *
6  * Copyright (C) 2007-2017 Timo Bingmann <tb@panthema.net>
7  *
8  * All rights reserved. Published under the Boost Software License, Version 1.0
9  ******************************************************************************/
10 
11 #include <tlx/string/to_lower.hpp>
12 
13 #include <algorithm>
14 
15 namespace tlx {
16 
17 char to_lower(char ch) {
18  if (static_cast<unsigned>(ch - 'A') < 26u)
19  ch = static_cast<char>(ch - 'A' + 'a');
20  return ch;
21 }
22 
23 std::string& to_lower(std::string* str) {
24  std::transform(str->begin(), str->end(), str->begin(),
25  [](char c) { return to_lower(c); });
26  return *str;
27 }
28 
29 std::string to_lower(const std::string& str) {
30  std::string str_copy(str.size(), 0);
31  std::transform(str.begin(), str.end(), str_copy.begin(),
32  [](char c) { return to_lower(c); });
33  return str_copy;
34 }
35 
36 } // namespace tlx
37 
38 /******************************************************************************/
char to_lower(char ch)
Transform the given character to lower case without any localization.
Definition: to_lower.cpp:17