diff --git a/yenc/yenc.zep b/yenc/yenc.zep index e4a2618..7acc374 100644 --- a/yenc/yenc.zep +++ b/yenc/yenc.zep @@ -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;