Fix some nits in CJS_Document helpers.

Change-Id: Iad2eaf53fcca2d4eee92760cdbd6da2869695d56
Reviewed-on: https://pdfium-review.googlesource.com/c/43831
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp
index 6e2f2da..7f81a37 100644
--- a/fxjs/cjs_document.cpp
+++ b/fxjs/cjs_document.cpp
@@ -32,31 +32,29 @@
 
 #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF)
 
-int CountWords(CPDF_TextObject* pTextObj) {
-  if (!pTextObj)
-    return 0;
-
+int CountWords(const CPDF_TextObject* pTextObj) {
   CPDF_Font* pFont = pTextObj->GetFont();
   if (!pFont)
     return 0;
 
-  bool bIsLatin = false;
+  bool bInLatinWord = false;
   int nWords = 0;
   for (size_t i = 0, sz = pTextObj->CountChars(); i < sz; ++i) {
     uint32_t charcode = CPDF_Font::kInvalidCharCode;
-    float kerning;
+    float unused_kerning;
 
-    pTextObj->GetCharInfo(i, &charcode, &kerning);
+    pTextObj->GetCharInfo(i, &charcode, &unused_kerning);
     WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
 
     uint16_t unicode = 0;
     if (swUnicode.GetLength() > 0)
       unicode = swUnicode[0];
 
-    if (ISLATINWORD(unicode) && bIsLatin)
+    bool bIsLatin = ISLATINWORD(unicode);
+    if (bIsLatin && bInLatinWord)
       continue;
 
-    bIsLatin = ISLATINWORD(unicode);
+    bInLatinWord = bIsLatin;
     if (unicode != 0x20)
       nWords++;
   }
@@ -64,30 +62,28 @@
   return nWords;
 }
 
-WideString GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex) {
-  WideString swRet;
-
+WideString GetObjWordStr(const CPDF_TextObject* pTextObj, int nWordIndex) {
   CPDF_Font* pFont = pTextObj->GetFont();
   if (!pFont)
     return L"";
 
+  WideString swRet;
   int nWords = 0;
-  bool bIsLatin = false;
-
+  bool bInLatinWord = false;
   for (size_t i = 0, sz = pTextObj->CountChars(); i < sz; ++i) {
     uint32_t charcode = CPDF_Font::kInvalidCharCode;
-    float kerning;
+    float unused_kerning;
 
-    pTextObj->GetCharInfo(i, &charcode, &kerning);
+    pTextObj->GetCharInfo(i, &charcode, &unused_kerning);
     WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
 
     uint16_t unicode = 0;
     if (swUnicode.GetLength() > 0)
       unicode = swUnicode[0];
 
-    if (ISLATINWORD(unicode) && bIsLatin) {
-    } else {
-      bIsLatin = ISLATINWORD(unicode);
+    bool bIsLatin = ISLATINWORD(unicode);
+    if (!bIsLatin || !bInLatinWord) {
+      bInLatinWord = bIsLatin;
       if (unicode != 0x20)
         nWords++;
     }