Convert calls to Mid() to Left() or Right() if possible

The various string/byte classes support Mid(), Left(), and Right() for
extracting substrings. Mid() can handle all possible cases, but Left()
and Right() are useful for common cases and  more explicit about what
is going on.

Calls like Mid(offset, length - offset) can be converted to
Right(length - offset). Calls like Mid(0, length) can be converted to
Left(length).

If the substring being extracted does not extend all the way to one of
the edges of the string, then Mid() still needs to be used.

BUG=pdfium:828

Change-Id: I2ec46ad3d71aac0f7b513e103c69cbe8c854cf62
Reviewed-on: https://pdfium-review.googlesource.com/9510
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_simplefont.cpp b/core/fpdfapi/font/cpdf_simplefont.cpp
index 8c8520f..56a4b13 100644
--- a/core/fpdfapi/font/cpdf_simplefont.cpp
+++ b/core/fpdfapi/font/cpdf_simplefont.cpp
@@ -130,7 +130,7 @@
   }
   if (m_pFontFile) {
     if (m_BaseFont.GetLength() > 8 && m_BaseFont[7] == '+')
-      m_BaseFont = m_BaseFont.Mid(8, m_BaseFont.GetLength() - 8);
+      m_BaseFont = m_BaseFont.Right(m_BaseFont.GetLength() - 8);
   } else {
     LoadSubstFont();
   }
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index 5f571aa..288f9d5 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -620,7 +620,7 @@
       break;
     }
     auto word = m_pSyntax->GetWord();
-    CFX_ByteString key(word.Mid(1, word.GetLength() - 1));
+    CFX_ByteString key(word.Right(word.GetLength() - 1));
     auto pObj = m_pSyntax->ReadNextObject(false, false, 0);
     if (!key.IsEmpty()) {
       uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0;
@@ -1186,7 +1186,7 @@
   }
   if (name == "DeviceGray" || name == "DeviceCMYK" || name == "DeviceRGB") {
     CFX_ByteString defname = "Default";
-    defname += name.Mid(7, name.GetLength() - 7);
+    defname += name.Right(name.GetLength() - 7);
     CPDF_Object* pDefObj = FindResourceObj("ColorSpace", defname);
     if (!pDefObj) {
       if (name == "DeviceGray") {
@@ -1525,7 +1525,7 @@
         break;
       case CPDF_StreamParser::Name: {
         auto word = syntax.GetWord();
-        AddNameParam(word.Mid(1, word.GetLength() - 1));
+        AddNameParam(word.Right(word.GetLength() - 1));
         break;
       }
       default:
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index 83c1f65..956f912 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -66,7 +66,7 @@
     return false;
 
   CPDF_Dictionary* pFontDict =
-      pDRFontDict->GetDictFor(sFontName.Mid(1, sFontName.GetLength() - 1));
+      pDRFontDict->GetDictFor(sFontName.Right(sFontName.GetLength() - 1));
   if (!pFontDict) {
     pFontDict = pDoc->NewIndirect<CPDF_Dictionary>();
     pFontDict->SetNewFor<CPDF_Name>("Type", "Font");
@@ -74,7 +74,7 @@
     pFontDict->SetNewFor<CPDF_Name>("BaseFont", "Helvetica");
     pFontDict->SetNewFor<CPDF_Name>("Encoding", "WinAnsiEncoding");
     pDRFontDict->SetNewFor<CPDF_Reference>(
-        sFontName.Mid(1, sFontName.GetLength() - 1), pDoc,
+        sFontName.Right(sFontName.GetLength() - 1), pDoc,
         pFontDict->GetObjNum());
   }
   CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict);
diff --git a/core/fpdftext/cpdf_linkextract.cpp b/core/fpdftext/cpdf_linkextract.cpp
index 5179f73..e0bd4ae 100644
--- a/core/fpdftext/cpdf_linkextract.cpp
+++ b/core/fpdftext/cpdf_linkextract.cpp
@@ -154,7 +154,7 @@
         while (strBeCheck.GetLength() > 0) {
           wchar_t ch = strBeCheck.GetAt(strBeCheck.GetLength() - 1);
           if (ch == L')' || ch == L',' || ch == L'>' || ch == L'.') {
-            strBeCheck = strBeCheck.Mid(0, strBeCheck.GetLength() - 1);
+            strBeCheck = strBeCheck.Left(strBeCheck.GetLength() - 1);
             nCount--;
           } else {
             break;
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index 1dc03db..8f0e376 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -441,8 +441,8 @@
 
   if (nCount == -1) {
     nCount = pdfium::CollectionSize<int>(m_CharList) - start;
-    return CFX_WideString(
-        m_TextBuf.AsStringC().Mid(start, m_TextBuf.AsStringC().GetLength()));
+    CFX_WideStringC wsTextBuf = m_TextBuf.AsStringC();
+    return CFX_WideString(wsTextBuf.Right(wsTextBuf.GetLength() - start));
   }
   if (nCount <= 0 || m_CharList.empty())
     return L"";
diff --git a/core/fpdftext/cpdf_textpagefind.cpp b/core/fpdftext/cpdf_textpagefind.cpp
index 058c293..fe610ab 100644
--- a/core/fpdftext/cpdf_textpagefind.cpp
+++ b/core/fpdftext/cpdf_textpagefind.cpp
@@ -300,7 +300,7 @@
           continue;
         }
         if (pos > 0)
-          m_csFindWhatArray.push_back(csWord.Mid(0, pos));
+          m_csFindWhatArray.push_back(csWord.Left(pos));
         m_csFindWhatArray.push_back(curStr);
         if (pos == csWord.GetLength() - 1) {
           csWord.clear();
diff --git a/core/fxcrt/xml/cxml_parser.cpp b/core/fxcrt/xml/cxml_parser.cpp
index 0166ea8..5ac1f82 100644
--- a/core/fxcrt/xml/cxml_parser.cpp
+++ b/core/fxcrt/xml/cxml_parser.cpp
@@ -86,8 +86,8 @@
   if (iStart == -1) {
     bsName = bsFullName;
   } else {
-    bsSpace = bsFullName.Mid(0, iStart);
-    bsName = bsFullName.Mid(iStart + 1, bsFullName.GetLength() - (iStart + 1));
+    bsSpace = bsFullName.Left(iStart);
+    bsName = bsFullName.Right(bsFullName.GetLength() - (iStart + 1));
   }
 }
 
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp
index 5c7b602..4c0073a 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -432,7 +432,7 @@
   CFX_ByteString SubstName = name;
   SubstName.Remove(' ');
   if (bTrueType && name[0] == '@')
-    SubstName = name.Mid(1, name.GetLength() - 1);
+    SubstName = name.Right(name.GetLength() - 1);
   PDF_GetStandardFontName(&SubstName);
   if (SubstName == "Symbol" && !bTrueType) {
     pSubstFont->m_Family = "Chrome Symbol";
@@ -453,7 +453,7 @@
   if (find >= 0) {
     family = SubstName.Left(find);
     PDF_GetStandardFontName(&family);
-    style = SubstName.Mid(find + 1, SubstName.GetLength() - (find + 1));
+    style = SubstName.Right(SubstName.GetLength() - (find + 1));
     bHasComma = true;
   } else {
     family = SubstName;
@@ -480,7 +480,7 @@
     if (!bHasComma) {
       find = family.ReverseFind('-');
       if (find >= 0) {
-        style = family.Mid(find + 1, family.GetLength() - (find + 1));
+        style = family.Right(family.GetLength() - (find + 1));
         family = family.Left(find);
         bHasHyphen = true;
       }
diff --git a/fpdfsdk/formfiller/cba_fontmap.cpp b/fpdfsdk/formfiller/cba_fontmap.cpp
index b195303..577faf4 100644
--- a/fpdfsdk/formfiller/cba_fontmap.cpp
+++ b/fpdfsdk/formfiller/cba_fontmap.cpp
@@ -221,7 +221,7 @@
 
   CFX_ByteString sFontName(syntax.GetWord());
   CFX_ByteString sDecodedFontName = PDF_NameDecode(sFontName);
-  *sAlias = sDecodedFontName.Mid(1, sDecodedFontName.GetLength() - 1);
+  *sAlias = sDecodedFontName.Right(sDecodedFontName.GetLength() - 1);
 
   CPDF_Dictionary* pFontDict = nullptr;
   if (CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictFor("AP")) {
diff --git a/fpdfsdk/fpdfppo.cpp b/fpdfsdk/fpdfppo.cpp
index d05fab9..bc3d769 100644
--- a/fpdfsdk/fpdfppo.cpp
+++ b/fpdfsdk/fpdfppo.cpp
@@ -91,7 +91,7 @@
     nStringTo = rangstring.Find(',', nStringFrom);
     if (nStringTo == -1)
       nStringTo = nLength;
-    cbMidRange = rangstring.Mid(nStringFrom, nStringTo - nStringFrom);
+    cbMidRange = rangstring.Right(nStringTo - nStringFrom);
     int nMid = cbMidRange.Find('-');
     if (nMid == -1) {
       long lPageNum = atol(cbMidRange.c_str());
@@ -99,7 +99,7 @@
         return false;
       pageArray->push_back((uint16_t)lPageNum);
     } else {
-      int nStartPageNum = atol(cbMidRange.Mid(0, nMid).c_str());
+      int nStartPageNum = atol(cbMidRange.Left(nMid).c_str());
       if (nStartPageNum == 0)
         return false;
 
diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp
index bf84b9c..06ed64c 100644
--- a/fpdfsdk/javascript/PublicMethods.cpp
+++ b/fpdfsdk/javascript/PublicMethods.cpp
@@ -980,11 +980,10 @@
     }
   }
 
-  CFX_WideString wprefix = wstrValue.Mid(0, pEvent->SelStart());
+  CFX_WideString wprefix = wstrValue.Left(pEvent->SelStart());
   CFX_WideString wpostfix;
   if (pEvent->SelEnd() < wstrValue.GetLength())
-    wpostfix = wstrValue.Mid(pEvent->SelEnd(),
-                             wstrValue.GetLength() - pEvent->SelEnd());
+    wpostfix = wstrValue.Right(wstrValue.GetLength() - pEvent->SelEnd());
   val = wprefix + wstrChange + wpostfix;
   return true;
 }
@@ -1532,14 +1531,13 @@
   CFX_WideString prefix, postfix;
 
   if (pEventHandler->SelStart() >= 0)
-    prefix = swValue.Mid(0, pEventHandler->SelStart());
+    prefix = swValue.Left(pEventHandler->SelStart());
   else
     prefix = L"";
 
   if (pEventHandler->SelEnd() >= 0 &&
       pEventHandler->SelEnd() <= swValue.GetLength())
-    postfix = swValue.Mid(pEventHandler->SelEnd(),
-                          swValue.GetLength() - pEventHandler->SelEnd());
+    postfix = swValue.Right(swValue.GetLength() - pEventHandler->SelEnd());
   else
     postfix = L"";
 
diff --git a/fxbarcode/cbc_ean13.cpp b/fxbarcode/cbc_ean13.cpp
index 1c57a87..ac08a9d 100644
--- a/fxbarcode/cbc_ean13.cpp
+++ b/fxbarcode/cbc_ean13.cpp
@@ -45,7 +45,7 @@
     encodeContents = byteString.UTF8Decode();
   }
   if (length > 13)
-    encodeContents = encodeContents.Mid(0, 13);
+    encodeContents = encodeContents.Left(13);
 
   return encodeContents;
 }
diff --git a/fxbarcode/cbc_ean8.cpp b/fxbarcode/cbc_ean8.cpp
index 3b4369e..ce2cf2b 100644
--- a/fxbarcode/cbc_ean8.cpp
+++ b/fxbarcode/cbc_ean8.cpp
@@ -43,7 +43,7 @@
     encodeContents += wchar_t(checksum - 0 + '0');
   }
   if (length > 8)
-    encodeContents = encodeContents.Mid(0, 8);
+    encodeContents = encodeContents.Left(8);
 
   return encodeContents;
 }
diff --git a/fxbarcode/cbc_upca.cpp b/fxbarcode/cbc_upca.cpp
index 6c2e08a..85b5d54 100644
--- a/fxbarcode/cbc_upca.cpp
+++ b/fxbarcode/cbc_upca.cpp
@@ -44,7 +44,7 @@
     encodeContents = byteString.UTF8Decode();
   }
   if (length > 12)
-    encodeContents = encodeContents.Mid(0, 12);
+    encodeContents = encodeContents.Left(12);
 
   return encodeContents;
 }
diff --git a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
index ec527d2..6034173 100644
--- a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
+++ b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
@@ -76,13 +76,12 @@
     return CFX_WideString();
 
   context.setAllowRectangular(allowRectangular);
-  if ((msg.Mid(0, 6) == MACRO_05_HEADER) &&
-      (msg.Mid(msg.GetLength() - 1, 1) == MACRO_TRAILER)) {
+  if ((msg.Left(6) == MACRO_05_HEADER) && (msg.Right(1) == MACRO_TRAILER)) {
     context.writeCodeword(MACRO_05);
     context.setSkipAtEnd(2);
     context.m_pos += 6;
-  } else if ((msg.Mid(0, 6) == MACRO_06_HEADER) &&
-             (msg.Mid(msg.GetLength() - 1, 1) == MACRO_TRAILER)) {
+  } else if ((msg.Left(6) == MACRO_06_HEADER) &&
+             (msg.Right(1) == MACRO_TRAILER)) {
     context.writeCodeword(MACRO_06);
     context.setSkipAtEnd(2);
     context.m_pos += 6;
diff --git a/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
index 0e4bab9..6f1d957 100644
--- a/fxbarcode/oned/BC_OnedEAN13Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
@@ -109,7 +109,7 @@
     return nullptr;
 
   m_iDataLenth = 13;
-  int32_t firstDigit = FXSYS_atoi(contents.Mid(0, 1).c_str());
+  int32_t firstDigit = FXSYS_atoi(contents.Left(1).c_str());
   int32_t parities = FIRST_DIGIT_ENCODINGS[firstDigit];
   outLength = m_codeWidth;
   std::unique_ptr<uint8_t, FxFreeDeleter> result(
@@ -219,7 +219,7 @@
                            static_cast<float>(iFontSize), &affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
-  tempStr = str.Mid(0, 1);
+  tempStr = str.Left(1);
   iLen = tempStr.GetLength();
   strWidth = multiple * 7;
   strWidth = (int32_t)(strWidth * m_outputHScale);
diff --git a/fxbarcode/oned/BC_OnedEAN8Writer.cpp b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
index f891c08..9a85f81 100644
--- a/fxbarcode/oned/BC_OnedEAN8Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
@@ -159,7 +159,7 @@
   CFX_ByteString str = FX_UTF8Encode(contents);
   int32_t iLength = str.GetLength();
   std::vector<FXTEXT_CHARPOS> charpos(iLength);
-  CFX_ByteString tempStr = str.Mid(0, 4);
+  CFX_ByteString tempStr = str.Left(4);
   int32_t iLen = tempStr.GetLength();
   int32_t strWidth = 7 * multiple * 4;
   float blank = 0.0;
diff --git a/fxbarcode/oned/BC_OnedUPCAWriter.cpp b/fxbarcode/oned/BC_OnedUPCAWriter.cpp
index 78ada17..13514eb 100644
--- a/fxbarcode/oned/BC_OnedUPCAWriter.cpp
+++ b/fxbarcode/oned/BC_OnedUPCAWriter.cpp
@@ -183,7 +183,7 @@
                            static_cast<float>(iFontSize), &affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
-  tempStr = str.Mid(0, 1);
+  tempStr = str.Left(1);
   iLen = tempStr.GetLength();
   strWidth = (float)multiple * 7;
   strWidth = strWidth * m_outputHScale;
diff --git a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
index 955e2c7..cad70b8 100644
--- a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
@@ -432,7 +432,7 @@
     index += 2;
   }
   if (index)
-    result->push_back({CBC_QRCoderMode::sGBK, content.Mid(0, index)});
+    result->push_back({CBC_QRCoderMode::sGBK, content.Left(index)});
   if (index >= content.GetLength())
     return;
 
@@ -479,7 +479,7 @@
   }
   flag = index;
   if (index < content.GetLength())
-    SplitString(content.Mid(index, content.GetLength() - index), result);
+    SplitString(content.Right(content.GetLength() - index), result);
 }
 
 CBC_QRCoderMode* ChooseMode(const CFX_ByteString& content,
diff --git a/xfa/fgas/crt/cfgas_formatstring.cpp b/xfa/fgas/crt/cfgas_formatstring.cpp
index 0abc86f..f07cce8 100644
--- a/xfa/fgas/crt/cfgas_formatstring.cpp
+++ b/xfa/fgas/crt/cfgas_formatstring.cpp
@@ -2242,7 +2242,7 @@
   }
   if (!bAddNeg && bNeg) {
     *wsOutput = pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) +
-                (*wsOutput)[0] + wsOutput->Mid(1, wsOutput->GetLength() - 1);
+                (*wsOutput)[0] + wsOutput->Right(wsOutput->GetLength() - 1);
   }
   return true;
 }
diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp
index 1278649..53fec05 100644
--- a/xfa/fwl/cfwl_edit.cpp
+++ b/xfa/fwl/cfwl_edit.cpp
@@ -1152,8 +1152,8 @@
     return false;
 
   int32_t nLen = wsText.GetLength();
-  CFX_WideString l = wsText.Mid(0, caretPos);
-  CFX_WideString r = wsText.Mid(caretPos, nLen - caretPos);
+  CFX_WideString l = wsText.Left(caretPos);
+  CFX_WideString r = wsText.Right(nLen - caretPos);
   CFX_WideString wsNew = l + cNum + r;
   return wsNew.GetInteger() <= m_iMax;
 }
diff --git a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
index 1910e60..84064efb 100644
--- a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
@@ -1139,7 +1139,7 @@
   CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr();
   CFX_ByteString szArgString = ValueToUTF8String(argOne.get());
   FX_STRSIZE pos = szArgString.Find('T', 0);
-  szArgString = szArgString.Mid(pos + 1, szArgString.GetLength() - (pos + 1));
+  szArgString = szArgString.Right(szArgString.GetLength() - (pos + 1));
   if (szArgString.IsEmpty()) {
     args.GetReturnValue()->SetInteger(0);
     return;
@@ -3694,8 +3694,7 @@
 
         CFX_WideString wsTimePattern(L"time{");
         wsTimePattern +=
-            wsPattern.Mid(iTChar + 1, wsPattern.GetLength() - (iTChar + 1)) +
-            L"}";
+            wsPattern.Right(wsPattern.GetLength() - (iTChar + 1)) + L"}";
         wsPattern = wsDatePattern + wsTimePattern;
       } break;
       case XFA_VT_DATE: {
@@ -3881,8 +3880,7 @@
       FX_STRSIZE iTChar = wsPattern.Find(L'T');
       CFX_WideString wsDatePattern(L"date{" + wsPattern.Left(iTChar) + L"} ");
       CFX_WideString wsTimePattern(
-          L"time{" +
-          wsPattern.Mid(iTChar + 1, wsPattern.GetLength() - (iTChar + 1)) +
+          L"time{" + wsPattern.Right(wsPattern.GetLength() - (iTChar + 1)) +
           L"}");
       wsPattern = wsDatePattern + wsTimePattern;
       CXFA_LocaleValue localeValue(patternType, wsValue, wsPattern, pLocale,
diff --git a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
index b201863..a74239f 100644
--- a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
@@ -62,7 +62,7 @@
   javascript << L"function ";
   if (m_wsName.GetAt(0) == L'!') {
     CFX_WideString tempName =
-        EXCLAMATION_IN_IDENTIFIER + m_wsName.Mid(1, m_wsName.GetLength() - 1);
+        EXCLAMATION_IN_IDENTIFIER + m_wsName.Right(m_wsName.GetLength() - 1);
     javascript << tempName;
   } else {
     javascript << m_wsName;
@@ -75,7 +75,7 @@
     if (identifier.GetAt(0) == L'!') {
       CFX_WideString tempIdentifier =
           EXCLAMATION_IN_IDENTIFIER +
-          identifier.Mid(1, identifier.GetLength() - 1);
+          identifier.Right(identifier.GetLength() - 1);
       javascript << tempIdentifier;
     } else {
       javascript << identifier;
@@ -130,7 +130,7 @@
   CFX_WideString tempName(m_wsName);
   if (m_wsName.GetAt(0) == L'!') {
     tempName =
-        EXCLAMATION_IN_IDENTIFIER + m_wsName.Mid(1, m_wsName.GetLength() - 1);
+        EXCLAMATION_IN_IDENTIFIER + m_wsName.Right(m_wsName.GetLength() - 1);
   }
   javascript << tempName;
   javascript << L" = ";
@@ -154,7 +154,7 @@
   CFX_WideString tempName(m_wsName);
   if (m_wsName.GetAt(0) == L'!') {
     tempName =
-        EXCLAMATION_IN_IDENTIFIER + m_wsName.Mid(1, m_wsName.GetLength() - 1);
+        EXCLAMATION_IN_IDENTIFIER + m_wsName.Right(m_wsName.GetLength() - 1);
   }
   javascript << tempName;
   javascript << L" = ";
@@ -461,7 +461,7 @@
   CFX_WideString tempVariant;
   if (m_wsVariant.GetAt(0) == L'!') {
     tempVariant = EXCLAMATION_IN_IDENTIFIER +
-                  m_wsVariant.Mid(1, m_wsVariant.GetLength() - 1);
+                  m_wsVariant.Right(m_wsVariant.GetLength() - 1);
     javascript << tempVariant;
   } else {
     tempVariant = m_wsVariant;
@@ -516,7 +516,7 @@
   CFX_WideString tempVariant;
   if (m_wsVariant.GetAt(0) == L'!') {
     tempVariant = EXCLAMATION_IN_IDENTIFIER +
-                  m_wsVariant.Mid(1, m_wsVariant.GetLength() - 1);
+                  m_wsVariant.Right(m_wsVariant.GetLength() - 1);
     javascript << tempVariant;
   } else {
     tempVariant = m_wsVariant;
@@ -583,7 +583,7 @@
   if (m_wsIdentifier.GetAt(0) == L'!') {
     CFX_WideString tempIdentifier =
         EXCLAMATION_IN_IDENTIFIER +
-        m_wsIdentifier.Mid(1, m_wsIdentifier.GetLength() - 1);
+        m_wsIdentifier.Right(m_wsIdentifier.GetLength() - 1);
     javascript << tempIdentifier;
   } else {
     javascript << m_wsIdentifier;
@@ -615,7 +615,7 @@
   if (m_wsIdentifier.GetAt(0) == L'!') {
     CFX_WideString tempIdentifier =
         EXCLAMATION_IN_IDENTIFIER +
-        m_wsIdentifier.Mid(1, m_wsIdentifier.GetLength() - 1);
+        m_wsIdentifier.Right(m_wsIdentifier.GetLength() - 1);
     javascript << tempIdentifier;
   } else {
     javascript << m_wsIdentifier;
@@ -640,7 +640,7 @@
   if (m_wsIdentifier.GetAt(0) == L'!') {
     CFX_WideString tempIdentifier =
         EXCLAMATION_IN_IDENTIFIER +
-        m_wsIdentifier.Mid(1, m_wsIdentifier.GetLength() - 1);
+        m_wsIdentifier.Right(m_wsIdentifier.GetLength() - 1);
     javascript << tempIdentifier;
   } else {
     javascript << m_wsIdentifier;
@@ -671,7 +671,7 @@
   if (m_wsIdentifier.GetAt(0) == L'!') {
     CFX_WideString tempIdentifier =
         EXCLAMATION_IN_IDENTIFIER +
-        m_wsIdentifier.Mid(1, m_wsIdentifier.GetLength() - 1);
+        m_wsIdentifier.Right(m_wsIdentifier.GetLength() - 1);
     javascript << tempIdentifier;
   } else {
     javascript << m_wsIdentifier;
diff --git a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp
index 1a3a125..32876e3 100644
--- a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp
@@ -181,7 +181,7 @@
     tempStr = L"xfa.template";
   } else if (tempStr[0] == L'!') {
     tempStr =
-        EXCLAMATION_IN_IDENTIFIER + tempStr.Mid(1, tempStr.GetLength() - 1);
+        EXCLAMATION_IN_IDENTIFIER + tempStr.Right(tempStr.GetLength() - 1);
   }
   javascript << tempStr;
   return true;
diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
index e356583..4d6886d 100644
--- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
+++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
@@ -162,7 +162,7 @@
     if (wsExpr.GetAt(0) == '#') {
       CXFA_Node* pNode = pDocument->GetNodeByID(
           ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Template)),
-          wsExpr.Mid(1, wsExpr.GetLength() - 1).AsStringC());
+          wsExpr.Right(wsExpr.GetLength() - 1).AsStringC());
       if (pNode)
         return pNode;
     } else if (bNewExprStyle) {
diff --git a/xfa/fxfa/parser/cxfa_measurement.cpp b/xfa/fxfa/parser/cxfa_measurement.cpp
index 5007658..66b715e 100644
--- a/xfa/fxfa/parser/cxfa_measurement.cpp
+++ b/xfa/fxfa/parser/cxfa_measurement.cpp
@@ -40,8 +40,8 @@
   int32_t iOffset = (wsMeasure.GetAt(0) == L'=') ? 1 : 0;
   float fValue = FXSYS_wcstof(wsMeasure.unterminated_c_str() + iOffset,
                               wsMeasure.GetLength() - iOffset, &iUsedLen);
-  XFA_UNIT eUnit = GetUnitFromString(wsMeasure.Mid(
-      iOffset + iUsedLen, wsMeasure.GetLength() - (iOffset + iUsedLen)));
+  XFA_UNIT eUnit = GetUnitFromString(
+      wsMeasure.Right(wsMeasure.GetLength() - (iOffset + iUsedLen)));
   Set(fValue, eUnit);
 }
 
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 1265988..261fee1 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -77,7 +77,7 @@
       CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
       CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
       if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
-          wsInstName.Mid(1, wsInstName.GetLength() - 1) != wsName) {
+          wsInstName.Right(wsInstName.GetLength() - 1) != wsName) {
         return iCount;
       }
       dwNameHash = pNode->GetNameHash();
@@ -198,7 +198,7 @@
       CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
       CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
       if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
-          wsInstName.Mid(1, wsInstName.GetLength() - 1) != wsName) {
+          wsInstName.Right(wsInstName.GetLength() - 1) != wsName) {
         return nullptr;
       }
       dwNameHash = pNode->GetNameHash();
@@ -2737,7 +2737,7 @@
     if (pNode->GetElementType() == XFA_Element::InstanceManager) {
       CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
       if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
-          wsInstMgrName.Mid(1, wsInstMgrName.GetLength() - 1) == wsName) {
+          wsInstMgrName.Right(wsInstMgrName.GetLength() - 1) == wsName) {
         pInstanceMgr = pNode;
       }
       break;
@@ -3165,7 +3165,7 @@
     CFX_WideString wsInstanceName = CFX_WideString(
         wsInstManagerName.IsEmpty()
             ? wsInstManagerName
-            : wsInstManagerName.Mid(1, wsInstManagerName.GetLength() - 1));
+            : wsInstManagerName.Right(wsInstManagerName.GetLength() - 1));
     uint32_t dInstanceNameHash =
         FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
     CXFA_Node* pPrevSibling =
@@ -4665,7 +4665,7 @@
         CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
         CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
         if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
-            wsInstName.Mid(1, wsInstName.GetLength() - 1) == wsName) {
+            wsInstName.Right(wsInstName.GetLength() - 1) == wsName) {
           pInstanceMgr = pNode;
         }
         break;
diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp
index 1920e9f..5efc0ea 100644
--- a/xfa/fxfa/parser/cxfa_widgetdata.cpp
+++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp
@@ -1324,8 +1324,7 @@
       int32_t fA, fB;
       fA = FXSYS_wtoi(wsWideNarrowRatio.Left(ptPos).c_str());
       fB = FXSYS_wtoi(
-          wsWideNarrowRatio
-              .Mid(ptPos + 1, wsWideNarrowRatio.GetLength() - (ptPos + 1))
+          wsWideNarrowRatio.Right(wsWideNarrowRatio.GetLength() - (ptPos + 1))
               .c_str());
       if (fB)
         fRatio = (float)fA / fB;