|
a/src/utils/smallut.cpp |
|
b/src/utils/smallut.cpp |
|
... |
|
... |
532 |
return out;
|
532 |
return out;
|
533 |
}
|
533 |
}
|
534 |
|
534 |
|
535 |
|
535 |
|
536 |
// Substitute printf-like percent cmds inside a string
|
536 |
// Substitute printf-like percent cmds inside a string
|
537 |
bool pcSubst(const string& in, string& out, map<char, string>& subs)
|
537 |
bool pcSubst(const string& in, string& out, const map<char, string>& subs)
|
538 |
{
|
538 |
{
|
539 |
string::const_iterator it;
|
539 |
string::const_iterator it;
|
540 |
for (it = in.begin(); it != in.end();it++) {
|
540 |
for (it = in.begin(); it != in.end();it++) {
|
541 |
if (*it == '%') {
|
541 |
if (*it == '%') {
|
542 |
if (++it == in.end()) {
|
542 |
if (++it == in.end()) {
|
|
... |
|
... |
545 |
}
|
545 |
}
|
546 |
if (*it == '%') {
|
546 |
if (*it == '%') {
|
547 |
out += '%';
|
547 |
out += '%';
|
548 |
continue;
|
548 |
continue;
|
549 |
}
|
549 |
}
|
550 |
map<char,string>::iterator tr;
|
550 |
map<char,string>::const_iterator tr;
|
551 |
if ((tr = subs.find(*it)) != subs.end()) {
|
551 |
if ((tr = subs.find(*it)) != subs.end()) {
|
552 |
out += tr->second;
|
552 |
out += tr->second;
|
553 |
} else {
|
553 |
} else {
|
554 |
// We used to do "out += *it;" here but this does not make
|
554 |
// We used to do "out += *it;" here but this does not make
|
555 |
// sense
|
555 |
// sense
|
|
... |
|
... |
559 |
}
|
559 |
}
|
560 |
}
|
560 |
}
|
561 |
return true;
|
561 |
return true;
|
562 |
}
|
562 |
}
|
563 |
|
563 |
|
564 |
bool pcSubst(const string& in, string& out, map<string, string>& subs)
|
564 |
bool pcSubst(const string& in, string& out, const map<string, string>& subs)
|
565 |
{
|
565 |
{
|
566 |
out.erase();
|
566 |
out.erase();
|
567 |
string::size_type i;
|
567 |
string::size_type i;
|
568 |
for (i = 0; i < in.size(); i++) {
|
568 |
for (i = 0; i < in.size(); i++) {
|
569 |
if (in[i] == '%') {
|
569 |
if (in[i] == '%') {
|
|
... |
|
... |
590 |
key = in.substr(i, j-i);
|
590 |
key = in.substr(i, j-i);
|
591 |
i = j;
|
591 |
i = j;
|
592 |
} else {
|
592 |
} else {
|
593 |
key = in[i];
|
593 |
key = in[i];
|
594 |
}
|
594 |
}
|
595 |
map<string,string>::iterator tr;
|
595 |
map<string,string>::const_iterator tr;
|
596 |
if ((tr = subs.find(key)) != subs.end()) {
|
596 |
if ((tr = subs.find(key)) != subs.end()) {
|
597 |
out += tr->second;
|
597 |
out += tr->second;
|
598 |
} else {
|
598 |
} else {
|
599 |
// Substitute to nothing, that's the reasonable thing to do
|
599 |
// Substitute to nothing, that's the reasonable thing to do
|
600 |
// instead of keeping the %(key)
|
600 |
// instead of keeping the %(key)
|