From 74aa295f55b335b4b89cc8739a1dcf229bcce05c Mon Sep 17 00:00:00 2001 From: Phil Krylov Date: Mon, 9 Jan 2006 17:12:34 +0100 Subject: [PATCH] riched20: Simplified logic in ME_StrRelPos(). --- dlls/riched20/string.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/dlls/riched20/string.c b/dlls/riched20/string.c index 6abd22a5ff8..c9057bf5059 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(nVCharnLen && *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; }