2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2007-02-21 16:37:27 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2007-02-21 16:37:27 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC 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 3 of the License, or (at your option) any later version.
|
2007-02-21 16:37:27 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2007-02-21 16:37:27 +00:00
|
|
|
// 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.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2007-02-21 16:37:27 +00:00
|
|
|
|
|
|
|
#ifndef STR_UTIL_H
|
|
|
|
#define STR_UTIL_H
|
|
|
|
|
2010-09-30 22:16:18 +00:00
|
|
|
#include <string>
|
2014-10-24 21:22:07 +00:00
|
|
|
#include <vector>
|
2012-07-02 18:51:02 +00:00
|
|
|
#include <string.h>
|
2007-02-21 16:37:27 +00:00
|
|
|
|
2011-02-09 00:21:40 +00:00
|
|
|
extern void strcpy_overlap(char*, const char*);
|
2007-02-21 16:37:27 +00:00
|
|
|
extern int ndays_to_string(double x, int smallest_timescale, char *buf);
|
|
|
|
extern void nbytes_to_string(double nbytes, double total_bytes, char* str, int len);
|
|
|
|
extern int parse_command_line(char*, char**);
|
|
|
|
extern void c2x(char *what);
|
|
|
|
extern void strip_whitespace(char *str);
|
2010-09-30 22:16:18 +00:00
|
|
|
extern void strip_whitespace(std::string&);
|
2007-02-21 16:37:27 +00:00
|
|
|
extern char* time_to_string(double);
|
|
|
|
extern char* precision_time_to_string(double);
|
2012-05-07 15:41:34 +00:00
|
|
|
extern void secs_to_hmsf(double, char*);
|
2010-09-30 22:16:18 +00:00
|
|
|
extern std::string timediff_format(double);
|
|
|
|
|
|
|
|
inline bool ends_with(std::string const& s, std::string const& suffix) {
|
|
|
|
return
|
|
|
|
s.size()>=suffix.size() &&
|
|
|
|
s.substr(s.size()-suffix.size()) == suffix;
|
|
|
|
}
|
|
|
|
|
2012-02-07 17:54:09 +00:00
|
|
|
inline bool ends_with(const char* s, const char* suffix) {
|
|
|
|
int m = (int)strlen(s), n = (int)strlen(suffix);
|
|
|
|
if (n > m) return false;
|
|
|
|
return (strcmp(suffix, s+m-n) == 0);
|
|
|
|
}
|
|
|
|
|
2010-09-30 22:16:18 +00:00
|
|
|
inline bool starts_with(std::string const& s, std::string const& prefix) {
|
|
|
|
return s.substr(0, prefix.size()) == prefix;
|
|
|
|
}
|
|
|
|
|
2012-02-16 23:59:26 +00:00
|
|
|
inline bool starts_with(const char* s, const char* prefix) {
|
|
|
|
return (strncmp(s, prefix, strlen(prefix)) == 0);
|
|
|
|
}
|
|
|
|
|
2010-09-30 22:16:18 +00:00
|
|
|
inline void downcase_string(std::string& w) {
|
|
|
|
for (std::string::iterator p = w.begin(); p != w.end(); ++p) {
|
|
|
|
*p = (char)tolower((int)*p);
|
|
|
|
}
|
|
|
|
}
|
2007-02-21 16:37:27 +00:00
|
|
|
|
2009-07-22 18:41:02 +00:00
|
|
|
inline void downcase_string(char* p) {
|
|
|
|
while (*p) {
|
2010-03-02 00:21:40 +00:00
|
|
|
*p = (char)tolower((int)*p);
|
2009-07-22 18:41:02 +00:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-19 19:46:18 +00:00
|
|
|
extern int string_substitute(
|
|
|
|
const char* haystack, char* out, int out_len,
|
|
|
|
const char* needle, const char* target
|
|
|
|
);
|
|
|
|
|
2010-09-30 22:16:18 +00:00
|
|
|
// convert UNIX time to MySQL timestamp (yyyymmddhhmmss)
|
|
|
|
//
|
|
|
|
extern void mysql_timestamp(double, char*);
|
|
|
|
|
2014-09-12 01:06:05 +00:00
|
|
|
// parse host.serialnum into component parts.
|
|
|
|
// Given a string of the form
|
|
|
|
// [BOINC|7.2.42][CUDA|GeForce GTX 860M|1|2048MB|34052|101][INTEL|Intel(R) HD Graphics 4600|1|1752MB||102][vbox|4.2.16]
|
|
|
|
// split it into the BOINC, vbox, and other (coproc) parts
|
|
|
|
//
|
|
|
|
extern void parse_serialnum(char* in, char* boinc, char* vbox, char* coprocs);
|
|
|
|
|
2014-02-27 00:16:51 +00:00
|
|
|
// take a malloced string.
|
|
|
|
// if \n is not last char, add it.
|
|
|
|
//
|
|
|
|
extern char* lf_terminate(char*);
|
|
|
|
|
2007-02-21 16:37:27 +00:00
|
|
|
extern const char* network_status_string(int);
|
|
|
|
extern const char* rpc_reason_string(int);
|
2010-05-07 16:14:54 +00:00
|
|
|
extern const char* suspend_reason_string(int reason);
|
2010-11-10 18:17:20 +00:00
|
|
|
extern const char* run_mode_string(int mode);
|
2013-06-18 18:33:22 +00:00
|
|
|
extern const char* battery_state_string(int state);
|
|
|
|
extern const char* result_client_state_string(int state);
|
|
|
|
extern const char* result_scheduler_state_string(int state);
|
|
|
|
extern const char* active_task_state_string(int state);
|
2013-10-22 22:27:34 +00:00
|
|
|
extern const char* batch_state_string(int state);
|
2010-05-07 16:14:54 +00:00
|
|
|
|
2010-10-28 21:46:18 +00:00
|
|
|
extern void strip_translation(char* p);
|
2010-09-30 05:05:05 +00:00
|
|
|
|
2014-10-24 21:22:07 +00:00
|
|
|
extern std::vector<std::string> split(std::string, char delim);
|
2015-09-17 20:48:04 +00:00
|
|
|
|
2010-09-30 22:16:18 +00:00
|
|
|
#endif
|