[3/5] richedit: Removed ME_StrLen and ME_StrVLen field access functions.

Dylan Smith dylan.ah.smith at gmail.com
Sat Feb 7 12:21:17 CST 2009


These functions were probably previously needed because of some wierd
special handling of backspace characters, but currently there is no
reason why the nLen field can't be accessed directly.

Having to functions that just access the string length field just causes
slightly more effort for someone to look at the code, because they need
to enter the function to find out what it actually is doing.
---
 dlls/riched20/caret.c  |   10 +++++-----
 dlls/riched20/editor.c |   22 +++++++++++-----------
 dlls/riched20/editor.h |    3 ---
 dlls/riched20/paint.c  |    6 +++---
 dlls/riched20/run.c    |   14 +++++++-------
 dlls/riched20/string.c |   25 +++----------------------
 dlls/riched20/wrap.c   |    6 +++---
 dlls/riched20/writer.c |    4 ++--
 8 files changed, 34 insertions(+), 56 deletions(-)
-------------- next part --------------
diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index cc8aefd..84b2f5f 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -204,7 +204,7 @@ ME_GetCursorCoordinates(ME_TextEditor *editor, ME_Cursor *pCursor,
       assert(run);
       assert(run->type == diRun);
       sz = ME_GetRunSize(&c, &para->member.para,
-                         &run->member.run, ME_StrLen(run->member.run.strText),
+                         &run->member.run, run->member.run.strText->nLen,
                          row->member.row.nLMargin);
     }
   }
@@ -347,7 +347,7 @@ BOOL ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, int nChars,
         nCharsToDelete, nChars, c.nOffset,
         debugstr_w(run->strText->szData), run->strText->nLen);
 
-      if (!c.nOffset && ME_StrVLen(run->strText) == nCharsToDelete)
+      if (!c.nOffset && run->strText->nLen == nCharsToDelete)
       {
         /* undo = reinsert whole run */
         /* nOfs is a character offset (from the start of the document
@@ -381,9 +381,9 @@ BOOL ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, int nChars,
             else
               pThisCur->nOffset -= nCharsToDelete;
             assert(pThisCur->nOffset >= 0);
-            assert(pThisCur->nOffset <= ME_StrVLen(run->strText));
+            assert(pThisCur->nOffset <= run->strText->nLen);
           }
-          if (pThisCur->nOffset == ME_StrVLen(run->strText))
+          if (pThisCur->nOffset == run->strText->nLen)
           {
             pThisCur->pRun = ME_FindItemFwd(pThisCur->pRun, diRunOrParagraphOrEnd);
             assert(pThisCur->pRun->type == diRun);
@@ -399,7 +399,7 @@ BOOL ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, int nChars,
       else
         ME_PropagateCharOffset(c.pRun, shift);
 
-      if (!ME_StrVLen(cursor.pRun->member.run.strText))
+      if (!cursor.pRun->member.run.strText->nLen)
       {
         TRACE("Removing useless run\n");
         ME_Remove(cursor.pRun);
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 2721745..2827f42 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -1721,7 +1721,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
           /* Check to see if next character is a whitespace */
           if (flags & FR_WHOLEWORD)
           {
-            if (nCurStart + nMatched == ME_StrLen(pCurItem->member.run.strText))
+            if (nCurStart + nMatched == pCurItem->member.run.strText->nLen)
             {
               pNextItem = ME_FindItemFwd(pCurItem, diRun);
               nNextStart = -nMatched;
@@ -1745,7 +1745,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
           TRACE("found at %d-%d\n", nStart, nStart + nLen);
           return nStart;
         }
-        if (nCurStart + nMatched == ME_StrLen(pCurItem->member.run.strText))
+        if (nCurStart + nMatched == pCurItem->member.run.strText->nLen)
         {
           pCurItem = ME_FindItemFwd(pCurItem, diRun);
           nCurStart = -nMatched;
@@ -1757,7 +1757,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
         wLastChar = ' ';
 
       nStart++;
-      if (nStart == ME_StrLen(item->member.run.strText))
+      if (nStart == item->member.run.strText->nLen)
       {
         item = ME_FindItemFwd(item, diRun);
         para = ME_GetParagraph(item);
@@ -1786,7 +1786,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
       if (nCurEnd == 0)
       {
         pCurItem = ME_FindItemBack(pCurItem, diRun);
-        nCurEnd = ME_StrLen(pCurItem->member.run.strText) + nMatched;
+        nCurEnd = pCurItem->member.run.strText->nLen + nMatched;
       }
 
       while (pCurItem && ME_CharCompare(pCurItem->member.run.strText->szData[nCurEnd - nMatched - 1], text[nLen - nMatched - 1], (flags & FR_MATCHCASE)))
@@ -1808,7 +1808,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
             {
               pPrevItem = ME_FindItemBack(pCurItem, diRun);
               if (pPrevItem)
-                nPrevEnd = ME_StrLen(pPrevItem->member.run.strText) + nMatched;
+                nPrevEnd = pPrevItem->member.run.strText->nLen + nMatched;
             }
 
             if (pPrevItem)
@@ -1835,7 +1835,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
           pCurItem = ME_FindItemBack(pCurItem, diRun);
           /* Don't care about pCurItem becoming NULL here; it's already taken
            * care of in the exterior loop condition */
-          nCurEnd = ME_StrLen(pCurItem->member.run.strText) + nMatched;
+          nCurEnd = pCurItem->member.run.strText->nLen + nMatched;
         }
       }
       if (pCurItem)
@@ -1848,7 +1848,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
       {
         item = ME_FindItemBack(item, diRun);
         para = ME_GetParagraph(item);
-        nEnd = ME_StrLen(item->member.run.strText);
+        nEnd = item->member.run.strText->nLen;
       }
     }
   }
@@ -4697,12 +4697,12 @@ static BOOL ME_FindNextURLCandidate(ME_TextEditor *editor, int sel_min, int sel_
     if (!(item->member.run.nFlags & MERF_ENDPARA)) {
       /* Find start of candidate */
       if (*candidate_min == -1) {
-        while (nStart < ME_StrLen(item->member.run.strText) &&
+        while (nStart < item->member.run.strText->nLen &&
                 !(isalnumW(item->member.run.strText->szData[nStart]) ||
                   isurlspecial(item->member.run.strText->szData[nStart]))) {
           nStart++;
         }
-        if (nStart < ME_StrLen(item->member.run.strText) &&
+        if (nStart < item->member.run.strText->nLen &&
                 (isalnumW(item->member.run.strText->szData[nStart]) ||
                  isurlspecial(item->member.run.strText->szData[nStart]))) {
           *candidate_min = para->member.para.nCharOfs + item->member.run.nCharOfs + nStart;
@@ -4713,7 +4713,7 @@ static BOOL ME_FindNextURLCandidate(ME_TextEditor *editor, int sel_min, int sel_
 
       /* Find end of candidate */
       if (*candidate_min >= 0) {
-        while (nStart < ME_StrLen(item->member.run.strText) &&
+        while (nStart < item->member.run.strText->nLen &&
                 (isalnumW(item->member.run.strText->szData[nStart]) ||
                  isurlspecial(item->member.run.strText->szData[nStart]) ||
                  (!foundColon && item->member.run.strText->szData[nStart] == ':') )) {
@@ -4721,7 +4721,7 @@ static BOOL ME_FindNextURLCandidate(ME_TextEditor *editor, int sel_min, int sel_
           lastAcceptedChar = item->member.run.strText->szData[nStart];
           nStart++;
         }
-        if (nStart < ME_StrLen(item->member.run.strText) &&
+        if (nStart < item->member.run.strText->nLen &&
                 !(isalnumW(item->member.run.strText->szData[nStart]) ||
                  isurlspecial(item->member.run.strText->szData[nStart]) )) {
           *candidate_max = para->member.para.nCharOfs + item->member.run.nCharOfs + nStart;
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 6cd7ad1..8be36b1 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -99,9 +99,6 @@ ME_String *ME_ConcatString(const ME_String *s1, const ME_String *s2);
 ME_String *ME_VSplitString(ME_String *orig, int nVPos);
 int ME_IsWhitespaces(const ME_String *s);
 int ME_IsSplitable(const ME_String *s);
-/* int ME_CalcSkipChars(ME_String *s); */
-int ME_StrLen(const ME_String *s);
-int ME_StrVLen(const ME_String *s);
 int ME_FindNonWhitespaceV(const ME_String *s, int nVChar);
 int ME_FindWhitespaceV(ME_String *s, int nVChar);
 int ME_CallWordBreakProc(ME_TextEditor *editor, ME_String *str, INT start, INT code);
diff --git a/dlls/riched20/paint.c b/dlls/riched20/paint.c
index 28813d4..ba2b471 100644
--- a/dlls/riched20/paint.c
+++ b/dlls/riched20/paint.c
@@ -446,9 +446,9 @@ static void ME_DrawRun(ME_Context *c, int x, int y, ME_DisplayItem *rundi, ME_Pa
   {
     if (c->editor->cPasswordMask)
     {
-      ME_String *szMasked = ME_MakeStringR(c->editor->cPasswordMask,ME_StrVLen(run->strText));
+      ME_String *szMasked = ME_MakeStringR(c->editor->cPasswordMask, run->strText->nLen);
       ME_DrawTextWithStyle(c, x, y,
-        szMasked->szData, ME_StrVLen(szMasked), run->style, run->nWidth,
+        szMasked->szData, szMasked->nLen, run->style, run->nWidth,
         nSelFrom-runofs,nSelTo-runofs,
         c->pt.y + para->pt.y + start->member.row.pt.y,
         start->member.row.nHeight);
@@ -456,7 +456,7 @@ static void ME_DrawRun(ME_Context *c, int x, int y, ME_DisplayItem *rundi, ME_Pa
     }
     else
       ME_DrawTextWithStyle(c, x, y,
-        run->strText->szData, ME_StrVLen(run->strText), run->style, run->nWidth,
+        run->strText->szData, run->strText->nLen, run->style, run->nWidth,
         nSelFrom-runofs,nSelTo-runofs,
         c->pt.y + para->pt.y + start->member.row.pt.y,
         start->member.row.nHeight);
diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c
index 265c0ab..ed066ea 100644
--- a/dlls/riched20/run.c
+++ b/dlls/riched20/run.c
@@ -225,7 +225,7 @@ void ME_JoinRuns(ME_TextEditor *editor, ME_DisplayItem *p)
   for (i=0; i<editor->nCursors; i++) {
     if (editor->pCursors[i].pRun == pNext) {
       editor->pCursors[i].pRun = p;
-      editor->pCursors[i].nOffset += ME_StrVLen(p->member.run.strText);
+      editor->pCursors[i].nOffset += p->member.run.strText->nLen;
     }
   }
 
@@ -302,7 +302,7 @@ ME_DisplayItem *ME_SplitRunSimple(ME_TextEditor *editor, ME_DisplayItem *item, i
   ME_DisplayItem *item2;
   ME_Run *run2;
   int i;
-  assert(nVChar > 0 && nVChar < ME_StrVLen(run->strText));
+  assert(nVChar > 0 && nVChar < run->strText->nLen);
   assert(item->type == diRun);
   assert(!(item->member.run.nFlags & MERF_NONTEXT));
   assert(item->member.run.nCharOfs != -1);
@@ -481,7 +481,7 @@ int ME_CharFromPoint(ME_Context *c, int cx, ME_Run *run)
   
   if (c->editor->cPasswordMask)
   {
-    ME_String *strMasked = ME_MakeStringR(c->editor->cPasswordMask,ME_StrVLen(run->strText));
+    ME_String *strMasked = ME_MakeStringR(c->editor->cPasswordMask, run->strText->nLen);
     GetTextExtentExPointW(c->hDC, strMasked->szData, run->strText->nLen,
       cx, &fit, NULL, &sz);
     ME_DestroyString(strMasked);
@@ -538,7 +538,7 @@ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run)
   }
 
   if (editor->cPasswordMask)
-    strRunText = ME_MakeStringR(editor->cPasswordMask,ME_StrVLen(run->strText));
+    strRunText = ME_MakeStringR(editor->cPasswordMask, run->strText->nLen);
   else
     strRunText = run->strText;
 
@@ -602,7 +602,7 @@ int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset)
   }
 
   if (editor->cPasswordMask)
-    strRunText = ME_MakeStringR(editor->cPasswordMask,ME_StrVLen(pRun->strText));
+    strRunText = ME_MakeStringR(editor->cPasswordMask, pRun->strText->nLen);
   else
     strRunText = pRun->strText;
 
@@ -623,7 +623,7 @@ static SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run
                                 int startx, int *pAscent, int *pDescent)
 {
   SIZE size;
-  int nMaxLen = ME_StrVLen(run->strText);
+  int nMaxLen = run->strText->nLen;
 
   if (nLen>nMaxLen)
     nLen = nMaxLen;
@@ -716,7 +716,7 @@ void ME_CalcRunExtent(ME_Context *c, const ME_Paragraph *para, int startx, ME_Ru
     run->nWidth = 0;
   else
   {
-    int nEnd = ME_StrVLen(run->strText);
+    int nEnd = run->strText->nLen;
     SIZE size = ME_GetRunSizeCommon(c, para, run, nEnd, startx,
                                     &run->nAscent, &run->nDescent);
     run->nWidth = size.cx;
diff --git a/dlls/riched20/string.c b/dlls/riched20/string.c
index fe4c1a4..ee13885 100644
--- a/dlls/riched20/string.c
+++ b/dlls/riched20/string.c
@@ -163,25 +163,6 @@ int ME_IsSplitable(const ME_String *s)
   return 0;
 }
 
-/* FIXME multibyte */
-/*
-int ME_CalcSkipChars(ME_String *s)
-{
-  int cnt = 0;
-  while(cnt < s->nLen && s->szData[s->nLen-1-cnt]==' ')
-    cnt++;
-  return cnt;
-}
-*/
-
-int ME_StrLen(const ME_String *s) {
-  return s->nLen;
-}
-
-int ME_StrVLen(const ME_String *s) {
-  return s->nLen;
-}
-
 int ME_StrRelPos(const ME_String *s, int nVChar, int *pRelChars)
 {
   int nRelChars = *pRelChars;
@@ -231,7 +212,7 @@ int ME_GetCharFwd(const ME_String *s, int nPos)
 {
   int nVPos = 0;
 
-  assert(nPos < ME_StrLen(s));
+  assert(nPos < s->nLen);
   if (nPos)
     nVPos = ME_StrRelPos2(s, nVPos, nPos);
   
@@ -242,9 +223,9 @@ int ME_GetCharFwd(const ME_String *s, int nPos)
 
 int ME_GetCharBack(const ME_String *s, int nPos)
 {
-  int nVPos = ME_StrVLen(s);
+  int nVPos = s->nLen;
 
-  assert(nPos < ME_StrLen(s));
+  assert(nPos < s->nLen);
   if (nPos)
     nVPos = ME_StrRelPos2(s, nVPos, -nPos);
   
diff --git a/dlls/riched20/wrap.c b/dlls/riched20/wrap.c
index 952f208..a51e2db 100644
--- a/dlls/riched20/wrap.c
+++ b/dlls/riched20/wrap.c
@@ -254,7 +254,7 @@ static ME_DisplayItem *ME_SplitByBacktracking(ME_WrapContext *wc, ME_DisplayItem
   ME_Run *run = &p->member.run;
 
   idesp = i = ME_CharFromPoint(wc->context, loc, run);
-  len = ME_StrVLen(run->strText);
+  len = run->strText->nLen;
   assert(len>0);
   assert(i<len);
   if (i) {
@@ -281,7 +281,7 @@ static ME_DisplayItem *ME_SplitByBacktracking(ME_WrapContext *wc, ME_DisplayItem
 
       piter = wc->pLastSplittableRun;
       run = &piter->member.run;
-      len = ME_StrVLen(run->strText);
+      len = run->strText->nLen;
       /* don't split words */
       i = ME_ReverseFindWhitespaceV(run->strText, len);
       if (i == len)
@@ -340,7 +340,7 @@ static ME_DisplayItem *ME_WrapHandleRun(ME_WrapContext *wc, ME_DisplayItem *p)
   run->pt.x = wc->pt.x;
   run->pt.y = wc->pt.y;
   ME_WrapSizeRun(wc, p);
-  len = ME_StrVLen(run->strText);
+  len = run->strText->nLen;
 
   if (wc->bOverflown) /* just skipping final whitespaces */
   {
diff --git a/dlls/riched20/writer.c b/dlls/riched20/writer.c
index deacaf8..d1d9990 100644
--- a/dlls/riched20/writer.c
+++ b/dlls/riched20/writer.c
@@ -889,7 +889,7 @@ ME_StreamOutRTF(ME_TextEditor *editor, ME_OutStream *pStream, int nStart, int nC
           if (!ME_StreamOutRTFCharProps(pStream, &p->member.run.style->fmt))
             return FALSE;
         
-          nEnd = (p == pEnd) ? nEndLen : ME_StrLen(p->member.run.strText);
+          nEnd = (p == pEnd) ? nEndLen : p->member.run.strText->nLen;
           if (!ME_StreamOutRTFText(pStream, p->member.run.strText->szData + nOffset, nEnd - nOffset))
             return FALSE;
           nOffset = 0;
@@ -931,7 +931,7 @@ ME_StreamOutText(ME_TextEditor *editor, ME_OutStream *pStream, int nStart, int n
   /* TODO: Handle SF_TEXTIZED */
 
   while (success && nChars && item) {
-    nLen = min(nChars, ME_StrLen(item->member.run.strText) - nStart);
+    nLen = min(nChars, item->member.run.strText->nLen - nStart);
 
     if (!editor->bEmulateVersion10 && item->member.run.nFlags & MERF_ENDPARA)
     {


More information about the wine-patches mailing list