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

Side by Side Diff: Source/wtf/text/TextPosition.cpp

Issue 23464095: WTF::notFound looks too much like a local variable. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « Source/wtf/text/StringImpl.cpp ('k') | Source/wtf/text/WTFString.h » ('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) 2013, Google Inc. All rights reserved. 2 * Copyright (C) 2013, 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 19 matching lines...) Expand all
30 30
31 namespace WTF { 31 namespace WTF {
32 32
33 PassOwnPtr<Vector<unsigned> > lineEndings(const String& text) 33 PassOwnPtr<Vector<unsigned> > lineEndings(const String& text)
34 { 34 {
35 OwnPtr<Vector<unsigned> > result(adoptPtr(new Vector<unsigned>())); 35 OwnPtr<Vector<unsigned> > result(adoptPtr(new Vector<unsigned>()));
36 36
37 unsigned start = 0; 37 unsigned start = 0;
38 while (start < text.length()) { 38 while (start < text.length()) {
39 size_t lineEnd = text.find('\n', start); 39 size_t lineEnd = text.find('\n', start);
40 if (lineEnd == notFound) 40 if (lineEnd == kNotFound)
41 break; 41 break;
42 42
43 result->append(static_cast<unsigned>(lineEnd)); 43 result->append(static_cast<unsigned>(lineEnd));
44 start = lineEnd + 1; 44 start = lineEnd + 1;
45 } 45 }
46 result->append(text.length()); 46 result->append(text.length());
47 47
48 return result.release(); 48 return result.release();
49 } 49 }
50 50
51 static inline unsigned valueExtractor(const unsigned* value) 51 static inline unsigned valueExtractor(const unsigned* value)
52 { 52 {
53 return *value; 53 return *value;
54 } 54 }
55 55
56 TextPosition TextPosition::fromOffsetAndLineEndings(unsigned offset, const Vecto r<unsigned>& lineEndings) 56 TextPosition TextPosition::fromOffsetAndLineEndings(unsigned offset, const Vecto r<unsigned>& lineEndings)
57 { 57 {
58 const unsigned* foundLineEnding = approximateBinarySearch<unsigned, unsigned >(lineEndings, lineEndings.size(), offset, valueExtractor); 58 const unsigned* foundLineEnding = approximateBinarySearch<unsigned, unsigned >(lineEndings, lineEndings.size(), offset, valueExtractor);
59 int lineIndex = foundLineEnding - &lineEndings.at(0); 59 int lineIndex = foundLineEnding - &lineEndings.at(0);
60 if (offset > *foundLineEnding) 60 if (offset > *foundLineEnding)
61 ++lineIndex; 61 ++lineIndex;
62 unsigned lineStartOffset = lineIndex > 0 ? lineEndings.at(lineIndex - 1) + 1 : 0; 62 unsigned lineStartOffset = lineIndex > 0 ? lineEndings.at(lineIndex - 1) + 1 : 0;
63 int column = offset - lineStartOffset; 63 int column = offset - lineStartOffset;
64 return TextPosition(OrdinalNumber::fromZeroBasedInt(lineIndex), OrdinalNumbe r::fromZeroBasedInt(column)); 64 return TextPosition(OrdinalNumber::fromZeroBasedInt(lineIndex), OrdinalNumbe r::fromZeroBasedInt(column));
65 } 65 }
66 66
67 } // namespace WTF 67 } // namespace WTF
OLDNEW
« no previous file with comments | « Source/wtf/text/StringImpl.cpp ('k') | Source/wtf/text/WTFString.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698