diff options
Diffstat (limited to 'core/ustring.cpp')
-rw-r--r-- | core/ustring.cpp | 100 |
1 files changed, 93 insertions, 7 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index cb0540dbb0..cd33c276a8 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -2467,13 +2467,8 @@ int String::findn(String p_str,int p_from) const { }; - CharType src=srcd[read_pos]; - CharType dst=p_str[j]; - - if (src>='a' && src<='z') - src-='a'-'A'; - if (dst>='a' && dst<='z') - dst-='a'-'A'; + CharType src=_find_lower(srcd[read_pos]); + CharType dst=_find_lower(p_str[j]); if (src!=dst) { found=false; @@ -2490,10 +2485,101 @@ int String::findn(String p_str,int p_from) const { int String::rfind(String p_str,int p_from) const { + //stabilish a limit + int limit = length()-p_str.length(); + if (limit<0) + return -1; + + //stabilish a starting point + if (p_from<0) + p_from=limit; + else if (p_from>limit) + p_from=limit; + + int src_len=p_str.length(); + int len=length(); + + if(src_len==0 || len==0) + return -1; //wont find anything! + + + const CharType *src = c_str(); + + for (int i=p_from;i>=0;i--) { + + bool found=true; + for (int j=0;j<src_len;j++) { + + int read_pos=i+j; + + if (read_pos>=len) { + + ERR_PRINT("read_pos>=len"); + return -1; + }; + + + if (src[read_pos]!=p_str[j]) { + found=false; + break; + } + } + + if (found) + return i; + } + return -1; } int String::rfindn(String p_str,int p_from) const { + //stabilish a limit + int limit = length()-p_str.length(); + if (limit<0) + return -1; + + //stabilish a starting point + if (p_from<0) + p_from=limit; + else if (p_from>limit) + p_from=limit; + + int src_len=p_str.length(); + int len=length(); + + if(src_len==0 || len==0) + return -1; //wont find anything! + + + const CharType *src = c_str(); + + for (int i=p_from;i>=0;i--) { + + bool found=true; + for (int j=0;j<src_len;j++) { + + int read_pos=i+j; + + if (read_pos>=len) { + + ERR_PRINT("read_pos>=len"); + return -1; + }; + + CharType srcc=_find_lower(src[read_pos]); + CharType dstc=_find_lower(p_str[j]); + + + if (srcc!=dstc) { + found=false; + break; + } + } + + if (found) + return i; + } + return -1; } |