http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/stl_util.h ---------------------------------------------------------------------- diff --git a/be/src/gutil/stl_util.h b/be/src/gutil/stl_util.h index 57007b1..60cb587 100644 --- a/be/src/gutil/stl_util.h +++ b/be/src/gutil/stl_util.h @@ -1,16 +1,21 @@ // Copyright 2002 Google Inc. // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. // // --- // @@ -47,10 +52,9 @@ using std::string; #include <vector> using std::vector; -#include "gutil/integral_types.h" -#include "gutil/macros.h" -#include "gutil/port.h" -#include "gutil/algorithm.h" +#include "kudu/gutil/integral_types.h" +#include "kudu/gutil/macros.h" +#include "kudu/gutil/port.h" // Sort and remove duplicates of an STL vector or deque. template<class T> @@ -575,8 +579,8 @@ void STLSetDifference(const SortedSTLContainerA &a, const SortedSTLContainerB &b, SortedSTLContainerC *c) { // The qualified name avoids an ambiguity error, particularly with C++11: - assert(util::gtl::is_sorted(a.begin(), a.end())); - assert(util::gtl::is_sorted(b.begin(), b.end())); + assert(std::is_sorted(a.begin(), a.end())); + assert(std::is_sorted(b.begin(), b.end())); assert(static_cast<const void *>(&a) != static_cast<const void *>(c)); assert(static_cast<const void *>(&b) != @@ -599,8 +603,8 @@ template<typename SortedSTLContainerA, void STLSetUnion(const SortedSTLContainerA &a, const SortedSTLContainerB &b, SortedSTLContainerC *c) { - assert(util::gtl::is_sorted(a.begin(), a.end())); - assert(util::gtl::is_sorted(b.begin(), b.end())); + assert(std::is_sorted(a.begin(), a.end())); + assert(std::is_sorted(b.begin(), b.end())); assert(static_cast<const void *>(&a) != static_cast<const void *>(c)); assert(static_cast<const void *>(&b) != @@ -615,8 +619,8 @@ template<typename SortedSTLContainerA, void STLSetSymmetricDifference(const SortedSTLContainerA &a, const SortedSTLContainerB &b, SortedSTLContainerC *c) { - assert(util::gtl::is_sorted(a.begin(), a.end())); - assert(util::gtl::is_sorted(b.begin(), b.end())); + assert(std::is_sorted(a.begin(), a.end())); + assert(std::is_sorted(b.begin(), b.end())); assert(static_cast<const void *>(&a) != static_cast<const void *>(c)); assert(static_cast<const void *>(&b) != @@ -647,8 +651,8 @@ template<typename SortedSTLContainerA, void STLSetIntersection(const SortedSTLContainerA &a, const SortedSTLContainerB &b, SortedSTLContainerC *c) { - assert(util::gtl::is_sorted(a.begin(), a.end())); - assert(util::gtl::is_sorted(b.begin(), b.end())); + assert(std::is_sorted(a.begin(), a.end())); + assert(std::is_sorted(b.begin(), b.end())); assert(static_cast<const void *>(&a) != static_cast<const void *>(c)); assert(static_cast<const void *>(&b) != @@ -671,8 +675,8 @@ template<typename SortedSTLContainerA, typename SortedSTLContainerB> bool STLIncludes(const SortedSTLContainerA &a, const SortedSTLContainerB &b) { - assert(util::gtl::is_sorted(a.begin(), a.end())); - assert(util::gtl::is_sorted(b.begin(), b.end())); + assert(std::is_sorted(a.begin(), a.end())); + assert(std::is_sorted(b.begin(), b.end())); return std::includes(a.begin(), a.end(), b.begin(), b.end()); } @@ -909,8 +913,8 @@ struct STLEmptyBaseHandle : public Base { template<typename InputIterator1, typename InputIterator2> bool SortedRangesHaveIntersection(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2) { - assert(util::gtl::is_sorted(begin1, end1)); - assert(util::gtl::is_sorted(begin2, end2)); + assert(std::is_sorted(begin1, end1)); + assert(std::is_sorted(begin2, end2)); while (begin1 != end1 && begin2 != end2) { if (*begin1 < *begin2) { ++begin1; @@ -929,8 +933,8 @@ template<typename InputIterator1, typename InputIterator2, typename Comp> bool SortedRangesHaveIntersection(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, Comp comparator) { - assert(util::gtl::is_sorted(begin1, end1, comparator)); - assert(util::gtl::is_sorted(begin2, end2, comparator)); + assert(std::is_sorted(begin1, end1, comparator)); + assert(std::is_sorted(begin2, end2, comparator)); while (begin1 != end1 && begin2 != end2) { if (comparator(*begin1, *begin2)) { ++begin1;
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/stringprintf.cc ---------------------------------------------------------------------- diff --git a/be/src/gutil/stringprintf.cc b/be/src/gutil/stringprintf.cc index dd7b4cf..112605c 100644 --- a/be/src/gutil/stringprintf.cc +++ b/be/src/gutil/stringprintf.cc @@ -1,6 +1,6 @@ // Copyright 2002 and onwards Google Inc. -#include "gutil/stringprintf.h" +#include "kudu/gutil/stringprintf.h" #include <errno.h> #include <stdarg.h> // For va_list and related operations @@ -8,8 +8,8 @@ #include <vector> using std::vector; #include <glog/logging.h> -#include "gutil/logging-inl.h" -#include "gutil/macros.h" +#include "kudu/gutil/logging-inl.h" +#include "kudu/gutil/macros.h" #ifdef _MSC_VER enum { IS__MSC_VER = 1 }; @@ -41,7 +41,7 @@ void StringAppendV(string* dst, const char* format, va_list ap) { // Error or MSVC running out of space. MSVC 8.0 and higher // can be asked about space needed with the special idiom below: va_copy(backup_ap, ap); - result = vsnprintf(NULL, 0, format, backup_ap); + result = vsnprintf(nullptr, 0, format, backup_ap); va_end(backup_ap); } @@ -54,7 +54,7 @@ void StringAppendV(string* dst, const char* format, va_list ap) { // Increase the buffer size to the size requested by vsnprintf, // plus one for the closing \0. int length = result+1; - char* buf = new char[length]; + auto buf = new char[length]; // Restore the va_list before we use it again va_copy(backup_ap, ap); http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/stringprintf.h ---------------------------------------------------------------------- diff --git a/be/src/gutil/stringprintf.h b/be/src/gutil/stringprintf.h index e486e72..2083574 100644 --- a/be/src/gutil/stringprintf.h +++ b/be/src/gutil/stringprintf.h @@ -16,7 +16,7 @@ using std::string; #include <vector> using std::vector; -#include "gutil/port.h" +#include "kudu/gutil/port.h" // Return a C++ string extern string StringPrintf(const char* format, ...) http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/ascii_ctype.cc ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/ascii_ctype.cc b/be/src/gutil/strings/ascii_ctype.cc index 44608f8..50ea8c2 100644 --- a/be/src/gutil/strings/ascii_ctype.cc +++ b/be/src/gutil/strings/ascii_ctype.cc @@ -4,7 +4,7 @@ // The C++ style guide requires 80-column lines. // cpplint.py requires 2-space indentation. -#include "gutil/strings/ascii_ctype.h" +#include "kudu/gutil/strings/ascii_ctype.h" // # Table generated by this Python code (bit 0x02 is currently unused): // def Hex2(n): http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/charset.cc ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/charset.cc b/be/src/gutil/strings/charset.cc index 7725b0f..2e9d5b1 100644 --- a/be/src/gutil/strings/charset.cc +++ b/be/src/gutil/strings/charset.cc @@ -1,6 +1,6 @@ // Copyright 2008 Google Inc. All Rights Reserved. -#include "gutil/strings/charset.h" +#include "kudu/gutil/strings/charset.h" #include <string.h> http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/charset.h ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/charset.h b/be/src/gutil/strings/charset.h index b6b7013..a2dbca4 100644 --- a/be/src/gutil/strings/charset.h +++ b/be/src/gutil/strings/charset.h @@ -3,7 +3,7 @@ #ifndef STRINGS_CHARSET_H_ #define STRINGS_CHARSET_H_ -#include "gutil/integral_types.h" +#include "kudu/gutil/integral_types.h" namespace strings { http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/escaping.cc ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/escaping.cc b/be/src/gutil/strings/escaping.cc index 8eb4114..cf49359 100644 --- a/be/src/gutil/strings/escaping.cc +++ b/be/src/gutil/strings/escaping.cc @@ -1,7 +1,7 @@ // Copyright 2008 Google Inc. All Rights Reserved. // Authors: Numerous. See the .h for contact people. -#include "gutil/strings/escaping.h" +#include "kudu/gutil/strings/escaping.h" #include <assert.h> #include <stdio.h> @@ -12,13 +12,13 @@ using std::numeric_limits; #include <vector> using std::vector; -#include "gutil/integral_types.h" -#include "gutil/port.h" -#include "gutil/gscoped_ptr.h" -#include "gutil/strings/join.h" -#include "gutil/utf/utf.h" // for runetochar -#include "gutil/charmap.h" -#include "gutil/stl_util.h" +#include "kudu/gutil/integral_types.h" +#include "kudu/gutil/port.h" +#include "kudu/gutil/gscoped_ptr.h" +#include "kudu/gutil/strings/join.h" +#include "kudu/gutil/utf/utf.h" // for runetochar +#include "kudu/gutil/charmap.h" +#include "kudu/gutil/stl_util.h" namespace strings { @@ -75,7 +75,7 @@ int EscapeStrForCSV(const char* src, char* dest, int dest_len) { #define IS_OCTAL_DIGIT(c) (((c) >= '0') && ((c) <= '7')) int UnescapeCEscapeSequences(const char* source, char* dest) { - return UnescapeCEscapeSequences(source, dest, NULL); + return UnescapeCEscapeSequences(source, dest, nullptr); } int UnescapeCEscapeSequences(const char* source, char* dest, @@ -215,7 +215,7 @@ int UnescapeCEscapeSequences(const char* source, char* dest, // // ---------------------------------------------------------------------- int UnescapeCEscapeString(const string& src, string* dest) { - return UnescapeCEscapeString(src, dest, NULL); + return UnescapeCEscapeString(src, dest, nullptr); } int UnescapeCEscapeString(const string& src, string* dest, @@ -230,7 +230,7 @@ int UnescapeCEscapeString(const string& src, string* dest, string UnescapeCEscapeString(const string& src) { gscoped_array<char> unescaped(new char[src.size() + 1]); - int len = UnescapeCEscapeSequences(src.c_str(), unescaped.get(), NULL); + int len = UnescapeCEscapeSequences(src.c_str(), unescaped.get(), nullptr); return string(unescaped.get(), len); } @@ -1648,8 +1648,7 @@ void EscapeFileName(const StringPiece& src, string* dst) { // Reserve at least src.size() chars dst->reserve(dst->size() + src.size()); - for (int i = 0; i < src.size(); ++i) { - const char c = src[i]; + for (char c : src) { // We do not use "isalpha" because we want the behavior to be // independent of the current locale settings. if (escape_file_name_exceptions.contains(c)) { @@ -1751,10 +1750,10 @@ static void b2a_hex_t(const unsigned char* b, T a, int num) { string b2a_bin(const string& b, bool byte_order_msb) { string result; - for (int byte_offset = 0; byte_offset < b.size(); ++byte_offset) { + for (char c : b) { for (int bit_offset = 0; bit_offset < 8; ++bit_offset) { int x = (byte_order_msb) ? 7-bit_offset : bit_offset; - result.append(1, (b[byte_offset] & (1 << x)) ? '1' : '0'); + result.append(1, (c & (1 << x)) ? '1' : '0'); } } return result; @@ -1814,15 +1813,15 @@ string ShellEscape(StringPiece src) { } else { // needs double quote escaping string result = "\""; - for (size_t i = 0; i < src.size(); ++i) { - switch (src[i]) { + for (char c : src) { + switch (c) { case '\\': case '$': case '"': case '`': result.push_back('\\'); }; - result.push_back(src[i]); + result.push_back(c); } result.push_back('"'); return result; http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/escaping.h ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/escaping.h b/be/src/gutil/strings/escaping.h index 5435d6d..19e0860 100644 --- a/be/src/gutil/strings/escaping.h +++ b/be/src/gutil/strings/escaping.h @@ -28,10 +28,11 @@ using std::string; using std::vector; #include <glog/logging.h> -#include "gutil/logging-inl.h" -#include "gutil/strings/ascii_ctype.h" -#include "gutil/strings/charset.h" -#include "gutil/strings/stringpiece.h" + +#include "kudu/gutil/logging-inl.h" +#include "kudu/gutil/strings/ascii_ctype.h" +#include "kudu/gutil/strings/charset.h" +#include "kudu/gutil/strings/stringpiece.h" namespace strings { http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/fastmem.h ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/fastmem.h b/be/src/gutil/strings/fastmem.h index ec84071..3beca6d 100644 --- a/be/src/gutil/strings/fastmem.h +++ b/be/src/gutil/strings/fastmem.h @@ -22,8 +22,8 @@ #include <stdio.h> #include <string.h> -#include "gutil/integral_types.h" -#include "gutil/port.h" +#include "kudu/gutil/integral_types.h" +#include "kudu/gutil/port.h" namespace strings { http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/human_readable.cc ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/human_readable.cc b/be/src/gutil/strings/human_readable.cc index 2820039..fb3419a 100644 --- a/be/src/gutil/strings/human_readable.cc +++ b/be/src/gutil/strings/human_readable.cc @@ -1,15 +1,15 @@ // Copyright 2007 Google Inc. All Rights Reserved. -#include "gutil/strings/human_readable.h" +#include "kudu/gutil/strings/human_readable.h" #include <stddef.h> #include <stdlib.h> #include <string.h> #include <glog/logging.h> -#include "gutil/logging-inl.h" -#include "gutil/stringprintf.h" -#include "gutil/strings/strip.h" +#include "kudu/gutil/logging-inl.h" +#include "kudu/gutil/stringprintf.h" +#include "kudu/gutil/strings/strip.h" namespace { @@ -122,7 +122,7 @@ string HumanReadableNumBytes::ToString(int64 num_bytes) { // Special case for bytes. if (num_bytes < GG_LONGLONG(1024)) { // No fractions for bytes. - return StringPrintf("%s%" GG_LL_FORMAT "dB", neg_str, num_bytes); + return StringPrintf("%s%" PRId64 "B", neg_str, num_bytes); } static const char units[] = "KMGTPE"; // int64 only goes up to E. @@ -163,7 +163,7 @@ string HumanReadableNumBytes::ToStringWithoutRounding(int64 num_bytes) { num_units = next_units; } - return StringPrintf("%s%lld%c", neg_str, num_units, units[unit_type]); + return StringPrintf("%s%" PRId64 "%c", neg_str, num_units, units[unit_type]); } string HumanReadableInt::ToString(int64 value) { @@ -173,7 +173,7 @@ string HumanReadableInt::ToString(int64 value) { value = -value; } if (value < GG_LONGLONG(1000)) { - StringAppendF(&s, "%" GG_LL_FORMAT "d", value); + StringAppendF(&s, "%" PRId64, value); } else if (value >= GG_LONGLONG(1000000000000000)) { // Number bigger than 1E15; use that notation. StringAppendF(&s, "%0.3G", static_cast<double>(value)); @@ -281,7 +281,11 @@ string HumanReadableElapsedTime::ToShortString(double seconds) { seconds = -seconds; } - // Start with us and keep going up to years. + // Start with ns and keep going up to years. + if (seconds < 0.000001) { + StringAppendF(&human_readable, "%0.3g ns", seconds * 1000000000.0); + return human_readable; + } if (seconds < 0.001) { StringAppendF(&human_readable, "%0.3g us", seconds * 1000000.0); return human_readable; @@ -329,6 +333,7 @@ bool HumanReadableElapsedTime::ToDouble(const string& str, double* value) { // will match; static const TimeUnits kUnits[] = { // Long forms + { "nanosecond", 0.000000001 }, { "microsecond", 0.000001 }, { "millisecond", 0.001 }, { "second", 1.0 }, @@ -340,6 +345,7 @@ bool HumanReadableElapsedTime::ToDouble(const string& str, double* value) { { "year", 365 * 86400.0 }, // Abbreviated forms + { "nanosec", 0.000000001 }, { "microsec", 0.000001 }, { "millisec", 0.001 }, { "sec", 1.0 }, @@ -350,6 +356,9 @@ bool HumanReadableElapsedTime::ToDouble(const string& str, double* value) { { "mon", 30 * 86400.0 }, { "yr", 365 * 86400.0 }, + // nano -> n + { "nsecond", 0.000000001 }, + { "nsec", 0.000000001 }, // micro -> u { "usecond", 0.000001 }, { "usec", 0.000001 }, @@ -358,6 +367,7 @@ bool HumanReadableElapsedTime::ToDouble(const string& str, double* value) { { "msec", 0.001 }, // Ultra-short form + { "ns", 0.000000001 }, { "us", 0.000001 }, { "ms", 0.001 }, { "s", 1.0 }, http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/human_readable.h ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/human_readable.h b/be/src/gutil/strings/human_readable.h index 8a05907..e05b169 100644 --- a/be/src/gutil/strings/human_readable.h +++ b/be/src/gutil/strings/human_readable.h @@ -12,9 +12,9 @@ using std::less; #include <string> using std::string; -#include "gutil/basictypes.h" -#include "gutil/integral_types.h" -#include "gutil/macros.h" +#include "kudu/gutil/basictypes.h" +#include "kudu/gutil/integral_types.h" +#include "kudu/gutil/macros.h" // WARNING // HumanReadable{NumBytes, Int} don't give you the standard set of SI prefixes. http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/join.cc ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/join.cc b/be/src/gutil/strings/join.cc index f3caa49..c0035e1 100644 --- a/be/src/gutil/strings/join.cc +++ b/be/src/gutil/strings/join.cc @@ -1,12 +1,12 @@ // Copyright 2008 and onwards Google Inc. All rights reserved. -#include "gutil/strings/join.h" +#include "kudu/gutil/strings/join.h" #include <glog/logging.h> -#include "gutil/logging-inl.h" -#include "gutil/gscoped_ptr.h" -#include "gutil/strings/ascii_ctype.h" -#include "gutil/strings/escaping.h" +#include "kudu/gutil/logging-inl.h" +#include "kudu/gutil/gscoped_ptr.h" +#include "kudu/gutil/strings/ascii_ctype.h" +#include "kudu/gutil/strings/escaping.h" // ---------------------------------------------------------------------- // JoinUsing() @@ -30,7 +30,7 @@ char* JoinUsing(const vector<const char*>& components, for (int i = 0; i < num_components; ++i) num_chars += strlen(components[i]); - char* res_buffer = new char[num_chars+1]; + auto res_buffer = new char[num_chars + 1]; return JoinUsingToBuffer(components, delim, num_chars+1, res_buffer, result_length_p); } @@ -50,7 +50,7 @@ char* JoinUsingToBuffer(const vector<const char*>& components, int result_buffer_size, char* result_buffer, int* result_length_p) { - CHECK(result_buffer != NULL); + CHECK(result_buffer != nullptr); const int num_components = components.size(); const int max_str_len = result_buffer_size - 1; char* curr_dest = result_buffer; @@ -76,7 +76,7 @@ char* JoinUsingToBuffer(const vector<const char*>& components, if (result_buffer_size > 0) *curr_dest = '\0'; // add null termination - if (result_length_p != NULL) // set string length value + if (result_length_p != nullptr) // set string length value *result_length_p = num_chars; return result_buffer; @@ -95,7 +95,7 @@ void JoinStringsInArray(string const* const* components, int num_components, const char* delim, string * result) { - CHECK(result != NULL); + CHECK(result != nullptr); result->clear(); for (int i = 0; i < num_components; i++) { if (i>0) { @@ -172,17 +172,17 @@ void JoinCSVLineWithDelimiter(const vector<string>& cols, char delimiter, // whitespace (ie ascii_isspace() returns true), escape all double-quotes and // bracket the string in double quotes. string.rbegin() evaluates to the last // character of the string. - for (int i = 0; i < cols.size(); ++i) { - if ((cols[i].find_first_of(escape_chars) != string::npos) || - (!cols[i].empty() && (ascii_isspace(*cols[i].begin()) || - ascii_isspace(*cols[i].rbegin())))) { + for (const auto& col : cols) { + if ((col.find_first_of(escape_chars) != string::npos) || + (!col.empty() && (ascii_isspace(*col.begin()) || + ascii_isspace(*col.rbegin())))) { // Double the original size, for escaping, plus two bytes for // the bracketing double-quotes, and one byte for the closing \0. - int size = 2 * cols[i].size() + 3; + int size = 2 * col.size() + 3; gscoped_array<char> buf(new char[size]); // Leave space at beginning and end for bracketing double-quotes. - int escaped_size = strings::EscapeStrForCSV(cols[i].c_str(), + int escaped_size = strings::EscapeStrForCSV(col.c_str(), buf.get() + 1, size - 2); CHECK_GE(escaped_size, 0) << "Buffer somehow wasn't large enough."; CHECK_GE(size, escaped_size + 3) @@ -194,7 +194,7 @@ void JoinCSVLineWithDelimiter(const vector<string>& cols, char delimiter, *((buf.get() + 1) + escaped_size + 1) = '\0'; quoted_cols.push_back(string(buf.get(), buf.get() + escaped_size + 2)); } else { - quoted_cols.push_back(cols[i]); + quoted_cols.push_back(col); } } JoinStrings(quoted_cols, delimiter_str, output); http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/join.h ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/join.h b/be/src/gutil/strings/join.h index bf946c4..4369c4c 100644 --- a/be/src/gutil/strings/join.h +++ b/be/src/gutil/strings/join.h @@ -32,13 +32,13 @@ using std::pair; #include <vector> using std::vector; -#include "gutil/integral_types.h" -#include "gutil/macros.h" -#include "gutil/template_util.h" -#include "gutil/strings/numbers.h" -#include "gutil/strings/strcat.h" // For backward compatibility. -#include "gutil/strings/stringpiece.h" -#include "gutil/hash/hash.h" +#include "kudu/gutil/integral_types.h" +#include "kudu/gutil/macros.h" +#include "kudu/gutil/template_util.h" +#include "kudu/gutil/strings/numbers.h" +#include "kudu/gutil/strings/strcat.h" // For backward compatibility. +#include "kudu/gutil/strings/stringpiece.h" +#include "kudu/gutil/hash/hash.h" // ---------------------------------------------------------------------- // JoinUsing() @@ -115,6 +115,32 @@ string JoinStringsIterator(const ITERATOR& start, const ITERATOR& end, const StringPiece& delim); +// Join the keys of a map using the specified delimiter. +template<typename ITERATOR> +void JoinKeysIterator(const ITERATOR& start, + const ITERATOR& end, + const StringPiece& delim, + string *result) { + result->clear(); + for (ITERATOR iter = start; iter != end; ++iter) { + if (iter == start) { + StrAppend(result, iter->first); + } else { + StrAppend(result, delim, iter->first); + } + } +} + +template <typename ITERATOR> +string JoinKeysIterator(const ITERATOR& start, + const ITERATOR& end, + const StringPiece& delim) { + string result; + JoinKeysIterator(start, end, delim, &result); + return result; +} + +// Join the keys and values of a map using the specified delimiters. template<typename ITERATOR> void JoinKeysAndValuesIterator(const ITERATOR& start, const ITERATOR& end, @@ -174,6 +200,24 @@ inline string JoinStrings(const CONTAINER& components, return result; } +// Join the strings produced by calling 'functor' on each element of +// 'components'. +template<class CONTAINER, typename FUNC> +string JoinMapped(const CONTAINER& components, + const FUNC& functor, + const StringPiece& delim) { + string result; + for (typename CONTAINER::const_iterator iter = components.begin(); + iter != components.end(); + iter++) { + if (iter != components.begin()) { + result.append(delim.data(), delim.size()); + } + result.append(functor(*iter)); + } + return result; +} + template <class ITERATOR> void JoinStringsIterator(const ITERATOR& start, const ITERATOR& end, http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/memutil.cc ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/memutil.cc b/be/src/gutil/strings/memutil.cc index 30e2153..390d2a0 100644 --- a/be/src/gutil/strings/memutil.cc +++ b/be/src/gutil/strings/memutil.cc @@ -2,11 +2,11 @@ // Copyright (C) 2001 and onwards Google, Inc. // -#include "gutil/strings/memutil.h" +#include "kudu/gutil/strings/memutil.h" #include <stdlib.h> // for malloc, NULL -#include "gutil/strings/ascii_ctype.h" // for ascii_tolower +#include "kudu/gutil/strings/ascii_ctype.h" // for ascii_tolower int memcasecmp(const char *s1, const char *s2, size_t len) { const unsigned char *us1 = reinterpret_cast<const unsigned char *>(s1); @@ -23,8 +23,8 @@ int memcasecmp(const char *s1, const char *s2, size_t len) { char *memdup(const char *s, size_t slen) { void *copy; - if ( (copy=malloc(slen)) == NULL ) - return NULL; + if ( (copy=malloc(slen)) == nullptr ) + return nullptr; memcpy(copy, s, slen); return reinterpret_cast<char *>(copy); } @@ -34,7 +34,7 @@ char *memrchr(const char *s, int c, size_t slen) { if (*e == c) return const_cast<char *>(e); } - return NULL; + return nullptr; } size_t memspn(const char *s, size_t slen, const char *accept) { @@ -74,7 +74,7 @@ char *mempbrk(const char *s, size_t slen, const char *accept) { if (sc == *s) return const_cast<char *>(s); } - return NULL; + return nullptr; } template<bool case_sensitive> @@ -104,7 +104,7 @@ const char *int_memmatch(const char *phaystack, size_t haylen, needle = needlestart; } } - return NULL; + return nullptr; } // explicit template instantiations @@ -121,7 +121,7 @@ const char *memmatch(const char *phaystack, size_t haylen, return phaystack; // even if haylen is 0 } if (haylen < neelen) - return NULL; + return nullptr; const char* match; const char* hayend = phaystack + haylen - neelen + 1; @@ -134,5 +134,5 @@ const char *memmatch(const char *phaystack, size_t haylen, else phaystack = match + 1; } - return NULL; + return nullptr; } http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/memutil.h ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/memutil.h b/be/src/gutil/strings/memutil.h index b230149..9335735 100644 --- a/be/src/gutil/strings/memutil.h +++ b/be/src/gutil/strings/memutil.h @@ -56,7 +56,7 @@ #include <stddef.h> #include <string.h> // to get the POSIX mem*() routines -#include "gutil/port.h" // disable some warnings on Windows +#include "kudu/gutil/port.h" // disable some warnings on Windows inline char *memcat(char *dest, size_t destlen, const char *src, size_t srclen) { http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/numbers.cc ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/numbers.cc b/be/src/gutil/strings/numbers.cc index 5568318..7bdb57c 100644 --- a/be/src/gutil/strings/numbers.cc +++ b/be/src/gutil/strings/numbers.cc @@ -4,7 +4,7 @@ // This file contains string processing functions related to // numeric values. -#include "gutil/strings/numbers.h" +#include "kudu/gutil/strings/numbers.h" #include <assert.h> #include <ctype.h> @@ -19,14 +19,14 @@ using std::numeric_limits; #include <string> using std::string; -#include "gutil/int128.h" -#include "gutil/integral_types.h" +#include "kudu/gutil/int128.h" +#include "kudu/gutil/integral_types.h" #include <glog/logging.h> -#include "gutil/logging-inl.h" -#include "gutil/gscoped_ptr.h" -#include "gutil/stringprintf.h" -#include "gutil/strtoint.h" -#include "gutil/strings/ascii_ctype.h" +#include "kudu/gutil/logging-inl.h" +#include "kudu/gutil/gscoped_ptr.h" +#include "kudu/gutil/stringprintf.h" +#include "kudu/gutil/strtoint.h" +#include "kudu/gutil/strings/ascii_ctype.h" // Reads a <double> in *text, which may not be whitespace-initiated. // *len is the length, or -1 if text is '\0'-terminated, which is more @@ -46,7 +46,7 @@ static inline bool EatADouble(const char** text, int* len, bool allow_question, const char* pos = *text; int rem = *len; // remaining length, or -1 if null-terminated - if (pos == NULL || rem == 0) + if (pos == nullptr || rem == 0) return false; if (allow_question && (*pos == '?')) { @@ -138,7 +138,7 @@ bool ParseDoubleRange(const char* text, int len, const char** end, *from = -HUGE_VAL; *to = HUGE_VAL; } - if (opts.allow_currency && (is_currency != NULL)) + if (opts.allow_currency && (is_currency != nullptr)) *is_currency = false; assert(len >= -1); @@ -155,10 +155,10 @@ bool ParseDoubleRange(const char* text, int len, const char** end, double* dest = (comparator == '>') ? from : to; EatAChar(&text, &len, "=", true, false); if (opts.allow_currency && EatAChar(&text, &len, "$", true, false)) - if (is_currency != NULL) + if (is_currency != nullptr) *is_currency = true; - if (!EatADouble(&text, &len, opts.allow_unbounded_markers, dest, NULL, - NULL)) + if (!EatADouble(&text, &len, opts.allow_unbounded_markers, dest, nullptr, + nullptr)) return false; *end = text; return EatAChar(&text, &len, opts.acceptable_terminators, false, @@ -179,9 +179,9 @@ bool ParseDoubleRange(const char* text, int len, const char** end, bool final_period = false; bool* check_initial_minus = (strchr(opts.separators, '-') && !seen_dollar && (opts.num_required_bounds < 2)) ? - (&initial_minus_sign) : NULL; + (&initial_minus_sign) : nullptr; bool* check_final_period = strchr(opts.separators, '.') ? (&final_period) - : NULL; + : nullptr; bool double_seen = EatADouble(&text, &len, opts.allow_unbounded_markers, from, check_initial_minus, check_final_period); @@ -235,7 +235,7 @@ bool ParseDoubleRange(const char* text, int len, const char** end, || (opts.allow_currency && !double_seen)) && EatAChar(&text, &len, "$", true, false); bool second_double_seen = EatADouble( - &text, &len, opts.allow_unbounded_markers, to, NULL, NULL); + &text, &len, opts.allow_unbounded_markers, to, nullptr, nullptr); if (opts.num_required_bounds > double_seen + second_double_seen) return false; if (second_dollar_seen && !second_double_seen) { @@ -247,7 +247,7 @@ bool ParseDoubleRange(const char* text, int len, const char** end, seen_dollar = seen_dollar || second_dollar_seen; } - if (seen_dollar && (is_currency != NULL)) + if (seen_dollar && (is_currency != nullptr)) *is_currency = true; // We're done. But we have to check that the next char is a proper // terminator. @@ -293,7 +293,7 @@ void ConsumeStrayLeadingZeroes(string *const str) { // -------------------------------------------------------------------- int32 ParseLeadingInt32Value(const char *str, int32 deflt) { - char *error = NULL; + char *error = nullptr; long value = strtol(str, &error, 0); // Limit long values to int32 min/max. Needed for lp64; no-op on 32 bits. if (value > numeric_limits<int32>::max()) { @@ -307,7 +307,7 @@ int32 ParseLeadingInt32Value(const char *str, int32 deflt) { uint32 ParseLeadingUInt32Value(const char *str, uint32 deflt) { if (numeric_limits<unsigned long>::max() == numeric_limits<uint32>::max()) { // When long is 32 bits, we can use strtoul. - char *error = NULL; + char *error = nullptr; const uint32 value = strtoul(str, &error, 0); return (error == str) ? deflt : value; } else { @@ -316,7 +316,7 @@ uint32 ParseLeadingUInt32Value(const char *str, uint32 deflt) { // it would be impossible to differentiate "-2" (that should wrap // around to the value UINT_MAX-1) from a string with ULONG_MAX-1 // (that should be pegged to UINT_MAX due to overflow). - char *error = NULL; + char *error = nullptr; int64 value = strto64(str, &error, 0); if (value > numeric_limits<uint32>::max() || value < -static_cast<int64>(numeric_limits<uint32>::max())) { @@ -337,7 +337,7 @@ uint32 ParseLeadingUInt32Value(const char *str, uint32 deflt) { // -------------------------------------------------------------------- int32 ParseLeadingDec32Value(const char *str, int32 deflt) { - char *error = NULL; + char *error = nullptr; long value = strtol(str, &error, 10); // Limit long values to int32 min/max. Needed for lp64; no-op on 32 bits. if (value > numeric_limits<int32>::max()) { @@ -351,7 +351,7 @@ int32 ParseLeadingDec32Value(const char *str, int32 deflt) { uint32 ParseLeadingUDec32Value(const char *str, uint32 deflt) { if (numeric_limits<unsigned long>::max() == numeric_limits<uint32>::max()) { // When long is 32 bits, we can use strtoul. - char *error = NULL; + char *error = nullptr; const uint32 value = strtoul(str, &error, 10); return (error == str) ? deflt : value; } else { @@ -360,7 +360,7 @@ uint32 ParseLeadingUDec32Value(const char *str, uint32 deflt) { // it would be impossible to differentiate "-2" (that should wrap // around to the value UINT_MAX-1) from a string with ULONG_MAX-1 // (that should be pegged to UINT_MAX due to overflow). - char *error = NULL; + char *error = nullptr; int64 value = strto64(str, &error, 10); if (value > numeric_limits<uint32>::max() || value < -static_cast<int64>(numeric_limits<uint32>::max())) { @@ -380,19 +380,19 @@ uint32 ParseLeadingUDec32Value(const char *str, uint32 deflt) { // UInt64 and Int64 cannot handle decimal numbers with leading 0s. // -------------------------------------------------------------------- uint64 ParseLeadingUInt64Value(const char *str, uint64 deflt) { - char *error = NULL; + char *error = nullptr; const uint64 value = strtou64(str, &error, 0); return (error == str) ? deflt : value; } int64 ParseLeadingInt64Value(const char *str, int64 deflt) { - char *error = NULL; + char *error = nullptr; const int64 value = strto64(str, &error, 0); return (error == str) ? deflt : value; } uint64 ParseLeadingHex64Value(const char *str, uint64 deflt) { - char *error = NULL; + char *error = nullptr; const uint64 value = strtou64(str, &error, 16); return (error == str) ? deflt : value; } @@ -407,13 +407,13 @@ uint64 ParseLeadingHex64Value(const char *str, uint64 deflt) { // -------------------------------------------------------------------- int64 ParseLeadingDec64Value(const char *str, int64 deflt) { - char *error = NULL; + char *error = nullptr; const int64 value = strto64(str, &error, 10); return (error == str) ? deflt : value; } uint64 ParseLeadingUDec64Value(const char *str, uint64 deflt) { - char *error = NULL; + char *error = nullptr; const uint64 value = strtou64(str, &error, 10); return (error == str) ? deflt : value; } @@ -425,7 +425,7 @@ uint64 ParseLeadingUDec64Value(const char *str, uint64 deflt) { // -------------------------------------------------------------------- double ParseLeadingDoubleValue(const char *str, double deflt) { - char *error = NULL; + char *error = nullptr; errno = 0; const double value = strtod(str, &error); if (errno != 0 || // overflow/underflow happened @@ -494,16 +494,16 @@ bool ParseLeadingBoolValue(const char *str, bool deflt) { string FpToString(Fprint fp) { char buf[17]; - snprintf(buf, sizeof(buf), "%016llx", fp); + snprintf(buf, sizeof(buf), "%016" PRIx64, fp); return string(buf); } // Default arguments string Uint128ToHexString(uint128 ui128) { char buf[33]; - snprintf(buf, sizeof(buf), "%016" GG_LL_FORMAT "x", + snprintf(buf, sizeof(buf), "%016" PRIx64, Uint128High64(ui128)); - snprintf(buf + 16, sizeof(buf) - 16, "%016" GG_LL_FORMAT "x", + snprintf(buf + 16, sizeof(buf) - 16, "%016" PRIx64, Uint128Low64(ui128)); return string(buf); } @@ -866,10 +866,6 @@ char *FastInt64ToBuffer(int64 i, char* buffer) { return buffer; } -// Offset into buffer where FastInt32ToBuffer places the end of string -// null character. Also used by FastInt32ToBufferLeft -static const int kFastInt32ToBufferOffset = 11; - char *FastInt32ToBuffer(int32 i, char* buffer) { FastInt32ToBufferLeft(i, buffer); return buffer; @@ -912,13 +908,6 @@ char *FastHex32ToBuffer(uint32 value, char* buffer) { // division and modulo operations. extern const char two_ASCII_digits[100][2]; // from strutil.cc -static inline void PutTwoDigits(int i, char* p) { - DCHECK_GE(i, 0); - DCHECK_LT(i, 100); - p[0] = two_ASCII_digits[i][0]; - p[1] = two_ASCII_digits[i][1]; -} - // ---------------------------------------------------------------------- // FastInt32ToBufferLeft() // FastUInt32ToBufferLeft() @@ -936,8 +925,8 @@ static inline void PutTwoDigits(int i, char* p) { // ---------------------------------------------------------------------- char* FastUInt32ToBufferLeft(uint32 u, char* buffer) { - int digits; - const char *ASCII_digits = NULL; + uint digits; + const char *ASCII_digits = nullptr; // The idea of this implementation is to trim the number of divides to as few // as possible by using multiplication and subtraction rather than mod (%), // and by outputting two digits at a time rather than one. @@ -1030,8 +1019,8 @@ char* FastInt32ToBufferLeft(int32 i, char* buffer) { } char* FastUInt64ToBufferLeft(uint64 u64, char* buffer) { - int digits; - const char *ASCII_digits = NULL; + uint digits; + const char *ASCII_digits = nullptr; uint32 u = static_cast<uint32>(u64); if (u == u64) return FastUInt32ToBufferLeft(u, buffer); @@ -1259,7 +1248,7 @@ char* DoubleToBuffer(double value, char* buffer) { // larger than the precision we asked for. DCHECK(snprintf_result > 0 && snprintf_result < kDoubleToBufferSize); - if (strtod(buffer, NULL) != value) { + if (strtod(buffer, nullptr) != value) { snprintf_result = snprintf(buffer, kDoubleToBufferSize, "%.*g", DBL_DIG+2, value); @@ -1448,7 +1437,7 @@ string ItoaKMGT(int64 i) { val = i; } - return StringPrintf("%s%" GG_LL_FORMAT "d%s", sign, val, suffix); + return StringPrintf("%s%" PRId64 "%s", sign, val, suffix); } // DEPRECATED(wadetregaskis). http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/numbers.h ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/numbers.h b/be/src/gutil/strings/numbers.h index f5ad338..e9f5c1a 100644 --- a/be/src/gutil/strings/numbers.h +++ b/be/src/gutil/strings/numbers.h @@ -20,11 +20,11 @@ using std::string; #include <vector> using std::vector; -#include "gutil/int128.h" -#include "gutil/integral_types.h" -#include "gutil/macros.h" -#include "gutil/port.h" -#include "gutil/stringprintf.h" +#include "kudu/gutil/int128.h" +#include "kudu/gutil/integral_types.h" +#include "kudu/gutil/macros.h" +#include "kudu/gutil/port.h" +#include "kudu/gutil/stringprintf.h" // START DOXYGEN NumbersFunctions grouping @@ -393,22 +393,6 @@ inline string SimpleItoa(uint64 i) { return string(buf, FastUInt64ToBufferLeft(i, buf)); } -inline string SimpleItoa(long i) { // NOLINT long is OK here - if (sizeof(i) == 64 / 8) { - return SimpleItoa(static_cast<int64>(i)); - } else if (sizeof(i) == 32 / 8) { - return SimpleItoa(static_cast<int32>(i)); - } -} - -inline string SimpleItoa(unsigned long i) { // NOLINT long is OK here - if (sizeof(i) == 64 / 8) { - return SimpleItoa(static_cast<uint64>(i)); - } else if (sizeof(i) == 32 / 8) { - return SimpleItoa(static_cast<uint32>(i)); - } -} - // SimpleAtoi converts a string to an integer. // Uses safe_strto?() for actual parsing, so strict checking is // applied, which is to say, the string must be a base-10 integer, optionally @@ -484,15 +468,6 @@ string SimpleItoaWithCommas(int32 i); string SimpleItoaWithCommas(uint32 i); string SimpleItoaWithCommas(int64 i); string SimpleItoaWithCommas(uint64 i); -#ifdef _LP64 -inline string SimpleItoaWithCommas(size_t i) { - return SimpleItoaWithCommas(static_cast<uint64>(i)); -} - -inline string SimpleItoaWithCommas(ptrdiff_t i) { - return SimpleItoaWithCommas(static_cast<int64>(i)); -} -#endif // ---------------------------------------------------------------------- // ItoaKMGT() @@ -589,12 +564,12 @@ inline string IntToString(int i) { // DEPRECATED(wadetregaskis). Just call StringPrintf. inline string Int64ToString(int64 i64) { - return StringPrintf("%7" GG_LL_FORMAT "d", i64); + return StringPrintf("%7" PRId64, i64); } // DEPRECATED(wadetregaskis). Just call StringPrintf. inline string UInt64ToString(uint64 ui64) { - return StringPrintf("%7" GG_LL_FORMAT "u", ui64); + return StringPrintf("%7" PRIu64, ui64); } #endif // STRINGS_NUMBERS_H_ http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/serialize.cc ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/serialize.cc b/be/src/gutil/strings/serialize.cc index 59ef25e..5449ef7 100644 --- a/be/src/gutil/strings/serialize.cc +++ b/be/src/gutil/strings/serialize.cc @@ -1,6 +1,6 @@ // Copyright 2003, Google Inc. All rights reserved. -#include "gutil/strings/serialize.h" +#include "kudu/gutil/strings/serialize.h" #include <stddef.h> #include <stdlib.h> @@ -15,13 +15,13 @@ using std::pair; #include <vector> using std::vector; -#include "gutil/casts.h" -#include "gutil/integral_types.h" -#include "gutil/stringprintf.h" -#include "gutil/strtoint.h" -#include "gutil/strings/join.h" -#include "gutil/strings/split.h" -#include "gutil/hash/hash.h" +#include "kudu/gutil/casts.h" +#include "kudu/gutil/integral_types.h" +#include "kudu/gutil/stringprintf.h" +#include "kudu/gutil/strtoint.h" +#include "kudu/gutil/strings/join.h" +#include "kudu/gutil/strings/split.h" +#include "kudu/gutil/hash/hash.h" // Convert a uint32 to a 4-byte string. string Uint32ToKey(uint32 u32) { @@ -223,9 +223,8 @@ int64 ReverseOrderedStringToInt64(const StringPiece& key) { string DictionaryInt32Encode(const hash_map<string, int32>* dictionary) { vector<string> entries; - for (hash_map<string, int32>::const_iterator iter = dictionary->begin(); - iter != dictionary->end(); ++iter) { - entries.push_back(StringPrintf("%s:%d", iter->first.c_str(), iter->second)); + for (const auto& entry : *dictionary) { + entries.push_back(StringPrintf("%s:%d", entry.first.c_str(), entry.second)); } string result; @@ -235,10 +234,9 @@ string DictionaryInt32Encode(const hash_map<string, int32>* dictionary) { string DictionaryInt64Encode(const hash_map<string, int64>* dictionary) { vector<string> entries; - for (hash_map<string, int64>::const_iterator iter = dictionary->begin(); - iter != dictionary->end(); ++iter) { - entries.push_back(StringPrintf("%s:%" GG_LL_FORMAT "d", - iter->first.c_str(), iter->second)); + for (const auto& entry : *dictionary) { + entries.push_back(StringPrintf("%s:%" PRId64, + entry.first.c_str(), entry.second)); } string result; @@ -248,9 +246,8 @@ string DictionaryInt64Encode(const hash_map<string, int64>* dictionary) { string DictionaryDoubleEncode(const hash_map<string, double>* dictionary) { vector<string> entries; - for (hash_map<string, double>::const_iterator iter = dictionary->begin(); - iter != dictionary->end(); ++iter) { - entries.push_back(StringPrintf("%s:%g", iter->first.c_str(), iter->second)); + for (const auto& entry : *dictionary) { + entries.push_back(StringPrintf("%s:%g", entry.first.c_str(), entry.second)); } string result; @@ -259,12 +256,12 @@ string DictionaryDoubleEncode(const hash_map<string, double>* dictionary) { } bool DictionaryParse(const string& encoded_str, - vector<pair<string, string> >* items) { + vector<pair<string, string> >* items) { vector<string> entries; SplitStringUsing(encoded_str, ",", &entries); - for (int i = 0; i < entries.size(); ++i) { + for (const auto& entry : entries) { vector<string> fields; - SplitStringAllowEmpty(entries[i], ":", &fields); + SplitStringAllowEmpty(entry, ":", &fields); if (fields.size() != 2) // parsing error return false; items->push_back(make_pair(fields[0], fields[1])); @@ -279,14 +276,14 @@ bool DictionaryInt32Decode(hash_map<string, int32>* dictionary, return false; dictionary->clear(); - for (int i = 0; i < items.size(); ++i) { - char *error = NULL; - const int32 value = strto32(items[i].second.c_str(), &error, 0); - if (error == items[i].second.c_str() || *error != '\0') { + for (const auto& item : items) { + char *error = nullptr; + const int32 value = strto32(item.second.c_str(), &error, 0); + if (error == item.second.c_str() || *error != '\0') { // parsing error return false; } - (*dictionary)[items[i].first] = value; + (*dictionary)[item.first] = value; } return true; } @@ -298,14 +295,14 @@ bool DictionaryInt64Decode(hash_map<string, int64>* dictionary, return false; dictionary->clear(); - for (int i = 0; i < items.size(); ++i) { - char *error = NULL; - const int64 value = strto64(items[i].second.c_str(), &error, 0); - if (error == items[i].second.c_str() || *error != '\0') { + for (const auto& item : items) { + char *error = nullptr; + const int64 value = strto64(item.second.c_str(), &error, 0); + if (error == item.second.c_str() || *error != '\0') { // parsing error return false; } - (*dictionary)[items[i].first] = value; + (*dictionary)[item.first] = value; } return true; } @@ -318,14 +315,14 @@ bool DictionaryDoubleDecode(hash_map<string, double>* dictionary, return false; dictionary->clear(); - for (int i = 0; i < items.size(); ++i) { - char *error = NULL; - const double value = strtod(items[i].second.c_str(), &error); - if (error == items[i].second.c_str() || *error != '\0') { + for (const auto& item : items) { + char *error = nullptr; + const double value = strtod(item.second.c_str(), &error); + if (error == item.second.c_str() || *error != '\0') { // parsing error return false; } - (*dictionary)[items[i].first] = value; + (*dictionary)[item.first] = value; } return true; } http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/serialize.h ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/serialize.h b/be/src/gutil/strings/serialize.h index 1bbda05..7966cd2 100644 --- a/be/src/gutil/strings/serialize.h +++ b/be/src/gutil/strings/serialize.h @@ -19,14 +19,15 @@ using std::pair; #include <vector> using std::vector; -#include "gutil/int128.h" -#include "gutil/integral_types.h" #include <glog/logging.h> -#include "gutil/logging-inl.h" -#include "gutil/type_traits.h" -#include "gutil/strings/stringpiece.h" -#include "gutil/endian.h" -#include "gutil/stl_util.h" + +#include "kudu/gutil/int128.h" +#include "kudu/gutil/integral_types.h" +#include "kudu/gutil/logging-inl.h" +#include "kudu/gutil/type_traits.h" +#include "kudu/gutil/strings/stringpiece.h" +#include "kudu/gutil/endian.h" +#include "kudu/gutil/stl_util.h" // Converts a 4-byte uint32 to a string such that the string keys sort in // the same order as the original uint32 value. http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/split.cc ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/split.cc b/be/src/gutil/strings/split.cc index c0404c2..a42faa7 100644 --- a/be/src/gutil/strings/split.cc +++ b/be/src/gutil/strings/split.cc @@ -2,7 +2,7 @@ // // Maintainer: Greg Miller <[email protected]> -#include "gutil/strings/split.h" +#include "kudu/gutil/strings/split.h" #include <assert.h> #include <stdlib.h> @@ -13,14 +13,14 @@ using std::iterator_traits; #include <limits> using std::numeric_limits; -#include "gutil/integral_types.h" +#include "kudu/gutil/integral_types.h" #include <glog/logging.h> -#include "gutil/logging-inl.h" -#include "gutil/macros.h" -#include "gutil/strtoint.h" -#include "gutil/strings/ascii_ctype.h" -#include "gutil/strings/util.h" -#include "gutil/hash/hash.h" +#include "kudu/gutil/logging-inl.h" +#include "kudu/gutil/macros.h" +#include "kudu/gutil/strtoint.h" +#include "kudu/gutil/strings/ascii_ctype.h" +#include "kudu/gutil/strings/util.h" +#include "kudu/gutil/hash/hash.h" // Implementations for some of the Split2 API. Much of the Split2 API is // templated so it exists in header files, either strings/split.h or @@ -133,8 +133,8 @@ void AppendToImpl(vector<string>* container, Splitter splitter) { vector<StringPiece> vsp = splitter; // Calls implicit conversion operator. size_t container_size = container->size(); container->resize(container_size + vsp.size()); - for (size_t i = 0; i < vsp.size(); ++i) { - vsp[i].CopyToString(&(*container)[container_size++]); + for (const auto& sp : vsp) { + sp.CopyToString(&(*container)[container_size++]); } } @@ -464,7 +464,7 @@ void SplitStringPieceToVector(const StringPiece& full, // ---------------------------------------------------------------------- vector<char*>* SplitUsing(char* full, const char* delim) { - vector<char*>* vec = new vector<char*>; + auto vec = new vector<char*>; SplitToVector(full, delim, vec, true); // Omit empty strings return vec; } @@ -472,12 +472,12 @@ vector<char*>* SplitUsing(char* full, const char* delim) { void SplitToVector(char* full, const char* delim, vector<char*>* vec, bool omit_empty_strings) { char* next = full; - while ((next = gstrsep(&full, delim)) != NULL) { + while ((next = gstrsep(&full, delim)) != nullptr) { if (omit_empty_strings && next[0] == '\0') continue; vec->push_back(next); } // Add last element (or full string if no delimeter found): - if (full != NULL) { + if (full != nullptr) { vec->push_back(full); } } @@ -485,12 +485,12 @@ void SplitToVector(char* full, const char* delim, vector<char*>* vec, void SplitToVector(char* full, const char* delim, vector<const char*>* vec, bool omit_empty_strings) { char* next = full; - while ((next = gstrsep(&full, delim)) != NULL) { + while ((next = gstrsep(&full, delim)) != nullptr) { if (omit_empty_strings && next[0] == '\0') continue; vec->push_back(next); } // Add last element (or full string if no delimeter found): - if (full != NULL) { + if (full != nullptr) { vec->push_back(full); } } @@ -691,7 +691,7 @@ DEFINE_SPLIT_ONE_NUMBER_TOKEN(HexUint64, uint64, strtou64_16) bool SplitRange(const char* rangestr, int* from, int* to) { // We need to do the const-cast because strol takes a char**, not const char** char* val = const_cast<char*>(rangestr); - if (val == NULL || EOS(*val)) return true; // we'll say nothingness is ok + if (val == nullptr || EOS(*val)) return true; // we'll say nothingness is ok if ( val[0] == '-' && EOS(val[1]) ) // CASE 1: - return true; // nothing changes @@ -871,7 +871,7 @@ char* SplitStructuredLineInternal(char* line, if (!expected_to_close.empty()) { return current; // Missing closing symbol(s) } - return NULL; // Success + return nullptr; // Success } bool SplitStructuredLineInternal(StringPiece line, @@ -1004,10 +1004,10 @@ bool SplitStringIntoKeyValuePairs(const string& line, SplitStringUsing(line, key_value_pair_delimiters.c_str(), &pairs); bool success = true; - for (size_t i = 0; i < pairs.size(); ++i) { + for (const auto& pair : pairs) { string key; vector<string> value; - if (!SplitStringIntoKeyValues(pairs[i], + if (!SplitStringIntoKeyValues(pair, key_value_delimiters, "", &key, &value)) { // Don't return here, to allow for keys without associated @@ -1033,7 +1033,7 @@ bool SplitStringIntoKeyValuePairs(const string& line, // -------------------------------------------------------------------- const char* SplitLeadingDec32Values(const char *str, vector<int32> *result) { for (;;) { - char *end = NULL; + char *end = nullptr; long value = strtol(str, &end, 10); if (end == str) break; @@ -1053,7 +1053,7 @@ const char* SplitLeadingDec32Values(const char *str, vector<int32> *result) { const char* SplitLeadingDec64Values(const char *str, vector<int64> *result) { for (;;) { - char *end = NULL; + char *end = nullptr; const int64 value = strtoll(str, &end, 10); if (end == str) break; http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/split.h ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/split.h b/be/src/gutil/strings/split.h index 869d121..c487689 100644 --- a/be/src/gutil/strings/split.h +++ b/be/src/gutil/strings/split.h @@ -51,13 +51,14 @@ using std::pair; #include <vector> using std::vector; -#include "gutil/integral_types.h" #include <glog/logging.h> -#include "gutil/logging-inl.h" -#include "gutil/strings/charset.h" -#include "gutil/strings/split_internal.h" -#include "gutil/strings/stringpiece.h" -#include "gutil/strings/strip.h" + +#include "kudu/gutil/integral_types.h" +#include "kudu/gutil/logging-inl.h" +#include "kudu/gutil/strings/charset.h" +#include "kudu/gutil/strings/split_internal.h" +#include "kudu/gutil/strings/stringpiece.h" +#include "kudu/gutil/strings/strip.h" namespace strings { @@ -400,7 +401,7 @@ template <typename Delimiter> class LimitImpl { public: LimitImpl(Delimiter delimiter, int limit) - : delimiter_(delimiter), limit_(limit), count_(0) {} + : delimiter_(std::move(delimiter)), limit_(limit), count_(0) {} StringPiece Find(StringPiece text) { if (count_++ == limit_) { return StringPiece(text.end(), 0); // No more matches. @@ -853,11 +854,11 @@ bool SplitRange(const char* rangestr, int* from, int* to); // The following variants of SplitCSVLine() are not recommended for new code. // Please consider the CSV parser in //util/csv as an alternative. Examples: // To parse a single line: -// #include "util/csv/parser.h" +// #include "kudu/util/csv/parser.h" // vector<string> fields = util::csv::ParseLine(line).fields(); // // To parse an entire file: -// #include "util/csv/parser.h" +// #include "kudu/util/csv/parser.h" // for (Record rec : Parser(source)) { // vector<string> fields = rec.fields(); // } @@ -1155,9 +1156,9 @@ bool SplitStringAndParseToInserter( vector<StringPiece> pieces = strings::Split(source, strings::delimiter::AnyOf(delim), strings::SkipEmpty()); - for (size_t i = 0; i < pieces.size(); ++i) { + for (const auto& piece : pieces) { typename Container::value_type t; - if (parse(pieces[i].as_string(), &t)) { + if (parse(piece.as_string(), &t)) { insert_policy(result, t); } else { retval = false; http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/split_internal.h ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/split_internal.h b/be/src/gutil/strings/split_internal.h index e50ddc8..01b3fac 100644 --- a/be/src/gutil/strings/split_internal.h +++ b/be/src/gutil/strings/split_internal.h @@ -26,8 +26,8 @@ using std::multimap; #include <vector> using std::vector; -#include "gutil/port.h" // for LANG_CXX11 -#include "gutil/strings/stringpiece.h" +#include "kudu/gutil/port.h" // for LANG_CXX11 +#include "kudu/gutil/strings/stringpiece.h" #ifdef LANG_CXX11 // This must be included after "base/port.h", which defines LANG_CXX11. @@ -72,16 +72,22 @@ class SplitIterator public: // Two constructors for "end" iterators. explicit SplitIterator(Delimiter d) - : delimiter_(d), predicate_(), is_end_(true) {} + : delimiter_(std::move(d)), predicate_(), is_end_(true) {} SplitIterator(Delimiter d, Predicate p) - : delimiter_(d), predicate_(p), is_end_(true) {} + : delimiter_(std::move(d)), predicate_(std::move(p)), is_end_(true) {} // Two constructors taking the text to iterator. SplitIterator(StringPiece text, Delimiter d) - : text_(text), delimiter_(d), predicate_(), is_end_(false) { + : text_(std::move(text)), + delimiter_(std::move(d)), + predicate_(), + is_end_(false) { ++(*this); } SplitIterator(StringPiece text, Delimiter d, Predicate p) - : text_(text), delimiter_(d), predicate_(p), is_end_(false) { + : text_(std::move(text)), + delimiter_(std::move(d)), + predicate_(std::move(p)), + is_end_(false) { ++(*this); } @@ -323,8 +329,8 @@ class Splitter { Container c; ReserveCapacity(&c, v.size()); std::insert_iterator<Container> inserter(c, c.begin()); - for (size_t i = 0; i < v.size(); ++i) { - *inserter++ = converter(v[i]); + for (const auto& sp : v) { + *inserter++ = converter(sp); } return c; } http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/strcat.cc ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/strcat.cc b/be/src/gutil/strings/strcat.cc index 70d389e..93f8114 100644 --- a/be/src/gutil/strings/strcat.cc +++ b/be/src/gutil/strings/strcat.cc @@ -1,6 +1,6 @@ // Copyright 2008 and onwards Google Inc. All rights reserved. -#include "gutil/strings/strcat.h" +#include "kudu/gutil/strings/strcat.h" #include <stdarg.h> #include <stdint.h> @@ -8,11 +8,11 @@ #include <string.h> #include <glog/logging.h> -#include "gutil/logging-inl.h" -#include "gutil/gscoped_ptr.h" -#include "gutil/strings/ascii_ctype.h" -#include "gutil/strings/escaping.h" -#include "gutil/stl_util.h" +#include "kudu/gutil/logging-inl.h" +#include "kudu/gutil/gscoped_ptr.h" +#include "kudu/gutil/strings/ascii_ctype.h" +#include "kudu/gutil/strings/escaping.h" +#include "kudu/gutil/stl_util.h" AlphaNum gEmptyAlphaNum(""); http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/strcat.h ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/strcat.h b/be/src/gutil/strings/strcat.h index 72ac462..40b888b 100644 --- a/be/src/gutil/strings/strcat.h +++ b/be/src/gutil/strings/strcat.h @@ -10,9 +10,9 @@ #include <string> using std::string; -#include "gutil/integral_types.h" -#include "gutil/strings/numbers.h" -#include "gutil/strings/stringpiece.h" +#include "kudu/gutil/integral_types.h" +#include "kudu/gutil/strings/numbers.h" +#include "kudu/gutil/strings/stringpiece.h" // The AlphaNum type was designed to be used as the parameter type for StrCat(). // I suppose that any routine accepting either a string or a number could accept @@ -51,16 +51,9 @@ struct AlphaNum { AlphaNum(uint64 u64) // NOLINT(runtime/explicit) : piece(digits, FastUInt64ToBufferLeft(u64, digits) - &digits[0]) {} -#ifdef _LP64 - AlphaNum(long x) // NOLINT(runtime/explicit) - : piece(digits, FastInt64ToBufferLeft(x, digits) - &digits[0]) {} - AlphaNum(unsigned long x) // NOLINT(runtime/explicit) - : piece(digits, FastUInt64ToBufferLeft(x, digits) - &digits[0]) {} -#else - AlphaNum(long x) // NOLINT(runtime/explicit) - : piece(digits, FastInt32ToBufferLeft(x, digits) - &digits[0]) {} - AlphaNum(unsigned long x) // NOLINT(runtime/explicit) - : piece(digits, FastUInt32ToBufferLeft(x, digits) - &digits[0]) {} +#if defined(__APPLE__) + AlphaNum(size_t size) // NOLINT(runtime/explicit) + : piece(digits, FastUInt64ToBufferLeft(size, digits) - &digits[0]) {} #endif AlphaNum(float f) // NOLINT(runtime/explicit) @@ -69,7 +62,8 @@ struct AlphaNum { : piece(digits, strlen(DoubleToBuffer(f, digits))) {} AlphaNum(const char *c_str) : piece(c_str) {} // NOLINT(runtime/explicit) - AlphaNum(const StringPiece &pc) : piece(pc) {} // NOLINT(runtime/explicit) + AlphaNum(StringPiece pc) + : piece(std::move(pc)) {} // NOLINT(runtime/explicit) AlphaNum(const string &s) : piece(s) {} // NOLINT(runtime/explicit) StringPiece::size_type size() const { return piece.size(); } http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/string_util-test.cc ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/string_util-test.cc b/be/src/gutil/strings/string_util-test.cc new file mode 100644 index 0000000..8849ca2 --- /dev/null +++ b/be/src/gutil/strings/string_util-test.cc @@ -0,0 +1,58 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// +// Some portions Copyright 2013 The Chromium Authors. All rights reserved. +#include "kudu/gutil/strings/util.h" + +#include <gtest/gtest.h> + +namespace kudu { + +TEST(StringUtilTest, MatchPatternTest) { + EXPECT_TRUE(MatchPattern("www.google.com", "*.com")); + EXPECT_TRUE(MatchPattern("www.google.com", "*")); + EXPECT_FALSE(MatchPattern("www.google.com", "www*.g*.org")); + EXPECT_TRUE(MatchPattern("Hello", "H?l?o")); + EXPECT_FALSE(MatchPattern("www.google.com", "http://*)")); + EXPECT_FALSE(MatchPattern("www.msn.com", "*.COM")); + EXPECT_TRUE(MatchPattern("Hello*1234", "He??o\\*1*")); + EXPECT_FALSE(MatchPattern("", "*.*")); + EXPECT_TRUE(MatchPattern("", "*")); + EXPECT_TRUE(MatchPattern("", "?")); + EXPECT_TRUE(MatchPattern("", "")); + EXPECT_FALSE(MatchPattern("Hello", "")); + EXPECT_TRUE(MatchPattern("Hello*", "Hello*")); + // Stop after a certain recursion depth. + EXPECT_FALSE(MatchPattern("123456789012345678", "?????????????????*")); + + // Test UTF8 matching. + EXPECT_TRUE(MatchPattern("heart: \xe2\x99\xa0", "*\xe2\x99\xa0")); + EXPECT_TRUE(MatchPattern("heart: \xe2\x99\xa0.", "heart: ?.")); + EXPECT_TRUE(MatchPattern("hearts: \xe2\x99\xa0\xe2\x99\xa0", "*")); + // Invalid sequences should be handled as a single invalid character. + EXPECT_TRUE(MatchPattern("invalid: \xef\xbf\xbe", "invalid: ?")); + // If the pattern has invalid characters, it shouldn't match anything. + EXPECT_FALSE(MatchPattern("\xf4\x90\x80\x80", "\xf4\x90\x80\x80")); + + // This test verifies that consecutive wild cards are collapsed into 1 + // wildcard (when this doesn't occur, MatchPattern reaches it's maximum + // recursion depth). + EXPECT_TRUE(MatchPattern("Hello" , + "He********************************o")) ; +} + +} // namespace kudu http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/stringpiece.cc ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/stringpiece.cc b/be/src/gutil/strings/stringpiece.cc index 285d646..d6f23ee 100644 --- a/be/src/gutil/strings/stringpiece.cc +++ b/be/src/gutil/strings/stringpiece.cc @@ -2,35 +2,32 @@ // // -#include "gutil/strings/stringpiece.h" +#include "kudu/gutil/strings/stringpiece.h" -#include <string.h> #include <algorithm> +#include <climits> +#include <glog/logging.h> +#include <string.h> +#include <string> + +#include "kudu/gutil/hash/hash.h" +#include "kudu/gutil/logging-inl.h" +#include "kudu/gutil/stl_util.h" +#include "kudu/gutil/strings/memutil.h" + using std::copy; using std::max; using std::min; using std::reverse; using std::sort; using std::swap; -#include <climits> -#include <string> using std::string; -#include <glog/logging.h> -#include "gutil/logging-inl.h" -#include "gutil/strings/memutil.h" -#include "gutil/stl_util.h" -#include "gutil/hash/hash.h" - -#include <ext/hash_set> -namespace __gnu_cxx { - -size_t hash<StringPiece>::operator()(StringPiece s) const { - return HashTo32(s.data(), s.size()); -} - -} // namespace __gnu_cxx - +namespace std { + size_t hash<StringPiece>::operator()(StringPiece s) const { + return HashTo32(s.data(), s.size()); + } +} // namespace std std::ostream& operator<<(std::ostream& o, StringPiece piece) { o.write(piece.data(), piece.size()); @@ -84,7 +81,7 @@ int StringPiece::find(char c, size_type pos) const { } const char* result = static_cast<const char*>( memchr(ptr_ + pos, c, length_ - pos)); - return result != NULL ? result - ptr_ : npos; + return result != nullptr ? result - ptr_ : npos; } int StringPiece::rfind(StringPiece s, size_type pos) const { http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/stringpiece.h ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/stringpiece.h b/be/src/gutil/strings/stringpiece.h index 77afb70..0f28f2b 100644 --- a/be/src/gutil/strings/stringpiece.h +++ b/be/src/gutil/strings/stringpiece.h @@ -114,23 +114,18 @@ #include <assert.h> -#include <stddef.h> -#include <string.h> -#include <ext/hash_map> -using __gnu_cxx::hash; -using __gnu_cxx::hash_map; +#include <functional> #include <iosfwd> -using std::ostream; #include <limits> -using std::numeric_limits; +#include <stddef.h> +#include <string.h> #include <string> -using std::string; -#include "gutil/integral_types.h" -#include "gutil/port.h" -#include "gutil/type_traits.h" -#include "gutil/strings/fastmem.h" -#include "gutil/hash/hash.h" +#include "kudu/gutil/integral_types.h" +#include "kudu/gutil/port.h" +#include "kudu/gutil/type_traits.h" +#include "kudu/gutil/strings/fastmem.h" +#include "kudu/gutil/hash/hash.h" class StringPiece { private: @@ -153,7 +148,7 @@ class StringPiece { length_ = static_cast<int>(length); } } - StringPiece(const string& str) // NOLINT(runtime/explicit) + StringPiece(const std::string& str) // NOLINT(runtime/explicit) : ptr_(str.data()), length_(0) { size_t length = str.size(); assert(length <= static_cast<size_t>(std::numeric_limits<int>::max())); @@ -231,7 +226,7 @@ class StringPiece { return 0; } - string as_string() const { + std::string as_string() const { return ToString(); } // We also define ToString() here, since many other string-like @@ -239,13 +234,13 @@ class StringPiece { // "ToString", and it's confusing to have the method that does that // for a StringPiece be called "as_string()". We also leave the // "as_string()" method defined here for existing code. - string ToString() const { - if (ptr_ == NULL) return string(); - return string(data(), size()); + std::string ToString() const { + if (ptr_ == NULL) return std::string(); + return std::string(data(), size()); } - void CopyToString(string* target) const; - void AppendToString(string* target) const; + void CopyToString(std::string* target) const; + void AppendToString(std::string* target) const; bool starts_with(StringPiece x) const { return (length_ >= x.length_) && (memcmp(ptr_, x.ptr_, x.length_) == 0); @@ -352,20 +347,12 @@ template <class X> struct GoodFastHash; // SWIG doesn't know how to parse this stuff properly. Omit it. #ifndef SWIG -#include <ext/hash_set> -namespace __gnu_cxx { +namespace std { template<> struct hash<StringPiece> { size_t operator()(StringPiece s) const; - // Less than operator, for MSVC. - bool operator()(const StringPiece& s1, const StringPiece& s2) const { - return s1 < s2; - } - static const size_t bucket_size = 4; // These are required by MSVC - static const size_t min_buckets = 8; // 4 and 8 are defaults. }; - -} // namespace __gnu_cxx +} // namespace std // An implementation of GoodFastHash for StringPiece. See http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/strip.cc ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/strip.cc b/be/src/gutil/strings/strip.cc index 8a51776..1a6a547 100644 --- a/be/src/gutil/strings/strip.cc +++ b/be/src/gutil/strings/strip.cc @@ -4,7 +4,7 @@ // This file contains functions that remove a defined part from the string, // i.e., strip the string. -#include "gutil/strings/strip.h" +#include "kudu/gutil/strings/strip.h" #include <assert.h> #include <string.h> @@ -18,8 +18,8 @@ using std::swap; #include <string> using std::string; -#include "gutil/strings/ascii_ctype.h" -#include "gutil/strings/stringpiece.h" +#include "kudu/gutil/strings/ascii_ctype.h" +#include "kudu/gutil/strings/stringpiece.h" string StripPrefixString(StringPiece str, const StringPiece& prefix) { if (str.starts_with(prefix)) @@ -74,9 +74,9 @@ void StripString(char* str, int len, StringPiece remove, char replacewith) { } void StripString(string* s, StringPiece remove, char replacewith) { - for (string::iterator it = s->begin(), end = s->end(); it != end; ++it) { - if (remove.find(*it) != StringPiece::npos) { - *it = replacewith; + for (char& c : *s) { + if (remove.find(c) != StringPiece::npos) { + c = replacewith; } } } @@ -286,7 +286,7 @@ int StripDupCharacters(string* s, char dup_char, int start_pos) { // Remove leading, trailing, and duplicate internal whitespace. // ---------------------------------------------------------------------- void RemoveExtraWhitespace(string* s) { - assert(s != NULL); + assert(s != nullptr); // Empty strings clearly have no whitespace, and this code assumes that // string length is greater than 0 if (s->empty()) @@ -324,7 +324,7 @@ void RemoveExtraWhitespace(string* s) { void StripLeadingWhiteSpace(string* str) { char const* const leading = StripLeadingWhiteSpace( const_cast<char*>(str->c_str())); - if (leading != NULL) { + if (leading != nullptr) { string const tmp(leading); str->assign(tmp); } else { http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/strip.h ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/strip.h b/be/src/gutil/strings/strip.h index cdde845..8104b76 100644 --- a/be/src/gutil/strings/strip.h +++ b/be/src/gutil/strings/strip.h @@ -11,8 +11,8 @@ #include <string> using std::string; -#include "gutil/strings/ascii_ctype.h" -#include "gutil/strings/stringpiece.h" +#include "kudu/gutil/strings/ascii_ctype.h" +#include "kudu/gutil/strings/stringpiece.h" // Given a string and a putative prefix, returns the string minus the // prefix string if the prefix matches, otherwise the original http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/substitute.cc ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/substitute.cc b/be/src/gutil/strings/substitute.cc index d4b2a7b..245894b 100644 --- a/be/src/gutil/strings/substitute.cc +++ b/be/src/gutil/strings/substitute.cc @@ -1,13 +1,13 @@ // Copyright 2008 Google Inc. All rights reserved. -#include "gutil/strings/substitute.h" +#include "kudu/gutil/strings/substitute.h" #include <glog/logging.h> -#include "gutil/logging-inl.h" -#include "gutil/macros.h" -#include "gutil/strings/ascii_ctype.h" -#include "gutil/strings/escaping.h" -#include "gutil/stl_util.h" +#include "kudu/gutil/logging-inl.h" +#include "kudu/gutil/macros.h" +#include "kudu/gutil/strings/ascii_ctype.h" +#include "kudu/gutil/strings/escaping.h" +#include "kudu/gutil/stl_util.h" namespace strings { @@ -93,7 +93,7 @@ void SubstituteAndAppend( const SubstituteArg& arg6, const SubstituteArg& arg7, const SubstituteArg& arg8, const SubstituteArg& arg9) { const SubstituteArg* const args_array[] = { - &arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8, &arg9, NULL + &arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8, &arg9, nullptr }; // Determine total size needed. @@ -112,7 +112,7 @@ void SubstituteAndAppend( SubstituteArg::SubstituteArg(const void* value) { COMPILE_ASSERT(sizeof(scratch_) >= sizeof(value) * 2 + 2, fix_sizeof_scratch_); - if (value == NULL) { + if (value == nullptr) { text_ = "NULL"; size_ = strlen(text_); } else { http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/substitute.h ---------------------------------------------------------------------- diff --git a/be/src/gutil/strings/substitute.h b/be/src/gutil/strings/substitute.h index 84d362a..0812c3f 100644 --- a/be/src/gutil/strings/substitute.h +++ b/be/src/gutil/strings/substitute.h @@ -4,9 +4,9 @@ #include <string> using std::string; -#include "gutil/basictypes.h" -#include "gutil/strings/numbers.h" -#include "gutil/strings/stringpiece.h" +#include "kudu/gutil/basictypes.h" +#include "kudu/gutil/strings/numbers.h" +#include "kudu/gutil/strings/stringpiece.h" #ifndef STRINGS_SUBSTITUTE_H_
