Laid foundation for modifiers and built a couple.
This commit is contained in:
parent
39f5936787
commit
7fbbac4a65
23
Global.cpp
23
Global.cpp
@ -1,6 +1,7 @@
|
||||
#include "Global.h"
|
||||
#include "Exception.h"
|
||||
#include "__mysql.h"
|
||||
#include "Modifiers.h"
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
@ -38,9 +39,29 @@ namespace jet {
|
||||
}
|
||||
|
||||
coreutils::MString& Global::processModifier(coreutils::MString &value, coreutils::MString &modifier) {
|
||||
Modifiers modifiers;
|
||||
if(modifier.getLength() == 0)
|
||||
return value;
|
||||
lastConverted = modifier;
|
||||
if(modifier == "tobinary")
|
||||
modifiers.processToBinaryModifier(value, lastConverted);
|
||||
if(modifier == "frombinary")
|
||||
modifiers.processFromBinaryModifier(value, lastConverted);
|
||||
if(modifier == "tohex")
|
||||
modifiers.processToHexModifier(value, lastConverted);
|
||||
if(modifier == "fromhex")
|
||||
modifiers.processFromHexModifier(value, lastConverted);
|
||||
if(modifier == "tobase64")
|
||||
modifiers.processToBase64Modifier(value, lastConverted);
|
||||
if(modifier == "frombase64")
|
||||
modifiers.processFromBase64Modifier(value, lastConverted);
|
||||
if(modifier == "toupper")
|
||||
modifiers.processToUpperModifier(value, lastConverted);
|
||||
if(modifier == "tolower")
|
||||
modifiers.processToLowerModifier(value, lastConverted);
|
||||
if(modifier == "tocgi")
|
||||
modifiers.processToCGIModifier(value, lastConverted);
|
||||
if(modifier == "fromcgi")
|
||||
modifiers.processFromCGIModifier(value, lastConverted);
|
||||
return lastConverted;
|
||||
}
|
||||
|
||||
|
85
Modifiers.cpp
Normal file
85
Modifiers.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
#include "Modifiers.h"
|
||||
#include "Exception.h"
|
||||
|
||||
namespace jet {
|
||||
|
||||
void Modifiers::processToBinaryModifier(coreutils::MString &value, coreutils::MString &lastConverted) {
|
||||
value.reset();
|
||||
lastConverted = "";
|
||||
char temp;
|
||||
while(!value.eod()) {
|
||||
temp = value.nextChar();
|
||||
if(strchr("\\'\".\0\r\n", temp))
|
||||
lastConverted.write('\\');
|
||||
lastConverted.write(temp);
|
||||
}
|
||||
value.reset();
|
||||
}
|
||||
|
||||
void Modifiers::processFromBinaryModifier(coreutils::MString &value, coreutils::MString &lastConverted) {
|
||||
}
|
||||
|
||||
void Modifiers::processToHexModifier(coreutils::MString &value, coreutils::MString &lastConverted) {
|
||||
value.reset();
|
||||
lastConverted = "";
|
||||
char temp;
|
||||
while(!value.eod()) {
|
||||
temp = value.nextChar();
|
||||
char temp2 = temp;
|
||||
temp >>= 4;
|
||||
lastConverted.write(hexChar(temp));
|
||||
lastConverted.write(hexChar(temp2));
|
||||
}
|
||||
value.reset();
|
||||
}
|
||||
|
||||
void Modifiers::processFromHexModifier(coreutils::MString &value, coreutils::MString &lastConverted) {
|
||||
value.reset();
|
||||
lastConverted = "";
|
||||
while(!value.eod()) {
|
||||
char ch1 = value.nextChar();
|
||||
ch1 -= 48;
|
||||
if(ch1 > 9)
|
||||
ch1 -= 7;
|
||||
ch1 <<= 4;
|
||||
ch1 &= 240;
|
||||
if(value.eod())
|
||||
coreutils::Exception("conversion from hex requires even number of characters.");
|
||||
char ch2 = value.nextChar();
|
||||
ch2 -= 48;
|
||||
if(ch2 > 9)
|
||||
ch2 -= 7;
|
||||
ch2 &= 15;
|
||||
ch1 |= ch2;
|
||||
lastConverted.write(ch1);
|
||||
}
|
||||
value.reset();
|
||||
}
|
||||
|
||||
void Modifiers::processToBase64Modifier(coreutils::MString &value, coreutils::MString &lastConverted) {
|
||||
}
|
||||
|
||||
void Modifiers::processFromBase64Modifier(coreutils::MString &value, coreutils::MString &lastConverted) {
|
||||
}
|
||||
|
||||
void Modifiers::processToUpperModifier(coreutils::MString &value, coreutils::MString &lastConverted) {
|
||||
}
|
||||
|
||||
void Modifiers::processToLowerModifier(coreutils::MString &value, coreutils::MString &lastConverted) {
|
||||
}
|
||||
|
||||
void Modifiers::processToCGIModifier(coreutils::MString &value, coreutils::MString &lastConverted) {
|
||||
}
|
||||
|
||||
void Modifiers::processFromCGIModifier(coreutils::MString &value, coreutils::MString &lastConverted) {
|
||||
}
|
||||
|
||||
char Modifiers::hexChar(char c) {
|
||||
c &= 15;
|
||||
c += 48;
|
||||
if(c > 57)
|
||||
c += 7;
|
||||
return c;
|
||||
}
|
||||
|
||||
}
|
29
Modifiers.h
Normal file
29
Modifiers.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef __MODIFIERS_H__
|
||||
#define __MODIFIERS_H__
|
||||
|
||||
#include "MString.h"
|
||||
|
||||
namespace jet {
|
||||
|
||||
class Modifiers {
|
||||
|
||||
public:
|
||||
void processToBinaryModifier(coreutils::MString &value, coreutils::MString &lastConverted);
|
||||
void processFromBinaryModifier(coreutils::MString &value, coreutils::MString &lastConverted);
|
||||
void processToHexModifier(coreutils::MString &value, coreutils::MString &lastConverted);
|
||||
void processFromHexModifier(coreutils::MString &value, coreutils::MString &lastConverted);
|
||||
void processToBase64Modifier(coreutils::MString &value, coreutils::MString &lastConverted);
|
||||
void processFromBase64Modifier(coreutils::MString &value, coreutils::MString &lastConverted);
|
||||
void processToUpperModifier(coreutils::MString &value, coreutils::MString &lastConverted);
|
||||
void processToLowerModifier(coreutils::MString &value, coreutils::MString &lastConverted);
|
||||
void processToCGIModifier(coreutils::MString &value, coreutils::MString &lastConverted);
|
||||
void processFromCGIModifier(coreutils::MString &value, coreutils::MString &lastConverted);
|
||||
|
||||
private:
|
||||
char hexChar(char c);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
10
tests/testmodifiers.jet
Executable file
10
tests/testmodifiers.jet
Executable file
@ -0,0 +1,10 @@
|
||||
#!../jet-2.0
|
||||
<jet>
|
||||
<set name="tester1" value="this is a test of the hex conversion." />
|
||||
<set name="tester2" value="$[tester1;tohex]" />
|
||||
1) $[tester1;tobinary]
|
||||
2) $[tester1;tohex]
|
||||
3) $[tester2;fromhex]
|
||||
4) $[tester1]
|
||||
5) $[tester2]
|
||||
</jet>
|
Loading…
x
Reference in New Issue
Block a user