Phil Krylov : riched20: Simplified logic in ME_StrRelPos().

Alexandre Julliard julliard at wine.codeweavers.com
Mon Jan 9 13:52:41 CST 2006


Module: wine
Branch: refs/heads/master
Commit: 74aa295f55b335b4b89cc8739a1dcf229bcce05c
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=74aa295f55b335b4b89cc8739a1dcf229bcce05c

Author: Phil Krylov <phil at newstar.rinet.ru>
Date:   Mon Jan  9 17:12:34 2006 +0100

riched20: Simplified logic in ME_StrRelPos().

---

 dlls/riched20/string.c |   27 ++++++++++-----------------
 1 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/dlls/riched20/string.c b/dlls/riched20/string.c
index 6abd22a..c9057bf 100644
--- a/dlls/riched20/string.c
+++ b/dlls/riched20/string.c
@@ -155,29 +155,22 @@ int ME_StrVLen(ME_String *s) {
   return s->nLen;
 }
 
-/* FIXME we use widechars, not multibytes, inside, no need for complex logic anymore */
 int ME_StrRelPos(ME_String *s, int nVChar, int *pRelChars)
 {
+  int nRelChars = *pRelChars;
+  
   TRACE("%s,%d,&%d\n", debugstr_w(s->szData), nVChar, *pRelChars);
 
   assert(*pRelChars);
-  if (!*pRelChars) return nVChar;
-  
-  if (*pRelChars>0)
-  {
-    while(nVChar<s->nLen && *pRelChars>0)
-    {
-      nVChar++;
-      (*pRelChars)--;
-    }
+  if (!nRelChars)
     return nVChar;
-  }
-
-  while(nVChar>0 && *pRelChars<0)
-  {
-    nVChar--;
-    (*pRelChars)++;
-  }
+  
+  if (nRelChars>0)
+    nRelChars = min(*pRelChars, s->nLen - nVChar);
+  else
+    nRelChars = max(*pRelChars, -nVChar);
+  nVChar += nRelChars;
+  *pRelChars -= nRelChars;
   return nVChar;
 }
 




More information about the wine-cvs mailing list