|
a/sc2src/smallut.cpp |
|
b/sc2src/smallut.cpp |
|
... |
|
... |
358 |
}
|
358 |
}
|
359 |
}
|
359 |
}
|
360 |
template void stringsToString<list<string> >(const list<string>&, string&);
|
360 |
template void stringsToString<list<string> >(const list<string>&, string&);
|
361 |
template void stringsToString<vector<string> >(const vector<string>&, string&);
|
361 |
template void stringsToString<vector<string> >(const vector<string>&, string&);
|
362 |
template void stringsToString<set<string> >(const set<string>&, string&);
|
362 |
template void stringsToString<set<string> >(const set<string>&, string&);
|
|
|
363 |
template void stringsToString<unordered_set<string> >(const unordered_set<string>&, string&);
|
363 |
template <class T> string stringsToString(const T& tokens)
|
364 |
template <class T> string stringsToString(const T& tokens)
|
364 |
{
|
365 |
{
|
365 |
string out;
|
366 |
string out;
|
366 |
stringsToString<T>(tokens, out);
|
367 |
stringsToString<T>(tokens, out);
|
367 |
return out;
|
368 |
return out;
|
368 |
}
|
369 |
}
|
369 |
template string stringsToString<list<string> >(const list<string>&);
|
370 |
template string stringsToString<list<string> >(const list<string>&);
|
370 |
template string stringsToString<vector<string> >(const vector<string>&);
|
371 |
template string stringsToString<vector<string> >(const vector<string>&);
|
371 |
template string stringsToString<set<string> >(const set<string>&);
|
372 |
template string stringsToString<set<string> >(const set<string>&);
|
|
|
373 |
template string stringsToString<unordered_set<string> >(const unordered_set<string>&);
|
372 |
|
374 |
|
373 |
template <class T> void stringsToCSV(const T& tokens, string& s,
|
375 |
template <class T> void stringsToCSV(const T& tokens, string& s,
|
374 |
char sep)
|
376 |
char sep)
|
375 |
{
|
377 |
{
|
376 |
s.erase();
|
378 |
s.erase();
|
|
... |
|
... |
450 |
return false;
|
452 |
return false;
|
451 |
}
|
453 |
}
|
452 |
|
454 |
|
453 |
void trimstring(string& s, const char *ws)
|
455 |
void trimstring(string& s, const char *ws)
|
454 |
{
|
456 |
{
|
|
|
457 |
rtrimstring(s, ws);
|
|
|
458 |
ltrimstring(s, ws);
|
|
|
459 |
}
|
|
|
460 |
|
|
|
461 |
void rtrimstring(string& s, const char *ws)
|
|
|
462 |
{
|
|
|
463 |
string::size_type pos = s.find_last_not_of(ws);
|
|
|
464 |
if (pos != string::npos && pos != s.length() - 1) {
|
|
|
465 |
s.replace(pos + 1, string::npos, string());
|
|
|
466 |
}
|
|
|
467 |
}
|
|
|
468 |
|
|
|
469 |
void ltrimstring(string& s, const char *ws)
|
|
|
470 |
{
|
455 |
string::size_type pos = s.find_first_not_of(ws);
|
471 |
string::size_type pos = s.find_first_not_of(ws);
|
456 |
if (pos == string::npos) {
|
472 |
if (pos == string::npos) {
|
457 |
s.clear();
|
473 |
s.clear();
|
458 |
return;
|
474 |
return;
|
459 |
}
|
475 |
}
|
460 |
s.replace(0, pos, string());
|
476 |
s.replace(0, pos, string());
|
461 |
|
|
|
462 |
pos = s.find_last_not_of(ws);
|
|
|
463 |
if (pos != string::npos && pos != s.length() - 1) {
|
|
|
464 |
s.replace(pos + 1, string::npos, string());
|
|
|
465 |
}
|
|
|
466 |
}
|
477 |
}
|
467 |
|
478 |
|
468 |
// Remove some chars and replace them with spaces
|
479 |
// Remove some chars and replace them with spaces
|
469 |
string neutchars(const string& str, const string& chars)
|
480 |
string neutchars(const string& str, const string& chars)
|
470 |
{
|
481 |
{
|
|
... |
|
... |
666 |
out += in[i];
|
677 |
out += in[i];
|
667 |
}
|
678 |
}
|
668 |
}
|
679 |
}
|
669 |
return true;
|
680 |
return true;
|
670 |
}
|
681 |
}
|
671 |
inline static int ulltorbuf(unsigned long long val, char *rbuf)
|
682 |
inline static int ulltorbuf(uint64_t val, char *rbuf)
|
672 |
{
|
683 |
{
|
673 |
int idx;
|
684 |
int idx;
|
674 |
for (idx = 0; val; idx++) {
|
685 |
for (idx = 0; val; idx++) {
|
675 |
rbuf[idx] = '0' + val % 10;
|
686 |
rbuf[idx] = '0' + val % 10;
|
676 |
val /= 10;
|
687 |
val /= 10;
|
|
... |
|
... |
686 |
for (int i = idx - 1; i >= 0; i--) {
|
697 |
for (int i = idx - 1; i >= 0; i--) {
|
687 |
buf.push_back(rbuf[i]);
|
698 |
buf.push_back(rbuf[i]);
|
688 |
}
|
699 |
}
|
689 |
}
|
700 |
}
|
690 |
|
701 |
|
691 |
void ulltodecstr(unsigned long long val, string& buf)
|
702 |
void ulltodecstr(uint64_t val, string& buf)
|
692 |
{
|
703 |
{
|
693 |
buf.clear();
|
704 |
buf.clear();
|
694 |
if (val == 0) {
|
705 |
if (val == 0) {
|
695 |
buf = "0";
|
706 |
buf = "0";
|
696 |
return;
|
707 |
return;
|
|
... |
|
... |
701 |
|
712 |
|
702 |
ullcopyreverse(rbuf, buf, idx);
|
713 |
ullcopyreverse(rbuf, buf, idx);
|
703 |
return;
|
714 |
return;
|
704 |
}
|
715 |
}
|
705 |
|
716 |
|
706 |
void lltodecstr(long long val, string& buf)
|
717 |
void lltodecstr(int64_t val, string& buf)
|
707 |
{
|
718 |
{
|
708 |
buf.clear();
|
719 |
buf.clear();
|
709 |
if (val == 0) {
|
720 |
if (val == 0) {
|
710 |
buf = "0";
|
721 |
buf = "0";
|
711 |
return;
|
722 |
return;
|
|
... |
|
... |
726 |
|
737 |
|
727 |
ullcopyreverse(rbuf, buf, idx);
|
738 |
ullcopyreverse(rbuf, buf, idx);
|
728 |
return;
|
739 |
return;
|
729 |
}
|
740 |
}
|
730 |
|
741 |
|
731 |
string lltodecstr(long long val)
|
742 |
string lltodecstr(int64_t val)
|
732 |
{
|
743 |
{
|
733 |
string buf;
|
744 |
string buf;
|
734 |
lltodecstr(val, buf);
|
745 |
lltodecstr(val, buf);
|
735 |
return buf;
|
746 |
return buf;
|
736 |
}
|
747 |
}
|
737 |
|
748 |
|
738 |
string ulltodecstr(unsigned long long val)
|
749 |
string ulltodecstr(uint64_t val)
|
739 |
{
|
750 |
{
|
740 |
string buf;
|
751 |
string buf;
|
741 |
ulltodecstr(val, buf);
|
752 |
ulltodecstr(val, buf);
|
742 |
return buf;
|
753 |
return buf;
|
743 |
}
|
754 |
}
|
744 |
|
755 |
|
745 |
// Convert byte count into unit (KB/MB...) appropriate for display
|
756 |
// Convert byte count into unit (KB/MB...) appropriate for display
|
746 |
string displayableBytes(off_t size)
|
757 |
string displayableBytes(int64_t size)
|
747 |
{
|
758 |
{
|
748 |
const char *unit;
|
759 |
const char *unit;
|
749 |
|
760 |
|
750 |
double roundable = 0;
|
761 |
double roundable = 0;
|
751 |
if (size < 1000) {
|
762 |
if (size < 1000) {
|