diff options
Diffstat (limited to 'core/ustring.cpp')
-rw-r--r-- | core/ustring.cpp | 133 |
1 files changed, 118 insertions, 15 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index d119e341c3..cb0540dbb0 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -1596,6 +1596,7 @@ bool String::is_numeric() const { }; #define IS_DIGIT(m_d) ( (m_d)>='0' && (m_d)<='9' ) +#define IS_HEX_DIGIT(m_d) ( ( (m_d)>='0' && (m_d)<='9' ) || ( (m_d)>='a' && (m_d)<='f' ) || ( (m_d)>='A' && (m_d)<='F' ) ) template<class C> static double built_in_strtod(const C *string, /* A decimal ASCII floating-point number, @@ -2275,6 +2276,24 @@ String String::md5_text() const { return String::md5(ctx.digest); } +Vector<uint8_t> String::md5_buffer() const { + + CharString cs=utf8(); + MD5_CTX ctx; + MD5Init(&ctx); + MD5Update(&ctx,(unsigned char*)cs.ptr(),cs.length()); + MD5Final(&ctx); + + Vector<uint8_t> ret; + ret.resize(16); + for (int i=0; i<16; i++) { + ret[i] = ctx.digest[i]; + }; + + return ret; +}; + + String String::insert(int p_at_pos,String p_string) const { if (p_at_pos<0) @@ -2640,7 +2659,7 @@ String String::right(int p_pos) const { if (p_pos<0) return ""; - return substr(p_pos+1,(length()-p_pos)-1); + return substr(p_pos,(length()-p_pos)); } CharType String::ord_at(int p_idx) const { @@ -2891,23 +2910,107 @@ String String::xml_escape(bool p_escape_quotes) const { return str; } -String String::xml_unescape() const { +static _FORCE_INLINE_ int _xml_unescape(const CharType *p_src,int p_src_len,CharType *p_dst) { - String str=*this; - str=str.strip_edges(); - //str=str.replace("\"",""); - str=str.replace(">","<"); - str=str.replace("<",">"); - str=str.replace("'","'"); - str=str.replace(""","\""); - /* - for (int i=1;i<32;i++) { + int len=0; + while(p_src_len) { - char chr[2]={i,0}; - str=str.replace("&#"+String::num(i)+";",chr); - }*/ - str=str.replace("&","&"); + if (*p_src=='&') { + + int eat=0; + + if (p_src_len>=4 && p_src[1]=='#') { + + CharType c=0; + + for(int i=2;i<p_src_len;i++) { + + eat=i+1; + CharType ct=p_src[i]; + if (ct==';') { + break; + } else if (ct>='0' && ct<='9') { + ct=ct-'0'; + } else if (ct>='a' && ct<='f') { + ct=(ct-'a')+10; + } else if (ct>='A' && ct<='F') { + ct=(ct-'A')+10; + } else { + continue; + } + c<<=4; + c|=ct; + } + + if (p_dst) + *p_dst=c; + } else if (p_src_len>=4 && p_src[1]=='g' && p_src[2]=='t' && p_src[3]==';') { + + if (p_dst) + *p_dst='<'; + eat=4; + } else if (p_src_len>=4 && p_src[1]=='l' && p_src[2]=='t' && p_src[3]==';') { + + if (p_dst) + *p_dst='>'; + eat=4; + } else if (p_src_len>=5 && p_src[1]=='a' && p_src[2]=='m' && p_src[3]=='p' && p_src[4]==';') { + + if (p_dst) + *p_dst='&'; + eat=5; + } else if (p_src_len>=6 && p_src[1]=='q' && p_src[2]=='u' && p_src[3]=='o' && p_src[4]=='t' && p_src[5]==';') { + + if (p_dst) + *p_dst='"'; + eat=6; + } else if (p_src_len>=6 && p_src[1]=='a' && p_src[2]=='p' && p_src[3]=='o' && p_src[4]=='s' && p_src[5]==';') { + + if (p_dst) + *p_dst='\''; + eat=6; + } else { + + if (p_dst) + *p_dst=*p_src; + eat=1; + + } + + if (p_dst) + p_dst++; + + len++; + p_src+=eat; + p_src_len-=eat; + } else { + + if (p_dst) { + *p_dst=*p_src; + p_dst++; + } + len++; + p_src++; + p_src_len--; + } + } + + return len; + +} + +String String::xml_unescape() const { + + + String str; + int l = length(); + int len = _xml_unescape(c_str(),l,NULL); + if (len==0) + return String(); + str.resize(len+1); + _xml_unescape(c_str(),l,&str[0]); + str[len]=0; return str; } |