[CodeFormat] Clang-format cpp sources (#4965)

Clang-format all c++ source files.
This commit is contained in:
sduzh
2020-11-28 18:36:49 +08:00
committed by GitHub
parent f944bf4d44
commit 6fedf5881b
1331 changed files with 62548 additions and 68514 deletions

View File

@ -16,7 +16,6 @@
// under the License.
#include "runtime/datetime_value.h"
#include "util/timezone_utils.h"
#include <ctype.h>
#include <string.h>
@ -26,25 +25,23 @@
#include <sstream>
#include "common/logging.h"
#include "util/timezone_utils.h"
namespace doris {
const uint64_t log_10_int[] = {
1, 10, 100, 1000, 10000UL, 100000UL, 1000000UL, 10000000UL,
100000000UL, 1000000000UL, 10000000000UL, 100000000000UL
};
const uint64_t log_10_int[] = {1, 10, 100, 1000,
10000UL, 100000UL, 1000000UL, 10000000UL,
100000000UL, 1000000000UL, 10000000000UL, 100000000000UL};
static int s_days_in_month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
static const char* s_month_name[] =
{"", "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December", NULL};
static const char* s_ab_month_name[] =
{"", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL};
static const char* s_day_name[] =
{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", NULL};
static const char* s_ab_day_name[] =
{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", NULL};
static const char* s_month_name[] = {"", "January", "February", "March", "April",
"May", "June", "July", "August", "September",
"October", "November", "December", NULL};
static const char* s_ab_month_name[] = {"", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL};
static const char* s_day_name[] = {"Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday", "Sunday", NULL};
static const char* s_ab_day_name[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", NULL};
uint8_t mysql_week_mode(uint32_t mode) {
mode &= 7;
@ -63,14 +60,13 @@ static uint32_t calc_days_in_year(uint32_t year) {
}
DateTimeValue DateTimeValue::_s_min_datetime_value(0, TIME_DATETIME, 0, 0, 0, 0, 0, 1, 1);
DateTimeValue DateTimeValue::_s_max_datetime_value(0, TIME_DATETIME, 23, 59, 59, 0,
9999, 12, 31);
DateTimeValue DateTimeValue::_s_max_datetime_value(0, TIME_DATETIME, 23, 59, 59, 0, 9999, 12, 31);
RE2 DateTimeValue::time_zone_offset_format_reg("^[+-]{1}\\d{2}\\:\\d{2}$");
bool DateTimeValue::check_range() const {
return _year > 9999 || _month > 12 || _day > 31
|| _hour > (_type == TIME_TIME ? TIME_MAX_HOUR : 23)
|| _minute > 59 || _second > 59 || _microsecond > 999999;
return _year > 9999 || _month > 12 || _day > 31 ||
_hour > (_type == TIME_TIME ? TIME_MAX_HOUR : 23) || _minute > 59 || _second > 59 ||
_microsecond > 999999;
}
bool DateTimeValue::check_date() const {
@ -126,8 +122,7 @@ bool DateTimeValue::from_date_str(const char* date_str, int len) {
int field_idx = 0;
int field_len = year_len;
while (ptr < end
&& isdigit(*ptr) && field_idx < MAX_DATE_PARTS - 1) {
while (ptr < end && isdigit(*ptr) && field_idx < MAX_DATE_PARTS - 1) {
const char* start = ptr;
int temp_val = 0;
bool scan_to_delim = (!is_interval_format) && (field_idx != 6);
@ -222,7 +217,7 @@ bool DateTimeValue::from_date_str(const char* date_str, int len) {
// (991231, 10000101) invalid, because support 1000-01-01
// [10000101, 99991231] for four digits year date value.
// (99991231, 101000000) invalid, NOTE below this is datetime vaule hh:mm:ss must exist.
// [101000000, (YY_PART_YEAR - 1)##1231235959] two digits year datetime value
// [101000000, (YY_PART_YEAR - 1)##1231235959] two digits year datetime value
// ((YY_PART_YEAR - 1)##1231235959, YY_PART_YEAR##0101000000) invalid
// ((YY_PART_YEAR)##1231235959, 99991231235959] two digits year datetime value 1970 ~ 1999
// (999991231235959, ~) valid
@ -361,57 +356,57 @@ bool DateTimeValue::from_time_int64(int64_t value) {
return true;
}
char* DateTimeValue::append_date_string(char *to) const {
char* DateTimeValue::append_date_string(char* to) const {
uint32_t temp;
// Year
temp = _year / 100;
*to++ = (char) ('0' + (temp / 10));
*to++ = (char) ('0' + (temp % 10));
*to++ = (char)('0' + (temp / 10));
*to++ = (char)('0' + (temp % 10));
temp = _year % 100;
*to++ = (char) ('0' + (temp / 10));
*to++ = (char) ('0' + (temp % 10));
*to++ = (char)('0' + (temp / 10));
*to++ = (char)('0' + (temp % 10));
*to++ = '-';
// Month
*to++ = (char) ('0' + (_month / 10));
*to++ = (char) ('0' + (_month % 10));
*to++ = (char)('0' + (_month / 10));
*to++ = (char)('0' + (_month % 10));
*to++ = '-';
// Day
*to++ = (char) ('0' + (_day / 10));
*to++ = (char) ('0' + (_day % 10));
*to++ = (char)('0' + (_day / 10));
*to++ = (char)('0' + (_day % 10));
return to;
}
char* DateTimeValue::append_time_string(char *to) const {
char* DateTimeValue::append_time_string(char* to) const {
if (_neg) {
*to++ = '-';
}
// Hour
uint32_t temp = _hour;
if (temp >= 100) {
*to++ = (char) ('0' + (temp / 100));
*to++ = (char)('0' + (temp / 100));
temp %= 100;
}
*to++ = (char) ('0' + (temp / 10));
*to++ = (char) ('0' + (temp % 10));
*to++ = (char)('0' + (temp / 10));
*to++ = (char)('0' + (temp % 10));
*to++ = ':';
// Minute
*to++ = (char) ('0' + (_minute / 10));
*to++ = (char) ('0' + (_minute % 10));
*to++ = (char)('0' + (_minute / 10));
*to++ = (char)('0' + (_minute % 10));
*to++ = ':';
/* Second */
*to++ = (char) ('0' + (_second / 10));
*to++ = (char) ('0' + (_second % 10));
*to++ = (char)('0' + (_second / 10));
*to++ = (char)('0' + (_second % 10));
if (_microsecond > 0) {
*to++ = '.';
uint32_t first = _microsecond / 10000;
uint32_t second = (_microsecond % 10000) / 100;
uint32_t third = _microsecond % 100;
*to++ = (char) ('0' + first / 10);
*to++ = (char) ('0' + first % 10);
*to++ = (char) ('0' + second / 10);
*to++ = (char) ('0' + second % 10);
*to++ = (char) ('0' + third / 10);
*to++ = (char) ('0' + third % 10);
*to++ = (char)('0' + first / 10);
*to++ = (char)('0' + first % 10);
*to++ = (char)('0' + second / 10);
*to++ = (char)('0' + second % 10);
*to++ = (char)('0' + third / 10);
*to++ = (char)('0' + third % 10);
}
return to;
}
@ -455,8 +450,8 @@ char* DateTimeValue::to_string(char* to) const {
}
int64_t DateTimeValue::to_datetime_int64() const {
return (_year * 10000L + _month * 100 + _day) * 1000000L
+ _hour * 10000 + _minute * 100 + _second;
return (_year * 10000L + _month * 100 + _day) * 1000000L + _hour * 10000 + _minute * 100 +
_second;
}
int64_t DateTimeValue::to_date_int64() const {
@ -534,7 +529,7 @@ uint64_t DateTimeValue::calc_daynr(uint32_t year, uint32_t month, uint32_t day)
/* Cast to int to be able to handle month == 0 */
delsum = 365 * y + 31 * (month - 1) + day;
if (month <= 2) {
// No leap year
// No leap year
y--;
} else {
// This is great!!!
@ -554,7 +549,7 @@ static char* int_to_str(uint64_t val, char* to) {
*ptr++ = '0' + (val % 10);
val /= 10;
} while (val);
while (ptr > buf) {
*to++ = *--ptr;
}
@ -569,8 +564,7 @@ static char* append_string(const char* from, char* to) {
return to;
}
static char* append_with_prefix(const char* str, int str_len,
char prefix, int full_len, char* to) {
static char* append_with_prefix(const char* str, int str_len, char prefix, int full_len, char* to) {
int len = (str_len > full_len) ? str_len : full_len;
len -= str_len;
while (len-- > 0) {
@ -779,16 +773,16 @@ bool DateTimeValue::to_format_string(const char* format, int len, char* to) cons
break;
case 'r':
// Time, 12-hour (hh:mm:ss followed by AM or PM)
*to++ = (char) ('0' + (((_hour + 11) % 12 + 1) / 10));
*to++ = (char) ('0' + (((_hour + 11) % 12 + 1) % 10));
*to++ = (char)('0' + (((_hour + 11) % 12 + 1) / 10));
*to++ = (char)('0' + (((_hour + 11) % 12 + 1) % 10));
*to++ = ':';
// Minute
*to++ = (char) ('0' + (_minute / 10));
*to++ = (char) ('0' + (_minute % 10));
*to++ = (char)('0' + (_minute / 10));
*to++ = (char)('0' + (_minute % 10));
*to++ = ':';
/* Second */
*to++ = (char) ('0' + (_second / 10));
*to++ = (char) ('0' + (_second % 10));
*to++ = (char)('0' + (_second / 10));
*to++ = (char)('0' + (_second % 10));
if ((_hour % 24) >= 12) {
to = append_string(" PM", to);
} else {
@ -803,16 +797,16 @@ bool DateTimeValue::to_format_string(const char* format, int len, char* to) cons
break;
case 'T':
// Time, 24-hour (hh:mm:ss)
*to++ = (char) ('0' + ((_hour % 24) / 10));
*to++ = (char) ('0' + ((_hour % 24) % 10));
*to++ = (char)('0' + ((_hour % 24) / 10));
*to++ = (char)('0' + ((_hour % 24) % 10));
*to++ = ':';
// Minute
*to++ = (char) ('0' + (_minute / 10));
*to++ = (char) ('0' + (_minute % 10));
*to++ = (char)('0' + (_minute / 10));
*to++ = (char)('0' + (_minute % 10));
*to++ = ':';
/* Second */
*to++ = (char) ('0' + (_second / 10));
*to++ = (char) ('0' + (_second % 10));
*to++ = (char)('0' + (_second / 10));
*to++ = (char)('0' + (_second % 10));
break;
case 'u':
// Week (00..53), where Monday is the first day of the week;
@ -905,7 +899,7 @@ bool DateTimeValue::to_format_string(const char* format, int len, char* to) cons
return true;
}
uint8_t DateTimeValue::calc_week(const DateTimeValue& value, uint8_t mode, uint32_t *year) {
uint8_t DateTimeValue::calc_week(const DateTimeValue& value, uint8_t mode, uint32_t* year) {
bool monday_first = mode & WEEK_MONDAY_FIRST;
bool week_year = mode & WEEK_YEAR;
bool first_weekday = mode & WEEK_FIRST_WEEKDAY;
@ -918,9 +912,8 @@ uint8_t DateTimeValue::calc_week(const DateTimeValue& value, uint8_t mode, uint3
// Check wether the first days of this year belongs to last year
if (value._month == 1 && value._day <= (7 - weekday_first_day)) {
if (!week_year
&& ((first_weekday && weekday_first_day != 0)
|| (!first_weekday && weekday_first_day > 3))) {
if (!week_year && ((first_weekday && weekday_first_day != 0) ||
(!first_weekday && weekday_first_day > 3))) {
return 0;
}
(*year)--;
@ -930,8 +923,7 @@ uint8_t DateTimeValue::calc_week(const DateTimeValue& value, uint8_t mode, uint3
}
// How many days since first week
if ((first_weekday && weekday_first_day != 0)
|| (!first_weekday && weekday_first_day > 3)) {
if ((first_weekday && weekday_first_day != 0) || (!first_weekday && weekday_first_day > 3)) {
// days in new year belongs to last year.
days = day_nr - (daynr_first_day + (7 - weekday_first_day));
} else {
@ -940,9 +932,9 @@ uint8_t DateTimeValue::calc_week(const DateTimeValue& value, uint8_t mode, uint3
}
if (week_year && days >= 52 * 7) {
weekday_first_day = (weekday_first_day + calc_days_in_year(*year)) % 7;
if ((first_weekday && weekday_first_day == 0)
|| (!first_weekday && weekday_first_day <= 3)) {
weekday_first_day = (weekday_first_day + calc_days_in_year(*year)) % 7;
if ((first_weekday && weekday_first_day == 0) ||
(!first_weekday && weekday_first_day <= 3)) {
// Belong to next year.
(*year)++;
return 1;
@ -963,7 +955,7 @@ uint8_t DateTimeValue::calc_weekday(uint64_t day_nr, bool is_sunday_first_day) {
// TODO(zhaochun): Think endptr is NULL
// Return true if convert to a integer success. Otherwise false.
static bool str_to_int64(const char* ptr, const char** endptr, int64_t *ret) {
static bool str_to_int64(const char* ptr, const char** endptr, int64_t* ret) {
const static uint64_t MAX_NEGATIVE_NUMBER = 0x8000000000000000;
const static uint64_t ULONGLONG_MAX = ~0;
const static uint64_t LFACTOR2 = 100000000000ULL;
@ -1020,9 +1012,9 @@ static bool str_to_int64(const char* ptr, const char** endptr, int64_t *ret) {
uint64_t value_3 = 0;
// Check overflow.
if (value_1 > cutoff_1
|| (value_1 == cutoff_1 && (value_2 > cutoff_2
|| (value_2 == cutoff_2 && value_3 > cutoff_3)))) {
if (value_1 > cutoff_1 ||
(value_1 == cutoff_1 &&
(value_2 > cutoff_2 || (value_2 == cutoff_2 && value_3 > cutoff_3)))) {
return false;
}
return true;
@ -1072,10 +1064,8 @@ static int check_word(const char* lib[], const char* str, const char* end, const
// this method is exactly same as fromDateFormatStr() in DateLiteral.java in FE
// change this method should also change that.
bool DateTimeValue::from_date_format_str(
const char* format, int format_len,
const char* value, int value_len,
const char** sub_val_end) {
bool DateTimeValue::from_date_format_str(const char* format, int format_len, const char* value,
int value_len, const char** sub_val_end) {
const char* ptr = format;
const char* end = format + format_len;
const char* val = value;
@ -1368,21 +1358,21 @@ bool DateTimeValue::from_date_format_str(
if (*ptr == '%' && ptr + 1 < end) {
ptr++;
switch (*ptr++) {
case 'H':
case 'h':
case 'I':
case 'i':
case 'k':
case 'l':
case 'r':
case 's':
case 'S':
case 'p':
case 'T':
time_part_used = true;
break;
default:
break;
case 'H':
case 'h':
case 'I':
case 'i':
case 'k':
case 'l':
case 'r':
case 's':
case 'S':
case 'p':
case 'T':
time_part_used = true;
break;
default:
break;
}
} else {
ptr++;
@ -1409,9 +1399,9 @@ bool DateTimeValue::from_date_format_str(
// weekday
if (week_num >= 0 && weekday > 0) {
// Check
if ((strict_week_number && (strict_week_number_year < 0
|| strict_week_number_year_type != sunday_first))
|| (!strict_week_number && strict_week_number_year >= 0)) {
if ((strict_week_number &&
(strict_week_number_year < 0 || strict_week_number_year_type != sunday_first)) ||
(!strict_week_number && strict_week_number_year >= 0)) {
return false;
}
uint64_t days = calc_daynr(strict_week_number ? strict_week_number_year : _year, 1, 1);
@ -1471,15 +1461,15 @@ bool DateTimeValue::date_add_interval(const TimeInterval& interval, TimeUnit uni
case DAY_SECOND:
case DAY_MINUTE:
case DAY_HOUR: {
// This may change the day information
// This may change the day information
int64_t microseconds = _microsecond + sign * interval.microsecond;
int64_t extra_second = microseconds / 1000000L;
microseconds %= 1000000L;
int64_t seconds = (_day - 1) * 86400L + _hour * 3600L + _minute * 60 + _second
+ sign * (interval.day * 86400 + interval.hour * 3600
+ interval.minute * 60 + interval.second)
+ extra_second;
int64_t seconds = (_day - 1) * 86400L + _hour * 3600L + _minute * 60 + _second +
sign * (interval.day * 86400 + interval.hour * 3600 +
interval.minute * 60 + interval.second) +
extra_second;
if (microseconds < 0) {
seconds--;
microseconds += 1000000L;
@ -1543,7 +1533,7 @@ bool DateTimeValue::date_add_interval(const TimeInterval& interval, TimeUnit uni
return true;
}
bool DateTimeValue::unix_timestamp(int64_t* timestamp, const std::string& timezone) const{
bool DateTimeValue::unix_timestamp(int64_t* timestamp, const std::string& timezone) const {
cctz::time_zone ctz;
if (!TimezoneUtils::find_cctz_time_zone(timezone, ctz)) {
return false;
@ -1551,7 +1541,7 @@ bool DateTimeValue::unix_timestamp(int64_t* timestamp, const std::string& timezo
return unix_timestamp(timestamp, ctz);
}
bool DateTimeValue::unix_timestamp(int64_t* timestamp, const cctz::time_zone& ctz) const{
bool DateTimeValue::unix_timestamp(int64_t* timestamp, const cctz::time_zone& ctz) const {
const auto tp =
cctz::convert(cctz::civil_second(_year, _month, _day, _hour, _minute, _second), ctz);
*timestamp = tp.time_since_epoch().count();
@ -1568,7 +1558,8 @@ bool DateTimeValue::from_unixtime(int64_t timestamp, const std::string& timezone
bool DateTimeValue::from_unixtime(int64_t timestamp, const cctz::time_zone& ctz) {
static const cctz::time_point<cctz::sys_seconds> epoch =
std::chrono::time_point_cast<cctz::sys_seconds>(std::chrono::system_clock::from_time_t(0));
std::chrono::time_point_cast<cctz::sys_seconds>(
std::chrono::system_clock::from_time_t(0));
cctz::time_point<cctz::sys_seconds> t = epoch + cctz::seconds(timestamp);
const auto tp = cctz::convert(t, ctz);
@ -1582,7 +1573,7 @@ bool DateTimeValue::from_unixtime(int64_t timestamp, const cctz::time_zone& ctz)
_minute = tp.minute();
_second = tp.second();
_microsecond = 0;
return true;
}
@ -1613,7 +1604,7 @@ std::ostream& operator<<(std::ostream& os, const DateTimeValue& value) {
return os << buf;
}
// NOTE:
// NOTE:
// only support DATE - DATE (no support DATETIME - DATETIME)
std::size_t operator-(const DateTimeValue& v1, const DateTimeValue& v2) {
return v1.daynr() - v2.daynr();
@ -1623,4 +1614,4 @@ std::size_t hash_value(DateTimeValue const& value) {
return HashUtil::hash(&value, sizeof(DateTimeValue), 0);
}
}
} // namespace doris