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

Unified Diff: third_party/re2/util/strutil.cc

Issue 1544433002: Replace RE2 import with a dependency (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re-Added LICENSE and OWNERS file Created 5 years 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
« no previous file with comments | « third_party/re2/util/stringprintf.cc ('k') | third_party/re2/util/test.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/re2/util/strutil.cc
diff --git a/third_party/re2/util/strutil.cc b/third_party/re2/util/strutil.cc
deleted file mode 100644
index d3a0249133df514ff107d9c8a539effa6f3230bf..0000000000000000000000000000000000000000
--- a/third_party/re2/util/strutil.cc
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright 1999-2005 The RE2 Authors. All Rights Reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-#include "util/util.h"
-#include "re2/stringpiece.h"
-
-namespace re2 {
-
-// ----------------------------------------------------------------------
-// CEscapeString()
-// Copies 'src' to 'dest', escaping dangerous characters using
-// C-style escape sequences. 'src' and 'dest' should not overlap.
-// Returns the number of bytes written to 'dest' (not including the \0)
-// or -1 if there was insufficient space.
-// ----------------------------------------------------------------------
-int CEscapeString(const char* src, int src_len, char* dest,
- int dest_len) {
- const char* src_end = src + src_len;
- int used = 0;
-
- for (; src < src_end; src++) {
- if (dest_len - used < 2) // space for two-character escape
- return -1;
-
- unsigned char c = *src;
- switch (c) {
- case '\n': dest[used++] = '\\'; dest[used++] = 'n'; break;
- case '\r': dest[used++] = '\\'; dest[used++] = 'r'; break;
- case '\t': dest[used++] = '\\'; dest[used++] = 't'; break;
- case '\"': dest[used++] = '\\'; dest[used++] = '\"'; break;
- case '\'': dest[used++] = '\\'; dest[used++] = '\''; break;
- case '\\': dest[used++] = '\\'; dest[used++] = '\\'; break;
- default:
- // Note that if we emit \xNN and the src character after that is a hex
- // digit then that digit must be escaped too to prevent it being
- // interpreted as part of the character code by C.
- if (c < ' ' || c > '~') {
- if (dest_len - used < 5) // space for four-character escape + \0
- return -1;
-#if !defined(_WIN32)
- snprintf(dest + used, 5, "\\%03o", c);
-#else
- // On Windows, the function takes 4+VA arguments, not 3+VA. With an
- // array, the buffer size will be inferred, but not with a pointer.
- snprintf(dest + used, 5, _TRUNCATE, "\\%03o", c);
-#endif
- used += 4;
- } else {
- dest[used++] = c; break;
- }
- }
- }
-
- if (dest_len - used < 1) // make sure that there is room for \0
- return -1;
-
- dest[used] = '\0'; // doesn't count towards return value though
- return used;
-}
-
-
-// ----------------------------------------------------------------------
-// CEscape()
-// Copies 'src' to result, escaping dangerous characters using
-// C-style escape sequences. 'src' and 'dest' should not overlap.
-// ----------------------------------------------------------------------
-string CEscape(const StringPiece& src) {
- const int dest_length = src.size() * 4 + 1; // Maximum possible expansion
- char* dest = new char[dest_length];
- const int len = CEscapeString(src.data(), src.size(),
- dest, dest_length);
- string s = string(dest, len);
- delete[] dest;
- return s;
-}
-
-string PrefixSuccessor(const StringPiece& prefix) {
- // We can increment the last character in the string and be done
- // unless that character is 255, in which case we have to erase the
- // last character and increment the previous character, unless that
- // is 255, etc. If the string is empty or consists entirely of
- // 255's, we just return the empty string.
- bool done = false;
- string limit(prefix.data(), prefix.size());
- int index = static_cast<int>(limit.size()) - 1;
- while (!done && index >= 0) {
- if ((limit[index]&255) == 255) {
- limit.erase(index);
- index--;
- } else {
- limit[index]++;
- done = true;
- }
- }
- if (!done) {
- return "";
- } else {
- return limit;
- }
-}
-
-} // namespace re2
« no previous file with comments | « third_party/re2/util/stringprintf.cc ('k') | third_party/re2/util/test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698