File: | var/lib/jenkins/workspace/firefox-scan-build/extensions/spellcheck/src/mozEnglishWordUtils.cpp |
Warning: | line 42, column 19 Value stored to 'startWord' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | |
6 | #include "mozEnglishWordUtils.h" |
7 | #include "nsComponentManagerUtils.h" |
8 | #include "nsReadableUtils.h" |
9 | #include "nsUnicharUtils.h" |
10 | #include "nsUnicodeProperties.h" |
11 | #include "nsCRT.h" |
12 | #include "mozilla/Likely.h" |
13 | |
14 | NS_IMPL_CYCLE_COLLECTION(mozEnglishWordUtils, mURLDetector)mozEnglishWordUtils::cycleCollection mozEnglishWordUtils::_cycleCollectorGlobal ; void mozEnglishWordUtils::cycleCollection::Unlink(void* p) { mozEnglishWordUtils* tmp = DowncastCCParticipant<mozEnglishWordUtils >(p); ImplCycleCollectionUnlink(tmp->mURLDetector); (void )tmp; } nsresult mozEnglishWordUtils::cycleCollection::TraverseNative ( void* p, nsCycleCollectionTraversalCallback& cb) { mozEnglishWordUtils * tmp = DowncastCCParticipant<mozEnglishWordUtils>(p); cb .DescribeRefCountedNode(tmp->mRefCnt.get(), "mozEnglishWordUtils" ); ImplCycleCollectionTraverse(cb, tmp->mURLDetector, "mURLDetector" , 0); (void)tmp; return NS_OK; } |
15 | |
16 | mozEnglishWordUtils::mozEnglishWordUtils() { |
17 | mURLDetector = do_CreateInstance(MOZ_TXTTOHTMLCONV_CONTRACTID"@mozilla.org/txttohtmlconv;1"); |
18 | } |
19 | |
20 | mozEnglishWordUtils::~mozEnglishWordUtils() {} |
21 | |
22 | // This needs vast improvement |
23 | |
24 | // static |
25 | bool mozEnglishWordUtils::ucIsAlpha(char16_t aChar) { |
26 | // XXX we have to fix callers to handle the full Unicode range |
27 | return nsUGenCategory::kLetter == mozilla::unicode::GetGenCategory(aChar); |
28 | } |
29 | |
30 | bool mozEnglishWordUtils::FindNextWord(const nsAString& aWord, uint32_t offset, |
31 | int32_t* begin, int32_t* end) { |
32 | if (offset >= aWord.Length()) { |
33 | *begin = -1; |
34 | *end = -1; |
35 | return false; |
36 | } |
37 | |
38 | const char16_t* word = aWord.BeginReading(); |
39 | uint32_t length = aWord.Length(); |
40 | const char16_t* p = word + offset; |
41 | const char16_t* endbuf = word + length; |
42 | const char16_t* startWord = p; |
Value stored to 'startWord' during its initialization is never read | |
43 | |
44 | // XXX These loops should be modified to handle non-BMP characters. |
45 | // if previous character is a word character, need to advance out of the |
46 | // word |
47 | if (offset > 0 && ucIsAlpha(*(p - 1))) { |
48 | while (p < endbuf && ucIsAlpha(*p)) { |
49 | p++; |
50 | } |
51 | } |
52 | while ((p < endbuf) && (!ucIsAlpha(*p))) { |
53 | p++; |
54 | } |
55 | startWord = p; |
56 | while ((p < endbuf) && ((ucIsAlpha(*p)) || (*p == '\''))) { |
57 | p++; |
58 | } |
59 | |
60 | // we could be trying to break down a url, we don't want to break a url into |
61 | // parts, instead we want to find out if it really is a url and if so, skip |
62 | // it, advancing startWord to a point after the url. |
63 | |
64 | // before we spend more time looking to see if the word is a url, look for a |
65 | // url identifer and make sure that identifer isn't the last character in |
66 | // the word fragment. |
67 | if ((p < endbuf - 1) && (*p == ':' || *p == '@' || *p == '.')) { |
68 | // ok, we have a possible url...do more research to find out if we really |
69 | // have one and determine the length of the url so we can skip over it. |
70 | |
71 | if (mURLDetector) { |
72 | int32_t startPos = -1; |
73 | int32_t endPos = -1; |
74 | |
75 | mURLDetector->FindURLInPlaintext(startWord, endbuf - startWord, |
76 | p - startWord, &startPos, &endPos); |
77 | |
78 | // ok, if we got a url, adjust the array bounds, skip the current url |
79 | // text and find the next word again |
80 | if (startPos != -1 && endPos != -1) { |
81 | startWord = p + endPos + 1; // skip over the url |
82 | |
83 | // now recursively call FindNextWord to search for the next word now |
84 | // that we have skipped the url |
85 | return FindNextWord(aWord, startWord - word, begin, end); |
86 | } |
87 | } |
88 | } |
89 | |
90 | while ((p > startWord) && (*(p - 1) == '\'')) { // trim trailing apostrophes |
91 | p--; |
92 | } |
93 | |
94 | if (startWord == endbuf) { |
95 | *begin = -1; |
96 | *end = -1; |
97 | return false; |
98 | } |
99 | *begin = startWord - word; |
100 | *end = p - word; |
101 | return true; |
102 | } |