Adds support to t:compressWhitespace

This commit is contained in:
Felipe Zimmerle 2015-10-21 19:42:14 -03:00
parent 3d2ec2a3f5
commit 0227fe9d6c
2 changed files with 23 additions and 9 deletions

View File

@ -37,16 +37,28 @@ CompressWhitespace::CompressWhitespace(std::string action)
std::string CompressWhitespace::evaluate(std::string value,
Assay *assay) {
/**
* @todo Implement the transformation CompressWhitespace
*/
if (assay) {
#ifndef NO_LOGS
assay->debug(4, "Transformation CompressWhitespace is " \
"not implemented yet.");
#endif
std::string a;
int inWhiteSpace = 0;
int i = 0;
while (i < value.size()) {
if (isspace(value[i])) {
if (inWhiteSpace) {
i++;
continue;
} else {
inWhiteSpace = 1;
a.append(" ", 1);
}
} else {
inWhiteSpace = 0;
a.append(&value.at(i), 1);
}
i++;
}
return value;
return a;
}
} // namespace transformations

View File

@ -45,6 +45,7 @@
#include "actions/transformations/remove_comments.h"
#include "actions/transformations/remove_nulls.h"
#include "actions/transformations/remove_whitespace.h"
#include "actions/transformations/compress_whitespace.h"
#include "actions/transformations/replace_comments.h"
#include "actions/transformations/replace_nulls.h"
#include "actions/transformations/sha1.h"
@ -96,6 +97,7 @@ Transformation* Transformation::instantiate(std::string a) {
IF_MATCH(remove_comments) { return new RemoveComments(a); }
IF_MATCH(removeNulls) { return new RemoveNulls(a); }
IF_MATCH(remove_whitespace) { return new RemoveWhitespace(a); }
IF_MATCH(compressWhitespace) { return new CompressWhitespace(a); }
IF_MATCH(replace_comments) { return new ReplaceComments(a); }
IF_MATCH(replace_nulls) { return new ReplaceNulls(a); }
IF_MATCH(sha1) { return new Sha1(a); }