Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions yenc/yenc.zep
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,43 @@ class yEnc
*/
public lastError;

/**
* Decodes yEncoded text, does not do any checks to see if it's valid.
*/
public function decodeIgnore(string! encodedText) -> boolean
{
array matches = [];
/* Zephir doesn't allow stringing to a property, it resets the property every time.
Instead use a local variable and copy it to the property after we're done.
*/
string encoded, decoded = "";
uint i, max, intchar;

let this->decoded = "";

if (!preg_match("#ybegin.+?([\r\n]{1,2}=ypart.+?)?[\r\n](.+)[\r\n]{1,2}=yend#i", encodedText, matches)) {
return false;
}
let encoded = (string)matches[2];
let max = encoded->length();
if (encoded[max] == 0) {
let max--;
}
let i = 0;
while (i < max) {
let intchar = encoded[i];
if (intchar == 61) {
let i++;
let decoded .= chr((intchar - 64) - 42);
} else {
let decoded .= chr(intchar - 42);
}
let i++;
}
let this->decoded = decoded;
return decoded != "";
}

public function decode(string! encodedText) -> string|boolean
{
var dummy, entry;
Expand Down