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

Side by Side Diff: third_party/WebKit/Source/wtf/text/TextPosition.h

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 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
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 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 #include "wtf/Vector.h" 30 #include "wtf/Vector.h"
31 #include "wtf/WTFExport.h" 31 #include "wtf/WTFExport.h"
32 #include "wtf/text/WTFString.h" 32 #include "wtf/text/WTFString.h"
33 33
34 namespace WTF { 34 namespace WTF {
35 35
36 // An abstract number of element in a sequence. The sequence has a first element . 36 // An abstract number of element in a sequence. The sequence has a first element .
37 // This type should be used instead of integer because 2 contradicting tradition s can 37 // This type should be used instead of integer because 2 contradicting tradition s can
38 // call a first element '0' or '1' which makes integer type ambiguous. 38 // call a first element '0' or '1' which makes integer type ambiguous.
39 class OrdinalNumber final { 39 class OrdinalNumber final {
40 DISALLOW_NEW(); 40 DISALLOW_NEW();
41 public:
42 static OrdinalNumber fromZeroBasedInt(int zeroBasedInt) { return OrdinalNumb er(zeroBasedInt); }
43 static OrdinalNumber fromOneBasedInt(int oneBasedInt) { return OrdinalNumber (oneBasedInt - 1); }
44 OrdinalNumber() : m_zeroBasedValue(0) { }
45 41
46 int zeroBasedInt() const { return m_zeroBasedValue; } 42 public:
47 int oneBasedInt() const { return m_zeroBasedValue + 1; } 43 static OrdinalNumber fromZeroBasedInt(int zeroBasedInt) {
44 return OrdinalNumber(zeroBasedInt);
45 }
46 static OrdinalNumber fromOneBasedInt(int oneBasedInt) {
47 return OrdinalNumber(oneBasedInt - 1);
48 }
49 OrdinalNumber() : m_zeroBasedValue(0) {}
48 50
49 bool operator==(OrdinalNumber other) const { return m_zeroBasedValue == othe r.m_zeroBasedValue; } 51 int zeroBasedInt() const { return m_zeroBasedValue; }
50 bool operator!=(OrdinalNumber other) const { return !((*this) == other); } 52 int oneBasedInt() const { return m_zeroBasedValue + 1; }
51 53
52 static OrdinalNumber first() { return OrdinalNumber(0); } 54 bool operator==(OrdinalNumber other) const {
53 static OrdinalNumber beforeFirst() { return OrdinalNumber(-1); } 55 return m_zeroBasedValue == other.m_zeroBasedValue;
56 }
57 bool operator!=(OrdinalNumber other) const { return !((*this) == other); }
54 58
55 private: 59 static OrdinalNumber first() { return OrdinalNumber(0); }
56 OrdinalNumber(int zeroBasedInt) : m_zeroBasedValue(zeroBasedInt) { } 60 static OrdinalNumber beforeFirst() { return OrdinalNumber(-1); }
57 int m_zeroBasedValue; 61
62 private:
63 OrdinalNumber(int zeroBasedInt) : m_zeroBasedValue(zeroBasedInt) {}
64 int m_zeroBasedValue;
58 }; 65 };
59 66
60
61 // TextPosition structure specifies coordinates within an text resource. It is u sed mostly 67 // TextPosition structure specifies coordinates within an text resource. It is u sed mostly
62 // for saving script source position. 68 // for saving script source position.
63 class TextPosition final { 69 class TextPosition final {
64 DISALLOW_NEW(); 70 DISALLOW_NEW();
65 public:
66 TextPosition(OrdinalNumber line, OrdinalNumber column)
67 : m_line(line)
68 , m_column(column)
69 {
70 }
71 TextPosition() { }
72 bool operator==(const TextPosition& other) const { return m_line == other.m_ line && m_column == other.m_column; }
73 bool operator!=(const TextPosition& other) const { return !((*this) == other ); }
74 WTF_EXPORT OrdinalNumber toOffset(const Vector<unsigned>&);
75 71
76 // A 'minimum' value of position, used as a default value. 72 public:
77 static TextPosition minimumPosition() { return TextPosition(OrdinalNumber::f irst(), OrdinalNumber::first()); } 73 TextPosition(OrdinalNumber line, OrdinalNumber column)
74 : m_line(line), m_column(column) {}
75 TextPosition() {}
76 bool operator==(const TextPosition& other) const {
77 return m_line == other.m_line && m_column == other.m_column;
78 }
79 bool operator!=(const TextPosition& other) const {
80 return !((*this) == other);
81 }
82 WTF_EXPORT OrdinalNumber toOffset(const Vector<unsigned>&);
78 83
79 // A value with line value less than a minimum; used as an impossible positi on. 84 // A 'minimum' value of position, used as a default value.
80 static TextPosition belowRangePosition() { return TextPosition(OrdinalNumber ::beforeFirst(), OrdinalNumber::beforeFirst()); } 85 static TextPosition minimumPosition() {
86 return TextPosition(OrdinalNumber::first(), OrdinalNumber::first());
87 }
81 88
82 // A value corresponding to a position with given offset within text having the specified line ending offsets. 89 // A value with line value less than a minimum; used as an impossible position .
83 WTF_EXPORT static TextPosition fromOffsetAndLineEndings(unsigned, const Vect or<unsigned>&); 90 static TextPosition belowRangePosition() {
91 return TextPosition(OrdinalNumber::beforeFirst(),
92 OrdinalNumber::beforeFirst());
93 }
84 94
85 OrdinalNumber m_line; 95 // A value corresponding to a position with given offset within text having th e specified line ending offsets.
86 OrdinalNumber m_column; 96 WTF_EXPORT static TextPosition fromOffsetAndLineEndings(
97 unsigned,
98 const Vector<unsigned>&);
99
100 OrdinalNumber m_line;
101 OrdinalNumber m_column;
87 }; 102 };
88 103
89 WTF_EXPORT PassOwnPtr<Vector<unsigned>> lineEndings(const String&); 104 WTF_EXPORT PassOwnPtr<Vector<unsigned>> lineEndings(const String&);
90 105
91 } // namespace WTF 106 } // namespace WTF
92 107
93 using WTF::OrdinalNumber; 108 using WTF::OrdinalNumber;
94 109
95 using WTF::TextPosition; 110 using WTF::TextPosition;
96 111
97 using WTF::lineEndings; 112 using WTF::lineEndings;
98 113
99 #endif // TextPosition_h 114 #endif // TextPosition_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/TextEncodingRegistry.cpp ('k') | third_party/WebKit/Source/wtf/text/TextPosition.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698