diff options
author | Kostyantyn Ovechko <fastinetserver@gmail.com> | 2010-08-14 15:41:13 +0300 |
---|---|---|
committer | Kostyantyn Ovechko <fastinetserver@gmail.com> | 2010-08-14 15:41:13 +0300 |
commit | 404e6d597145751d4b829774f9bc56f44e1fa9fc (patch) | |
tree | 60015376de8b9e29c0e41b8d2efa699072e86ad2 /seggetd/str.cpp | |
parent | Add arguments to request tool: --help, --keep-pkglist-file. (diff) | |
download | idfetch-404e6d597145751d4b829774f9bc56f44e1fa9fc.tar.gz idfetch-404e6d597145751d4b829774f9bc56f44e1fa9fc.tar.bz2 idfetch-404e6d597145751d4b829774f9bc56f44e1fa9fc.zip |
Move /tmp folders/files to /var/tmp
Diffstat (limited to 'seggetd/str.cpp')
-rw-r--r-- | seggetd/str.cpp | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/seggetd/str.cpp b/seggetd/str.cpp new file mode 100644 index 0000000..cc7e813 --- /dev/null +++ b/seggetd/str.cpp @@ -0,0 +1,159 @@ +/* +* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>. +* +* Project: IDFetch. +* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine). +* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead). +* Mentoring organization: Gentoo Linux. +* Sponsored by GSOC 2010. +* +* This file is part of Segget. +* +* Segget is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* Segget is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with Segget; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "str.h" + +string toString(uint t){ + stringstream s; + s << t; + return s.str(); +} +string toString(int t){ + stringstream s; + s << t; + return s.str(); +} +string toString(ulong t){ + stringstream s; + s << t; + return s.str(); +} +string toString(long t){ + stringstream s; + s << t; + return s.str(); +} +string toString(bool t){ + stringstream s; + s << t; + return s.str(); +} +string toString(double t){ + stringstream s; + s << t; + return s.str(); +} + +vector <string> split_to_vector(string splitter, string str){ + vector <string> parts; + uint splitter_pos=str.find(splitter); + while (splitter_pos!=str.npos){ + parts.push_back(str.substr(0,splitter_pos)); + str=str.substr(splitter_pos+splitter.length()); + splitter_pos=str.find(splitter); + } + if (str.length()>0){ + parts.push_back(str); + } + return parts; +} + +/* +template<typename T> string toString(T t){ + stringstream s; + s << t; + return s.str(); +} +*/ +/* +template<typename T> string field(string prefix,T t, int width){ + try{ + stringstream s1,s2; + s1 << t; + width=width+prefix.length(); + s2.width(width); + s2 << prefix+s1.str(); + return s2.str(); + }catch(...){ + error_log("Error in str.cpp: field()"); + return ""; + } +} +*/ +string field(string prefix,ulong t, int width){ + try{ + stringstream s1,s2; + s1 << t; + width=width+prefix.length(); + s2.width(width); + s2 << prefix+s1.str(); + return s2.str(); + }catch(...){ + error_log("Error in str.cpp: field()"); + return ""; + } +} + +int lower_char(int c){ + try{ + return tolower((unsigned char)c); + }catch(...){ + error_log("Error in str.cpp: lower_char()"); + return 0; + } +} + +string noupper(string s){ + try{ + transform(s.begin(), s.end(), s.begin(), lower_char); + return s; + }catch(...){ + error_log("Error in str.cpp: noupper()"); + return ""; + } +} + +bool split(string splitter, string str, string &before, string &after){ + try{ + uint splitter_pos=str.find(splitter); + if (splitter_pos==str.npos) return 1; + before=str.substr(0,splitter_pos); + after=str.substr(splitter_pos+splitter.length()); + return 0; + }catch(...){ + error_log("Error in str.cpp: split()"); + return 1; + } +} + +string trim(std::string const& source, char const* delims) { + try{ + string result(source); + string::size_type index = result.find_last_not_of(delims); + if(index != string::npos) + result.erase(++index); + + index = result.find_first_not_of(delims); + if(index != string::npos) + result.erase(0, index); + else + result.erase(); + return result; + }catch(...){ + error_log("Error in str.cpp: trim()"); + return ""; + } +}
\ No newline at end of file |