xref: /aosp_15_r20/external/cronet/third_party/re2/src/util/strutil.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 
5 #include "util/strutil.h"
6 
7 namespace re2 {
8 
PrefixSuccessor(std::string * prefix)9 void PrefixSuccessor(std::string* prefix) {
10   // We can increment the last character in the string and be done
11   // unless that character is 255, in which case we have to erase the
12   // last character and increment the previous character, unless that
13   // is 255, etc. If the string is empty or consists entirely of
14   // 255's, we just return the empty string.
15   while (!prefix->empty()) {
16     char& c = prefix->back();
17     if (c == '\xff') {  // char literal avoids signed/unsigned.
18       prefix->pop_back();
19     } else {
20       ++c;
21       break;
22     }
23   }
24 }
25 
26 }  // namespace re2
27