migrating conversion modifiers from JetCore::Global to MString.

This commit is contained in:
barant committed 2024-12-19 10:32:23 -08:00
1 parent 10df4a6a99
commit f8557aa5f5
4 files changed
+196

No files matched your search

+126
View File
@@ -1,6 +1,7 @@
#include "MString.h"
#include "Log.h"
#include "uuid/uuid.h"
#include "Exception.h"
#include <cstring>
#include <string>
#include <format>
@@ -279,5 +280,130 @@ namespace coreutils {
int MString::offset() {
return cursor - data;
}
MString MString::toBinary() {
push();
reset();
MString target;
char temp;
while(!eod()) {
temp = nextChar();
if(strchr("\\'\".\0\r\n", temp))
target.write('\\');
target.write(temp);
}
pop();
return target;
}
MString MString::fromBinary() {
push();
reset();
MString target;
while(!eod()) {
if(ifNext("\\r"))
target.write(13);
else if(ifNext("\\n"))
target.write(10);
else if(ifNext("\\0"))
target.write(0);
else if(ifNext("\\\\"))
target.write("\\");
else if(ifNext("\\."))
target.write(".");
else if(ifNext("\\\""))
target.write("\"");
else if(ifNext("\\\'"))
target.write("'");
else
target.write(nextChar());
}
pop();
return target;
}
MString MString::toHex() {
push();
reset();
MString target;
char temp;
while(!eod()) {
temp = nextChar();
char temp2 = temp;
temp >>= 4;
target.write(hexChar(temp));
target.write(hexChar(temp2));
}
pop();
return target;
}
MString MString::fromHex() {
push();
reset();
MString target;
while(!eod()) {
char ch1 = nextChar();
ch1 -= 48;
if(ch1 > 9)
ch1 -= 7;
ch1 <<= 4;
ch1 &= 240;
if(eod())
coreutils::Exception("conversion from hex requires even number of characters.");
char ch2 = nextChar();
ch2 -= 48;
if(ch2 > 9)
ch2 -= 7;
ch2 &= 15;
ch1 |= ch2;
target.write(ch1);
}
pop();
return target;
}
MString MString::toBase64() {
MString target;
return target;
}
MString MString::fromBase64() {
MString target;
return target;
}
MString MString::toUpper() {
MString target;
return target;
}
MString MString::toLower() {
MString target;
return target;
}
MString MString::toCGI() {
MString target;
return target;
}
MString MString::fromCGI() {
MString target;
return target;
}
char MString::hexChar(char c) {
c &= 15;
c += 48;
if(c > 57)
c += 7;
return c;
}
}