diff options
author | Laszlo Csomor <laszlocsomor@google.com> | 2018-02-20 06:29:00 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-02-20 06:31:02 -0800 |
commit | 1585b90499b3219761172951d6a5c4e0b309459c (patch) | |
tree | 7c7fa6dffa1d531ae85cf84432f64754b6b5c3f3 /src | |
parent | 5deca4cf88f5568771f2c836a9b8c693b88bd749 (diff) |
Bazel client: remove dead code
Remove the static kAsciiPropertyBits data from
strings.cc and replace its only reference with
simpler code.
Change-Id: I95fb12b7d4bca4589ae64603b63019ee6e12bfc2
PiperOrigin-RevId: 186295165
Diffstat (limited to 'src')
-rw-r--r-- | src/main/cpp/util/strings.cc | 57 | ||||
-rw-r--r-- | src/main/cpp/util/strings.h | 21 |
2 files changed, 14 insertions, 64 deletions
diff --git a/src/main/cpp/util/strings.cc b/src/main/cpp/util/strings.cc index df4ae75bb6..8bac35a958 100644 --- a/src/main/cpp/util/strings.cc +++ b/src/main/cpp/util/strings.cc @@ -31,55 +31,9 @@ using std::wstring; static const char kSeparator[] = " \n\t\r"; -// # Table generated by this Python code (bit 0x02 is currently unused): -// def Hex2(n): -// return '0x' + hex(n/16)[2:] + hex(n%16)[2:] -// def IsPunct(ch): -// return (ord(ch) >= 32 and ord(ch) < 127 and -// not ch.isspace() and not ch.isalnum()) -// def IsBlank(ch): -// return ch in ' \t' -// def IsCntrl(ch): -// return ord(ch) < 32 or ord(ch) == 127 -// def IsXDigit(ch): -// return ch.isdigit() or ch.lower() in 'abcdef' -// for i in range(128): -// ch = chr(i) -// mask = ((ch.isalpha() and 0x01 or 0) | -// (ch.isalnum() and 0x04 or 0) | -// (ch.isspace() and 0x08 or 0) | -// (IsPunct(ch) and 0x10 or 0) | -// (IsBlank(ch) and 0x20 or 0) | -// (IsCntrl(ch) and 0x40 or 0) | -// (IsXDigit(ch) and 0x80 or 0)) -// print Hex2(mask) + ',', -// if i % 16 == 7: -// print ' //', Hex2(i & 0x78) -// elif i % 16 == 15: -// print -const unsigned char kAsciiPropertyBits[256] = { - 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, // 0x00 - 0x40, 0x68, 0x48, 0x48, 0x48, 0x48, 0x40, 0x40, - 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, // 0x10 - 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - 0x28, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, // 0x20 - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, - 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, // 0x30 - 0x84, 0x84, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x05, // 0x40 - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, // 0x50 - 0x05, 0x05, 0x05, 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x05, // 0x60 - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, // 0x70 - 0x05, 0x05, 0x05, 0x10, 0x10, 0x10, 0x10, 0x40, -}; - - bool starts_with(const string &haystack, const string &needle) { return (haystack.length() >= needle.length()) && - (memcmp(haystack.c_str(), needle.c_str(), needle.length()) == 0); + (memcmp(haystack.c_str(), needle.c_str(), needle.length()) == 0); } template <typename char_type> @@ -117,8 +71,8 @@ vector<string> Split(const string &contents, const char delimeter) { return result; } -void SplitStringUsing( - const string &contents, const char delimeter, vector<string> *result) { +void SplitStringUsing(const string &contents, const char delimeter, + vector<string> *result) { assert(result); size_t start = 0; @@ -214,7 +168,7 @@ void StripWhitespace(string *str) { } static void GetNextToken(const string &str, const char &comment, - string::const_iterator *iter, vector<string> *words) { + string::const_iterator *iter, vector<string> *words) { string output; auto last = *iter; char quote = '\0'; @@ -276,7 +230,6 @@ void Tokenize(const string &str, const char &comment, vector<string> *words) { } } - // Evaluate a format string and store the result in 'str'. void StringPrintf(string *str, const char *format, ...) { assert(str); @@ -328,7 +281,7 @@ string AsLower(const string &str) { template <typename U, typename V> static unique_ptr<V[]> UstringToVstring( const U *input, size_t (*convert)(V *output, const U *input, size_t len), - const char* fmtStringU) { + const char *fmtStringU) { size_t size = convert(nullptr, input, 0) + 1; if (size == (size_t)-1) { fprintf(stderr, "UstringToVstring: invalid input \""); diff --git a/src/main/cpp/util/strings.h b/src/main/cpp/util/strings.h index 45323e1704..943f6c6fd3 100644 --- a/src/main/cpp/util/strings.h +++ b/src/main/cpp/util/strings.h @@ -24,10 +24,15 @@ namespace blaze_util { -extern const unsigned char kAsciiPropertyBits[256]; -#define kApb kAsciiPropertyBits - -static inline bool ascii_isspace(unsigned char c) { return kApb[c] & 0x08; } +// Space characters according to Python: chr(i).isspace() +static inline bool ascii_isspace(unsigned char c) { + return c == 9 // TAB + || c == 10 // LF + || c == 11 // VT (vertical tab) + || c == 12 // FF (form feed) + || c == 13 // CR + || c == 32; // space +} bool starts_with(const std::string &haystack, const std::string &needle); @@ -62,14 +67,6 @@ inline CharStar var_strprefix(CharStar str, const char *prefix) { return strncmp(str, prefix, len) == 0 ? str + len : NULL; } -// Returns a mutable char* pointing to a string's internal buffer, which may not -// be null-terminated. Returns NULL for an empty string. If not non-null, -// writing through this pointer will modify the string. -inline char *string_as_array(std::string *str) { - // DO NOT USE const_cast<char*>(str->data())! See the unittest for why. - return str->empty() ? NULL : &*str->begin(); -} - // Join the elements of pieces separated by delimeter. Returns the joined // string in output. void JoinStrings(const std::vector<std::string> &pieces, const char delimeter, |