/* * Copyright (c) 2010-2012 OTClient * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #ifndef STDEXT_STRING_H #define STDEXT_STRING_H #include #include #include #include "types.h" #include "cast.h" namespace stdext { template std::string to_string(const T& t) { return unsafe_cast(t); } template T from_string(const std::string& str, T def = T()) { return unsafe_cast(str, def); } /// Resolve a file path by combining sourcePath with filePath std::string resolve_path(const std::string& filePath, std::string sourcePath); /// Get current date and time in a std::string std::string date_time_string(); std::string dec_to_hex(uint64_t num); uint64_t hex_to_dec(const std::string& str); std::string utf8_to_latin1(uchar *utf8); void tolower(std::string& str); void toupper(std::string& str); void trim(std::string& str); bool ends_with(const std::string& str, const std::string& test); bool starts_with(const std::string& str, const std::string& test); void replace_all(std::string& str, const std::string& search, const std::string& replacement); std::vector split(const std::string& str, const std::string& separators = " "); template std::vector split(const std::string& str, const std::string& separators = " ") { std::vector splitted = split(str, separators); std::vector results(splitted.size()); for(uint i=0;i(splitted[i]); return results; } } #endif