OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 return -1; | 235 return -1; |
236 } | 236 } |
237 } | 237 } |
238 | 238 |
239 //--------------------------------------------------------------------- | 239 //--------------------------------------------------------------------- |
240 // Linear Search Strategy | 240 // Linear Search Strategy |
241 //--------------------------------------------------------------------- | 241 //--------------------------------------------------------------------- |
242 | 242 |
243 | 243 |
244 template <typename PatternChar, typename SubjectChar> | 244 template <typename PatternChar, typename SubjectChar> |
245 static inline bool CharCompare(const PatternChar* pattern, | 245 inline bool CharCompare(const PatternChar* pattern, |
246 const SubjectChar* subject, | 246 const SubjectChar* subject, |
247 int length) { | 247 int length) { |
248 ASSERT(length > 0); | 248 ASSERT(length > 0); |
249 int pos = 0; | 249 int pos = 0; |
250 do { | 250 do { |
251 if (pattern[pos] != subject[pos]) { | 251 if (pattern[pos] != subject[pos]) { |
252 return false; | 252 return false; |
253 } | 253 } |
254 pos++; | 254 pos++; |
255 } while (pos < length); | 255 } while (pos < length); |
256 return true; | 256 return true; |
257 } | 257 } |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 } | 548 } |
549 return -1; | 549 return -1; |
550 } | 550 } |
551 | 551 |
552 | 552 |
553 // Perform a a single stand-alone search. | 553 // Perform a a single stand-alone search. |
554 // If searching multiple times for the same pattern, a search | 554 // If searching multiple times for the same pattern, a search |
555 // object should be constructed once and the Search function then called | 555 // object should be constructed once and the Search function then called |
556 // for each search. | 556 // for each search. |
557 template <typename SubjectChar, typename PatternChar> | 557 template <typename SubjectChar, typename PatternChar> |
558 static int SearchString(Isolate* isolate, | 558 int SearchString(Isolate* isolate, |
559 Vector<const SubjectChar> subject, | 559 Vector<const SubjectChar> subject, |
560 Vector<const PatternChar> pattern, | 560 Vector<const PatternChar> pattern, |
561 int start_index) { | 561 int start_index) { |
562 StringSearch<PatternChar, SubjectChar> search(isolate, pattern); | 562 StringSearch<PatternChar, SubjectChar> search(isolate, pattern); |
563 return search.Search(subject, start_index); | 563 return search.Search(subject, start_index); |
564 } | 564 } |
565 | 565 |
566 }} // namespace v8::internal | 566 }} // namespace v8::internal |
567 | 567 |
568 #endif // V8_STRING_SEARCH_H_ | 568 #endif // V8_STRING_SEARCH_H_ |
OLD | NEW |