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

Unified Diff: chrome/common/string_index.h

Issue 8236002: Create StringOrdinal to allow placement of strings in sorted lists (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Changing StringIndex to a class Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/string_index.h
diff --git a/chrome/common/string_index.h b/chrome/common/string_index.h
new file mode 100644
index 0000000000000000000000000000000000000000..ddf66f5909131624aac5ff3efa64d1dbcb6bacf1
--- /dev/null
+++ b/chrome/common/string_index.h
@@ -0,0 +1,66 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_COMMON_STRING_INDEX_H_
+#define CHROME_COMMON_STRING_INDEX_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
akalin 2011/10/14 10:16:29 what is this for? if this is for size_t, #include
+
+class StringIndex {
akalin 2011/10/14 10:16:29 add comment explaining what the class is for
+ public:
+ // Create a valid StringIndex if the str matches [A-Z]*[B-Z],
akalin 2011/10/14 10:16:29 str -> string
+ // otherwise create an invalid StringIndex
akalin 2011/10/14 10:16:29 end with period
+ explicit StringIndex(const std::string& str);
+
+ // Create an invalid StringIndex
akalin 2011/10/14 10:16:29 end with period
+ StringIndex();
+
+ // Check to see if this matches [A-Z]*[B-Z]
akalin 2011/10/14 10:16:29 Returns true iff this was initialized with a strin
+ bool IsValid() const;
+
+ bool LessThan(const StringIndex& other) const;
akalin 2011/10/14 10:16:29 probably should include an Equals() mem-fn for con
akalin 2011/10/14 10:16:29 add comment
+
+ // LessThan(other) must hold. Returns a StringIndex x s.t. LessThan(x)
akalin 2011/10/14 10:16:29 clean up this comment (e.g., s.t. -> such that)
+ // holds, and x.LessThan(other) holds.
+ StringIndex CreateBetween(const StringIndex& other) const;
+
+ // Returns a StringIndex x s.t. x.LessThan(*this) holds.
akalin 2011/10/14 10:16:29 clean up
+ StringIndex CreateBefore() const;
+
+ // Returns a StringIndex x s.t. LessThan(x) holds.
akalin 2011/10/14 10:16:29 clean up
+ StringIndex CreateAfter() const;
+
+ std::string ToString() const;
akalin 2011/10/14 10:16:29 add a comment like copy constructor and default as
+
+ private:
+ // Return the digit value at position i, padding with kZeroDigit if required.
+ int GetPositionValue(size_t i) const;
+
+ // Create a StringIndex that is lexigraphically greater than start and
+ // lexigraphically less than end, ideally the StringIndex will be a
+ // middle value between the two StringIndexs.
+ static StringIndex CreateStringIndexBetween(const StringIndex& start,
akalin 2011/10/14 10:16:29 is there are a reason why these functions are expo
+ const StringIndex& end);
+
+ // Compute the midpoint string that is between start and end.
+ static std::string ComputeMidpoint(const StringIndex& start,
+ const StringIndex& end);
+
+ // Check if two strings have the same value.
+ static bool EqualValueIndexs(const std::string& rhs, const std::string& lhs);
+
+ // Add kMidDigitValue to the value at position index because
+ // the previous index values had an odd difference, so their correct
+ // middle value is x and a half, so the half is now inserted.
+ static void AddHalf(size_t position, std::string& value);
+
+ // Remove all trailing zeros from a value as they provide no value.
+ static std::string RemoveTrailingZeros(const std::string& value);
+
+ std::string string_index_;
akalin 2011/10/14 10:16:29 const
+};
+#endif // CHROME_COMMON_STRING_INDEX_H_

Powered by Google App Engine
This is Rietveld 408576698