bool run(String string,int pos,int len) { #ifdef HX_SMART_STRINGS if (string.isUTF16Encoded()) { if (!rUtf16) { const char *error = 0; int err_offset = 0; hx::strbuf buf; rUtf16 = pcre16_compile((PCRE_SPTR16)expr.wc_str(&buf),flags|PCRE_UTF16,&error,&err_offset,NULL); if (!rUtf16) { return false; } } int n = pcre16_exec(rUtf16,NULL,(const unsigned short *)string.raw_wptr(),pos+len,pos,0,matchs,nmatchs * 3); return n>=0; } if (!rUtf8) { rUtf8 = pcre_compile(expr.utf8_str(),flags|PCRE_UTF8,0,0,0); if (!rUtf8) return false; } #endif return pcre_exec(rUtf8,NULL,string.utf8_str(),pos+len,pos,0,matchs,nmatchs * 3) >= 0; }
Dynamic _hx_regexp_new_options(String s, String opt) { hx::strbuf buf; const char *o = opt.utf8_str(&buf); int options = PCRE_UCP; while( *o ) { switch( *o++ ) { case 'i': options |= PCRE_CASELESS; break; case 's': options |= PCRE_DOTALL; break; case 'm': options |= PCRE_MULTILINE; break; case 'g': options |= PCRE_UNGREEDY; break; case 'u': break; default: hx::Throw( HX_CSTRING("Regexp unknown modifier : ") + String::fromCharCode(o[-1]) ); break; } } #ifdef HX_SMART_STRINGS if (s.isUTF16Encoded()) { const char *error = 0; int err_offset = 0; pcre16 *p = pcre16_compile((PCRE_SPTR16)s.raw_wptr(),options|PCRE_UTF16,&error,&err_offset,NULL); if( !p ) hx::Throw( HX_CSTRING("Regexp compilation error : ")+String(error)+HX_CSTRING(" in ")+s); pcredata *pdata = new pcredata; pdata->create16(p,s,options); return pdata; } else #endif { const char *error = 0; int err_offset = 0; pcre *p = pcre_compile(s.utf8_str(),options|PCRE_UTF8,&error,&err_offset,NULL); if( !p ) hx::Throw( HX_CSTRING("Regexp compilation error : ")+String(error)+HX_CSTRING(" in ")+s); pcredata *pdata = new pcredata; pdata->create8(p,s,options); return pdata; } }
/* * All encrypted data is hex numbers. To distinguish between strong * and weak data, we prefix the strong encryption with a '-'. */ static String strutil_encrypt_tf(const String &original) { if ( setup_twofish() ) { CryptData input(original.utf8_str()); CryptData output; int rc = TwoFishCrypt(1, 128, gs_GlobalPassword.utf8_str(), &input ,&output); if(rc) { String tmp = output.ToHex(); String tmp2; tmp2 << '-' << tmp; return tmp2; } } else { ERRORMESSAGE((_("Impossible to use encryption without password."))); } return wxEmptyString; }
double __hxcpp_parse_float(const String &inString) { if (!inString.raw_ptr()) return Math_obj::NaN; hx::strbuf buf; const char *str = inString.utf8_str(&buf); char *end = (char *)str; double result = str ? strtod(str,&end) : 0; if (end==str) return Math_obj::NaN; return result; }
Dynamic __hxcpp_parse_int(const String &inString) { if (!inString.raw_ptr()) return null(); long result; hx::strbuf buf; const char *str = inString.utf8_str(&buf); bool hex = (str[0]=='0' && (str[1]=='x' || str[1]=='X')); char *end = 0; if (hex) result = (long)strtoul(str+2,&end,16); else result = strtol(str,&end,10); if (str==end) return null(); return (int)result; }
static String strutil_decrypt_tf(const String &original) { if(! strutil_has_twofish) { ERRORMESSAGE((_("Strong encryption algorithm not available."))); return wxEmptyString; } if ( !setup_twofish() ) { ERRORMESSAGE((_("Impossible to use encryption without password."))); } CryptData input; input.FromHex(original.c_str()+1); // skip initial '-' CryptData output; int rc = TwoFishCrypt(0, 128, gs_GlobalPassword.utf8_str(), &input,&output); if(rc) { return output.data; } return wxEmptyString; }
// encode the given text unconditionally, i.e. without checking if it must be // encoded (this is supposed to be done in the caller) and using the specified // encodings and charset (which are supposed to be detected by the caller too) static String EncodeText(const String& in, wxFontEncoding enc, MIME::Encoding enc2047, const String& csName) { // encode the word splitting it in the chunks such that they will be no // longer than 75 characters each wxCharBuffer buf(in.mb_str(wxCSConv(enc))); if ( !buf ) { // if the header can't be encoded using the given encoding, use UTF-8 // which always works buf = in.utf8_str(); } String out; out.reserve(csName.length() + strlen(buf) + 7 /* for =?...?X?...?= */); const char *s = buf; while ( *s ) { // if we wrapped, insert a line break if ( !out.empty() ) out += "\r\n "; static const size_t RFC2047_MAXWORD_LEN = 75; // how many characters may we put in this encoded word? size_t len = 0; // take into account the length of "=?charset?...?=" int lenRemaining = RFC2047_MAXWORD_LEN - (5 + csName.length()); // for QP we need to examine all characters if ( enc2047 == MIME::Encoding_QuotedPrintable ) { for ( ; s[len]; len++ ) { const char c = s[len]; // normal characters stand for themselves in QP, the encoded ones // take 3 positions (=XX) lenRemaining -= (NeedsEncodingInHeader(c) || strchr(" \t=?", c)) ? 3 : 1; if ( lenRemaining <= 0 ) { // can't put any more chars into this word break; } } } else // Base64 { // rfc822_binary() splits lines after 60 characters so don't make // chunks longer than this as the base64-encoded headers can't have // EOLs in them static const int CCLIENT_MAX_BASE64_LEN = 60; if ( lenRemaining > CCLIENT_MAX_BASE64_LEN ) lenRemaining = CCLIENT_MAX_BASE64_LEN; // we can calculate how many characters we may put into lenRemaining // directly len = (lenRemaining / 4) * 3 - 2; // but not more than what we have size_t lenMax = wxStrlen(s); if ( len > lenMax ) { len = lenMax; } } // do encode this word unsigned char *text = (unsigned char *)s; // cast for cclient // length of the encoded text and the text itself unsigned long lenEnc; unsigned char *textEnc; if ( enc2047 == MIME::Encoding_QuotedPrintable ) { textEnc = rfc822_8bit(text, len, &lenEnc); } else // Encoding_Base64 { textEnc = rfc822_binary(text, len, &lenEnc); while ( textEnc[lenEnc - 2] == '\r' && textEnc[lenEnc - 1] == '\n' ) { // discard eol which we don't need in the header lenEnc -= 2; } } // put into string as we might want to do some more replacements... String encword(wxString::FromAscii(CHAR_CAST(textEnc), lenEnc)); // hack: rfc822_8bit() doesn't encode spaces normally but we must // do it inside the headers // // we also have to encode '?'s in the headers which are not encoded by it if ( enc2047 == MIME::Encoding_QuotedPrintable ) { String encword2; encword2.reserve(encword.length()); bool replaced = false; for ( const wxChar *p = encword.c_str(); *p; p++ ) { switch ( *p ) { case ' ': encword2 += _T("=20"); break; case '\t': encword2 += _T("=09"); break; case '?': encword2 += _T("=3F"); break; default: encword2 += *p; // skip assignment to replaced below continue; } replaced = true; } if ( replaced ) { encword = encword2; } } // append this word to the header out << _T("=?") << csName << _T('?') << (char)enc2047 << _T('?') << encword << _T("?="); fs_give((void **)&textEnc); // skip the already encoded part s += len; } return out; }