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