1 /******************************************************************************* 2 * tlx/string/to_upper.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_upper.hpp> 12 13 #include <algorithm> 14 15 namespace tlx { 16 to_upper(char ch)17char 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 to_upper(std::string * str)23std::string& to_upper(std::string* str) { 24 std::transform(str->begin(), str->end(), str->begin(), 25 [](char c) { return to_upper(c); }); 26 return *str; 27 } 28 to_upper(const std::string & str)29std::string to_upper(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_upper(c); }); 33 return str_copy; 34 } 35 36 } // namespace tlx 37 38 /******************************************************************************/ 39