d[--pos] = digs[r];
}
if (pad > 0) {
- for (int i = 128 - pos; i < pad; i ++) {
+ for (int i = 128 - pos; i < pad && i < 128; i ++) {
d[--pos] = '0';
}
}
ans.assign (d + pos, 128 - pos);
} else {
+ /* *** */
}
return ans;
}
return boost::to_upper_copy (str);
}
-ustring hexEncode (const ustring& data) {
+ustring hexEncode (const ustring& data, bool upcase) {
ustring ans;
uiterator b, e;
+ char (*fn) (int);
+ if (upcase)
+ fn = hexchar_c;
+ else
+ fn = hexchar;
ans.reserve (data.length () * 2);
b = data.begin ();
e = data.end ();
for (; b < e; b ++) {
- ans.append (1, hexchar ((*b >> 4) & 0x0f));
- ans.append (1, hexchar (*b & 0x0f));
+ ans.append (1, fn ((*b >> 4) & 0x0f));
+ ans.append (1, fn (*b & 0x0f));
}
return ans;
}
ustring formatDateString (const ustring& format, struct tm& v);
ustring toLower (const ustring& str);
ustring toUpper (const ustring& str);
-ustring hexEncode (const ustring& data);
+ustring hexEncode (const ustring& data, bool upcase = false);
ustring hexDecode (const ustring& data);
int octchar (uiterator b);
ustring octchar (int c);
/*DOC:
===base64-decode===
- (base64-decode STRING...) -> STRING
+ (base64-decode [#hex | #HEX] STRING...) -> STRING
*/
//#AFUNC base64-decode ml_base64_decode
MNode* ml_base64_decode (MNode* cell, MlEnv* mlenv) {
MNode* arg = cell->cdr ();
ustring str;
+ bool fhex = false;
+ bool fHex = false;
+ std::vector<MNode*> keywords;
+ MNode* rest;
+ static paramList kwlist[] = {
+ {CharConst ("hex"), true},
+ {CharConst ("HEX"), true},
+ {NULL, 0, 0}
+ };
- while (arg) {
- str.append (eval_str (arg->car (), mlenv));
- nextNode (arg);
+ setParams (arg, 0, NULL, kwlist, &keywords, &rest);
+ evkw_bool (0, fhex);
+ evkw_bool (1, fHex);
+ while (rest) {
+ str.append (eval_str (rest->car (), mlenv));
+ nextNode (rest);
}
-
str = base64Decode (str.begin (), str.end ());
-
- return newMNode_str (new ustring (fixUTF8 (str)));
+ if (fhex) {
+ str = hexEncode (str);
+ } else if (fHex) {
+ str = hexEncode (str, true);
+ } else {
+ str = fixUTF8 (str);
+ }
+ return newMNode_str (new ustring (str));
}
/*DOC:
/*DOC:
===hex-encode===
- (hex-encode STRING...) -> STRING
- (string-to-hex STRING ...) -> STRING
+ (hex-encode [#HEX] STRING...) -> STRING
+ (string-to-hex [#HEX] STRING ...) -> STRING
*/
//#AFUNC hex-encode ml_hex_encode
MNode* arg = cell->cdr ();
ustring text;
ustring ans;
+ bool fHex = false;
+ std::vector<MNode*> keywords;
+ MNode* rest;
+ static paramList kwlist[] = {
+ {CharConst ("HEX"), true},
+ {NULL, 0, 0}
+ };
- while (arg) {
- text = eval_str (arg->car (), mlenv);
- nextNode (arg);
- ans.append (hexEncode (text));
+ setParams (arg, 0, NULL, kwlist, &keywords, &rest);
+ evkw_bool (0, fHex);
+ while (rest) {
+ text = eval_str (rest->car (), mlenv);
+ nextNode (rest);
+ ans.append (hexEncode (text, fHex));
}
return newMNode_str (new ustring (ans));
}
MNode* ml_to_string (MNode* cell, MlEnv* mlenv) {
MNode* arg = cell->cdr ();
bool fhex = false;
- bool fuhex = false;
+ bool fHex = false;
bool foct = false;
bool fbin = false;
int pad = 0;
+ MNodePtr obj;
ustring text;
std::vector<MNode*> params;
std::vector<MNode*> keywords;
};
setParams (arg, 1, ¶ms, kwlist, &keywords, NULL);
+ obj = eval (params[0], mlenv);
evkw_bool (0, fhex);
- evkw_bool (1, fuhex);
+ evkw_bool (1, fHex);
evkw_bool (2, foct);
evkw_bool (3, fbin);
evkw_int (4, pad);
- if (fhex) {
- text = dtohex (eval_double (params[0], mlenv), pad, 16, false);
- } else if (fuhex) {
- text = dtohex (eval_double (params[0], mlenv), pad, 16, true);
- } else if (foct) {
- text = dtohex (eval_double (params[0], mlenv), pad, 8);
- } else if (fbin) {
- text = dtohex (eval_double (params[0], mlenv), pad, 2);
+ if (fhex || fHex || foct || fbin) {
+ if (isReal (obj ())) {
+ if (fhex) {
+ text = dtohex (to_double (obj ()), pad, 16, false);
+ } else if (fHex) {
+ text = dtohex (to_double (obj ()), pad, 16, true);
+ } else if (foct) {
+ text = dtohex (to_double (obj ()), pad, 8);
+ } else if (fbin) {
+ text = dtohex (to_double (obj ()), pad, 2);
+ }
+ } else {
+ }
} else {
- text = eval_str (params[0], mlenv);
+ text = to_string (obj ());
}
return newMNode_str (new ustring (text));
}
[[c3:VALUE]]
*/
-//#WIKILINE c3 wl_c3
+//#WIKILINE c3 wl_c3
bool wl_c3 (WikiMotorObjVecVec* args, WikiMotorObjVec& out, WikiFormat* wiki) {
WikiMotorObjVecVec::const_iterator b = args->begin ();
WikiMotorObjVecVec::const_iterator e = args->end ();