string_util.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. // Useful string functions and so forth. This is a grab-bag file.
  17. //
  18. // These functions work fine for UTF-8 strings as long as you can
  19. // consider them to be just byte strings. For example, due to the
  20. // design of UTF-8 you do not need to worry about accidental matches,
  21. // as long as all your inputs are valid UTF-8 (use \uHHHH, not \xHH or \oOOO).
  22. #ifndef IPHONE_FIRESTORE_PORT_STRING_UTIL_H_
  23. #define IPHONE_FIRESTORE_PORT_STRING_UTIL_H_
  24. #include <string>
  25. namespace leveldb {
  26. class Slice;
  27. }
  28. namespace Firestore {
  29. // Returns the smallest lexicographically larger string of equal or smaller
  30. // length. Returns an empty string if there is no such successor (if the input
  31. // is empty or consists entirely of 0xff bytes).
  32. // Useful for calculating the smallest lexicographically larger string
  33. // that will not be prefixed by the input string.
  34. //
  35. // Examples:
  36. // "a" -> "b", "aaa" -> "aab", "aa\xff" -> "ab", "\xff" -> "", "" -> ""
  37. std::string PrefixSuccessor(leveldb::Slice prefix);
  38. // Returns the immediate lexicographically-following string. This is useful to
  39. // turn an inclusive range into something that can be used with Bigtable's
  40. // SetLimitRow():
  41. //
  42. // // Inclusive range [min_element, max_element].
  43. // string min_element = ...;
  44. // string max_element = ...;
  45. //
  46. // // Equivalent range [range_start, range_end).
  47. // string range_start = min_element;
  48. // string range_end = ImmediateSuccessor(max_element);
  49. //
  50. // WARNING: Returns the input string with a '\0' appended; if you call c_str()
  51. // on the result, it will compare equal to s.
  52. //
  53. // WARNING: Transforms "" -> "\0"; this doesn't account for Bigtable's special
  54. // treatment of "" as infinity.
  55. std::string ImmediateSuccessor(leveldb::Slice s);
  56. } // namespace Firestore
  57. #endif // IPHONE_FIRESTORE_PORT_STRING_UTIL_H_