#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) { value.reset(); lastConverted = ""; while(!value.eod()) { if(value.ifNext("\\r")) lastConverted.write(13); else if(value.ifNext("\\n")) lastConverted.write(10); else if(value.ifNext("\\0")) lastConverted.write(0); else if(value.ifNext("\\\\")) lastConverted.write("\\"); else if(value.ifNext("\\.")) lastConverted.write("."); else if(value.ifNext("\\\"")) lastConverted.write("\""); else if(value.ifNext("\\\'")) lastConverted.write("'"); else lastConverted.write(value.nextChar()); } value.reset(); } 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; } }