Skip to content

Commit ad8dd70

Browse files
authored
Fix conversion warnings in CvtFormat (#8642)
+ adds some convenience methods for std::string_view
1 parent 3ef5562 commit ad8dd70

File tree

4 files changed

+48
-38
lines changed

4 files changed

+48
-38
lines changed

src/common/CvtFormat.cpp

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -487,12 +487,12 @@ namespace
487487

488488
void invalidPatternException(std::string_view pattern, Callbacks* cb)
489489
{
490-
cb->err(Arg::Gds(isc_invalid_date_format) << string(pattern.data(), pattern.length()));
490+
cb->err(Arg::Gds(isc_invalid_date_format) << pattern);
491491
}
492492

493493
void incompatibleDateFormatException(std::string_view pattern, Callbacks* cb)
494494
{
495-
cb->err(Arg::Gds(isc_incompatible_date_format_with_current_date_type) << string(pattern.data(), pattern.length()));
495+
cb->err(Arg::Gds(isc_incompatible_date_format_with_current_date_type) << pattern);
496496
}
497497

498498
//-----------------------------------------------------------------------------------------------------------------
@@ -915,7 +915,7 @@ namespace
915915

916916
if (format[0] == '\"')
917917
{
918-
patternResult.resize(format.length(), '\0');
918+
patternResult.resize(static_cast<string::size_type>(format.length()), '\0');
919919
for (FB_SIZE_T i = 1, j = 0; i < format.length(); i++, j++)
920920
{
921921
if (format[i] == '\"')
@@ -928,7 +928,7 @@ namespace
928928
patternResult.recalculate_length();
929929
}
930930
else
931-
patternResult.assign(format.data(), format.length());
931+
patternResult.assign(format);
932932
break;
933933
}
934934

@@ -951,7 +951,7 @@ namespace
951951
void throwExceptionOnEmptyValue(std::optional<T> value, std::string_view pattern, Callbacks* cb)
952952
{
953953
if (!value.has_value())
954-
cb->err(Arg::Gds(isc_missing_value_for_format_pattern) << string(pattern.data(), pattern.length()));
954+
cb->err(Arg::Gds(isc_missing_value_for_format_pattern) << pattern);
955955
}
956956

957957
std::vector<Token> parseStringToDateTimeFormat(const dsc* desc, const string& formatUpper, Format::Patterns& outFormatPatterns, Callbacks* cb)
@@ -982,7 +982,7 @@ namespace
982982
if (pattern == Format::NONE)
983983
invalidPatternException(patternStr, cb);
984984
if (outFormatPatterns & pattern)
985-
cb->err(Arg::Gds(isc_can_not_use_same_pattern_twice) << string(patternStr.data(), patternStr.length()));
985+
cb->err(Arg::Gds(isc_can_not_use_same_pattern_twice) << patternStr);
986986
if (!patternIsCompatibleWithDscType(desc, pattern))
987987
incompatibleDateFormatException(patternStr, cb);
988988

@@ -1136,7 +1136,7 @@ namespace
11361136
else if (period == FormatStr::PM)
11371137
return twelveHours == 12 ? twelveHours : 12 + twelveHours;
11381138

1139-
cb->err(Arg::Gds(isc_incorrect_hours_period) << string(period.data(), period.length()));
1139+
cb->err(Arg::Gds(isc_incorrect_hours_period) << period);
11401140
return 0; // suppress compiler warning/error
11411141
}
11421142

@@ -1275,8 +1275,8 @@ namespace
12751275

12761276
if (minutes.value() > 59)
12771277
{
1278-
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) <<
1279-
string(patternStr.data(), patternStr.length()) << Arg::Num(0) << Arg::Num(59));
1278+
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) << patternStr << Arg::Num(0) <<
1279+
Arg::Num(59));
12801280
}
12811281

12821282
if (!TimeZoneUtil::isValidOffset(sign, hours.value(), minutes.value()))
@@ -1398,8 +1398,8 @@ namespace
13981398

13991399
if (year > 9999)
14001400
{
1401-
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) <<
1402-
string(patternStr.data(), patternStr.length()) << Arg::Num(0) << Arg::Num(9999));
1401+
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) << patternStr <<
1402+
Arg::Num(0) << Arg::Num(9999));
14031403
}
14041404
outTimes.tm_year = year.value() - 1900;
14051405
break;
@@ -1411,8 +1411,8 @@ namespace
14111411

14121412
if (minutes > 59)
14131413
{
1414-
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) <<
1415-
string(patternStr.data(), patternStr.length()) << Arg::Num(0) << Arg::Num(59));
1414+
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) << patternStr <<
1415+
Arg::Num(0) << Arg::Num(59));
14161416
}
14171417

14181418
outTimes.tm_min = minutes.value();
@@ -1425,8 +1425,8 @@ namespace
14251425

14261426
if (month < 1 || month > 12)
14271427
{
1428-
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) <<
1429-
string(patternStr.data(), patternStr.length()) << Arg::Num(1) << Arg::Num(12));
1428+
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) << patternStr <<
1429+
Arg::Num(1) << Arg::Num(12));
14301430
}
14311431

14321432
outTimes.tm_mon = month.value() - 1;
@@ -1450,7 +1450,7 @@ namespace
14501450
}
14511451

14521452
if (!isFound)
1453-
cb->err(Arg::Gds(isc_month_name_mismatch) << string(monthShortName.data(), monthShortName.length()));
1453+
cb->err(Arg::Gds(isc_month_name_mismatch) << monthShortName);
14541454
break;
14551455
}
14561456
case Format::MONTH:
@@ -1471,7 +1471,7 @@ namespace
14711471
}
14721472

14731473
if (!isFound)
1474-
cb->err(Arg::Gds(isc_month_name_mismatch) << string(monthFullName.data(), monthFullName.length()));
1474+
cb->err(Arg::Gds(isc_month_name_mismatch) << monthFullName);
14751475
break;
14761476
}
14771477

@@ -1503,8 +1503,8 @@ namespace
15031503
const int month = romanToInt(str, strLength, strOffset);
15041504
if (month == 0 || month > 12)
15051505
{
1506-
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) <<
1507-
string(patternStr.data(), patternStr.length()) << Arg::Num(1) << Arg::Num(12));
1506+
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) << patternStr <<
1507+
Arg::Num(1) << Arg::Num(12));
15081508
}
15091509

15101510
outTimes.tm_mon = month - 1;
@@ -1518,8 +1518,8 @@ namespace
15181518

15191519
if (day == 0 || day > 31)
15201520
{
1521-
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) <<
1522-
string(patternStr.data(), patternStr.length()) << Arg::Num(1) << Arg::Num(31));
1521+
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) << patternStr <<
1522+
Arg::Num(1) << Arg::Num(31));
15231523
}
15241524

15251525
outTimes.tm_mday = day.value();
@@ -1535,8 +1535,8 @@ namespace
15351535
constexpr int maxJDN = 5373484; // 31.12.9999
15361536
if (JDN < minJDN || JDN > maxJDN)
15371537
{
1538-
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) <<
1539-
string(patternStr.data(), patternStr.length()) << Arg::Num(minJDN) << Arg::Num(maxJDN));
1538+
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) << patternStr <<
1539+
Arg::Num(minJDN) << Arg::Num(maxJDN));
15401540
}
15411541

15421542
int year = 0, month = 0, day = 0;
@@ -1555,8 +1555,8 @@ namespace
15551555

15561556
if (hours < 1 || hours > 12)
15571557
{
1558-
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) <<
1559-
string(patternStr.data(), patternStr.length()) << Arg::Num(1) << Arg::Num(12));
1558+
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) << patternStr <<
1559+
Arg::Num(1) << Arg::Num(12));
15601560
}
15611561

15621562
outTimes.tm_hour = hours.value();
@@ -1569,8 +1569,8 @@ namespace
15691569

15701570
if (hours > 23)
15711571
{
1572-
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) <<
1573-
string(patternStr.data(), patternStr.length()) << Arg::Num(0) << Arg::Num(23));
1572+
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) << patternStr <<
1573+
Arg::Num(0) << Arg::Num(23));
15741574
}
15751575

15761576
outTimes.tm_hour = hours.value();
@@ -1584,8 +1584,8 @@ namespace
15841584

15851585
if (seconds > 59)
15861586
{
1587-
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) <<
1588-
string(patternStr.data(), patternStr.length()) << Arg::Num(0) << Arg::Num(59));
1587+
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) << patternStr <<
1588+
Arg::Num(0) << Arg::Num(59));
15891589
}
15901590

15911591
outTimes.tm_sec = seconds.value();
@@ -1601,8 +1601,8 @@ namespace
16011601
const int secondsInDayValue = secondsInDay.value();
16021602
if (secondsInDayValue > maximumSecondsInDay)
16031603
{
1604-
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) <<
1605-
string(patternStr.data(), patternStr.length()) << Arg::Num(0) << Arg::Num(maximumSecondsInDay));
1604+
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) << patternStr <<
1605+
Arg::Num(0) << Arg::Num(maximumSecondsInDay));
16061606
}
16071607

16081608
const int hours = secondsInDayValue / 24;
@@ -1677,8 +1677,8 @@ namespace
16771677

16781678
if (minutes > 59)
16791679
{
1680-
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) <<
1681-
string(patternStr.data(), patternStr.length()) << Arg::Num(0) << Arg::Num(59));
1680+
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) << patternStr <<
1681+
Arg::Num(0) << Arg::Num(59));
16821682
}
16831683

16841684
outTimezoneInMinutes += sign(outTimezoneInMinutes) * minutes.value();
@@ -1691,8 +1691,8 @@ namespace
16911691
const int minutesValue = minutes.value();
16921692
if (abs(minutesValue) > 59)
16931693
{
1694-
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) <<
1695-
string(patternStr.data(), patternStr.length()) << Arg::Num(0) << Arg::Num(59));
1694+
cb->err(Arg::Gds(isc_value_for_pattern_is_out_of_range) << patternStr <<
1695+
Arg::Num(0) << Arg::Num(59));
16961696
}
16971697

16981698
outTimezoneInMinutes = minutesValue;
@@ -1717,8 +1717,8 @@ namespace
17171717
}
17181718

17191719
std::string_view timezoneName = getTimezoneNameFromString(str, strLength, oldOffset);
1720-
status_exception::raise(Arg::Gds(isc_invalid_timezone_region_or_displacement)
1721-
<< string(timezoneName.data(), timezoneName.length()));
1720+
status_exception::raise(
1721+
Arg::Gds(isc_invalid_timezone_region_or_displacement) << timezoneName);
17221722
}
17231723

17241724
strOffset += parsedTimezoneNameLength;

src/common/StatusArg.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ class StatusVector : public Base
221221
return *this;
222222
}
223223

224+
StatusVector& operator<<(std::string_view text) noexcept
225+
{
226+
implementation->shiftLeft(string(text.data(), static_cast<string::size_type>(text.length())));
227+
return *this;
228+
}
229+
224230
bool operator==(const StatusVector& arg) const noexcept
225231
{
226232
return implementation->compare(arg);

src/common/classes/fb_string.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,10 @@ namespace Firebird
739739
{
740740
return assign(first, last - first);
741741
}
742+
StringType& assign(std::string_view s)
743+
{
744+
return assign(s.data(), static_cast<size_type>(s.length()));
745+
}
742746

743747
StringType& operator=(const StringType& v)
744748
{

src/common/tests/StringTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static constexpr char lbl[] = "0123456789";
1414
#define validate(A, B) BOOST_TEST(std::string_view(A.c_str(), A.length()) == std::string_view(B))
1515
#define check(A, B) BOOST_TEST(A == B)
1616

17-
static constexpr string::size_type length(const std::string_view& str) noexcept
17+
static constexpr string::size_type length(std::string_view str) noexcept
1818
{
1919
return static_cast<string::size_type>(str.length());
2020
}

0 commit comments

Comments
 (0)