strutil.cc 791 B

1234567891011121314151617181920212223242526
  1. // Copyright 1999-2005 The RE2 Authors. All Rights Reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. #include "util/strutil.h"
  5. namespace re2 {
  6. void PrefixSuccessor(std::string* prefix) {
  7. // We can increment the last character in the string and be done
  8. // unless that character is 255, in which case we have to erase the
  9. // last character and increment the previous character, unless that
  10. // is 255, etc. If the string is empty or consists entirely of
  11. // 255's, we just return the empty string.
  12. while (!prefix->empty()) {
  13. char& c = prefix->back();
  14. if (c == '\xff') { // char literal avoids signed/unsigned.
  15. prefix->pop_back();
  16. } else {
  17. ++c;
  18. break;
  19. }
  20. }
  21. }
  22. } // namespace re2