git-svn-id: https://profuse.googlecode.com/svn/branches/v2@269 aa027e90-d47c-11dd-86d7-074df07e0730

This commit is contained in:
ksherlock
2010-05-24 11:37:48 +00:00
parent 5f252e4dac
commit d1cf4ebfff
3 changed files with 125 additions and 184 deletions

View File

@@ -367,93 +367,56 @@ void FileEntry::textInit()
/*
* compress white space into a dle.
* returns true if altered.
*
* nb -- only leading white space is compressed.
*/
bool FileEntry::Compress(std::string& text)
{
bool delta = false;
std::string out;
size_t pos;
unsigned start;
pos = start = 0;
for(;;)
{
size_t end;
unsigned count;
pos = text.find_first_of(' ',pos);
if (pos == std::string::npos) break;
end = text.find_first_not_of(' ',pos);
count = end - pos;
if (count < 3) continue;
delta = true;
out.append(text.begin() + start, text.begin() + pos);
while (count)
{
unsigned c = std::min(223u, count);
out.push_back(kDLE); // dle code.
out.push_back(32 + c);
count -= c;
}
pos = start = end;
}
if (delta)
{
out.append(text.begin() + start, text.end());
text.swap(out);
}
return delta;
size_t count;
if (text.length() < 3) return false;
if (text[0] != ' ') return false;
pos = text.find_first_not_of(' ');
if (pos == std::string::npos)
count = text.length();
else count = pos;
if (count < 3) return false;
count = std::max((int)count, 255 - 32);
out.push_back(kDLE);
out.push_back(32 + count);
out.append(text.begin() + count, text.end());
return true;
}
/*
* dle will only occur at start.
*
*/
bool FileEntry::Uncompress(std::string& text)
{
bool delta = false;
std::string out;
size_t start;
size_t pos;
size_t length = text.length();
start = pos = 0;
for(;;)
{
unsigned c;
pos = text.find_first_of(kDLE, pos);
if (pos == std::string::npos) break;
if (pos == length - 1) break; // should not happen;
c = text[pos + 1];
if (c <= 32) continue;
delta = true;
out.append(text.begin() + start, text.begin() + pos);
out.append(c - 32, ' ');
pos = pos + 1;
start = pos;
}
if (delta)
{
out.append(text.begin() + start, text.end());
text.swap(out);
}
return delta;
unsigned c;
if (text.length() < 2) return false;
if (text[0] != kDLE) return false;
c = text[1];
if (c < 32) c = 32;
out.append(c - 32, ' ');
out.append(text.begin() + 2, text.end());
return true;
}