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