Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: Source/testing/runner/MockSpellCheck.cpp

Issue 105143014: Add base:: to string16 in Source/testing/runner/. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/testing/runner/MockSpellCheck.h ('k') | Source/testing/runner/SpellCheckClient.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 BLINK_ASSERT(misspelledOffset); 61 BLINK_ASSERT(misspelledOffset);
62 BLINK_ASSERT(misspelledLength); 62 BLINK_ASSERT(misspelledLength);
63 63
64 // Initialize this spellchecker. 64 // Initialize this spellchecker.
65 initializeIfNeeded(); 65 initializeIfNeeded();
66 66
67 // Reset the result values as our spellchecker does. 67 // Reset the result values as our spellchecker does.
68 *misspelledOffset = 0; 68 *misspelledOffset = 0;
69 *misspelledLength = 0; 69 *misspelledLength = 0;
70 70
71 // Convert to a string16 because we store string16 instances in 71 // Convert to a base::string16 because we store base::string16 instances in
72 // m_misspelledWords and WebString has no find(). 72 // m_misspelledWords and WebString has no find().
73 string16 stringText = text; 73 base::string16 stringText = text;
74 int skippedLength = 0; 74 int skippedLength = 0;
75 75
76 while (!stringText.empty()) { 76 while (!stringText.empty()) {
77 // Extract the first possible English word from the given string. 77 // Extract the first possible English word from the given string.
78 // The given string may include non-ASCII characters or numbers. So, we 78 // The given string may include non-ASCII characters or numbers. So, we
79 // should filter out such characters before start looking up our 79 // should filter out such characters before start looking up our
80 // misspelled-word table. 80 // misspelled-word table.
81 // (This is a simple version of our SpellCheckWordIterator class.) 81 // (This is a simple version of our SpellCheckWordIterator class.)
82 // If the given string doesn't include any ASCII characters, we can trea t the 82 // If the given string doesn't include any ASCII characters, we can trea t the
83 // string as valid one. 83 // string as valid one.
84 string16::iterator firstChar = find_if(stringText.begin(), stringText.en d(), isASCIIAlpha); 84 base::string16::iterator firstChar = find_if(stringText.begin(), stringT ext.end(), isASCIIAlpha);
85 if (firstChar == stringText.end()) 85 if (firstChar == stringText.end())
86 return true; 86 return true;
87 int wordOffset = distance(stringText.begin(), firstChar); 87 int wordOffset = distance(stringText.begin(), firstChar);
88 int maxWordLength = static_cast<int>(stringText.length()) - wordOffset; 88 int maxWordLength = static_cast<int>(stringText.length()) - wordOffset;
89 int wordLength; 89 int wordLength;
90 string16 word; 90 base::string16 word;
91 91
92 // Look up our misspelled-word table to check if the extracted word is a 92 // Look up our misspelled-word table to check if the extracted word is a
93 // known misspelled word, and return the offset and the length of the 93 // known misspelled word, and return the offset and the length of the
94 // extracted word if this word is a known misspelled word. 94 // extracted word if this word is a known misspelled word.
95 // (See the comment in MockSpellCheck::initializeIfNeeded() why we use a 95 // (See the comment in MockSpellCheck::initializeIfNeeded() why we use a
96 // misspelled-word table.) 96 // misspelled-word table.)
97 for (size_t i = 0; i < m_misspelledWords.size(); ++i) { 97 for (size_t i = 0; i < m_misspelledWords.size(); ++i) {
98 wordLength = static_cast<int>(m_misspelledWords.at(i).length()) > ma xWordLength ? maxWordLength : static_cast<int>(m_misspelledWords.at(i).length()) ; 98 wordLength = static_cast<int>(m_misspelledWords.at(i).length()) > ma xWordLength ? maxWordLength : static_cast<int>(m_misspelledWords.at(i).length()) ;
99 word = stringText.substr(wordOffset, wordLength); 99 word = stringText.substr(wordOffset, wordLength);
100 if (word == m_misspelledWords.at(i) && (static_cast<int>(stringText. length()) == wordOffset + wordLength || isNotASCIIAlpha(stringText[wordOffset + wordLength]))) { 100 if (word == m_misspelledWords.at(i) && (static_cast<int>(stringText. length()) == wordOffset + wordLength || isNotASCIIAlpha(stringText[wordOffset + wordLength]))) {
101 *misspelledOffset = wordOffset + skippedLength; 101 *misspelledOffset = wordOffset + skippedLength;
102 *misspelledLength = wordLength; 102 *misspelledLength = wordLength;
103 break; 103 break;
104 } 104 }
105 } 105 }
106 106
107 if (*misspelledLength > 0) 107 if (*misspelledLength > 0)
108 break; 108 break;
109 109
110 string16::iterator lastChar = find_if(stringText.begin() + wordOffset, s tringText.end(), isNotASCIIAlpha); 110 base::string16::iterator lastChar = find_if(stringText.begin() + wordOff set, stringText.end(), isNotASCIIAlpha);
111 if (lastChar == stringText.end()) 111 if (lastChar == stringText.end())
112 wordLength = static_cast<int>(stringText.length()) - wordOffset; 112 wordLength = static_cast<int>(stringText.length()) - wordOffset;
113 else 113 else
114 wordLength = distance(firstChar, lastChar); 114 wordLength = distance(firstChar, lastChar);
115 115
116 BLINK_ASSERT(0 < wordOffset + wordLength); 116 BLINK_ASSERT(0 < wordOffset + wordLength);
117 stringText = stringText.substr(wordOffset + wordLength); 117 stringText = stringText.substr(wordOffset + wordLength);
118 skippedLength += wordOffset + wordLength; 118 skippedLength += wordOffset + wordLength;
119 } 119 }
120 120
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 // The following words are used by unit tests. 189 // The following words are used by unit tests.
190 "ifmmp", 190 "ifmmp",
191 "qwertyuiopasd", 191 "qwertyuiopasd",
192 "qwertyuiopasdf", 192 "qwertyuiopasdf",
193 "upper case", 193 "upper case",
194 "wellcome" 194 "wellcome"
195 }; 195 };
196 196
197 m_misspelledWords.clear(); 197 m_misspelledWords.clear();
198 for (size_t i = 0; i < arraysize(misspelledWords); ++i) 198 for (size_t i = 0; i < arraysize(misspelledWords); ++i)
199 m_misspelledWords.push_back(string16(misspelledWords[i], misspelledWords [i] + strlen(misspelledWords[i]))); 199 m_misspelledWords.push_back(base::string16(misspelledWords[i], misspelle dWords[i] + strlen(misspelledWords[i])));
200 200
201 // Mark as initialized to prevent this object from being initialized twice 201 // Mark as initialized to prevent this object from being initialized twice
202 // or more. 202 // or more.
203 m_initialized = true; 203 m_initialized = true;
204 204
205 // Since this MockSpellCheck class doesn't download dictionaries, this 205 // Since this MockSpellCheck class doesn't download dictionaries, this
206 // function always returns false. 206 // function always returns false.
207 return false; 207 return false;
208 } 208 }
209 209
210 } 210 }
OLDNEW
« no previous file with comments | « Source/testing/runner/MockSpellCheck.h ('k') | Source/testing/runner/SpellCheckClient.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698