From 44a3ae6c3a818f53fd148e79190614fcd25a98e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Wiosna?= Date: Sat, 18 Sep 2021 19:44:28 +0200 Subject: [PATCH] Replace `chop` w/ `chop_left` in `as_integer()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ```console In file included from string_view_test.cpp:2:0: ../aids.hpp: In instantiation of ‘aids::Maybe aids::String_View::as_integer() const [with Integer = int]’: string_view_test.cpp:103:59: required from here ../aids.hpp:399:22: warning: ‘void aids::String_View::chop(size_t)’ is deprecated: Please use String_View::chop_left() instead, komrade)) [-Wdeprecated-declarations] view.chop(1); ~~~~~~~~~^~~ ../aids.hpp:934:6: note: declared here void String_View::chop(size_t n) ^~~~~~~~~~~ ``` --- aids.hpp | 4 ++-- tests/string_view_test.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/aids.hpp b/aids.hpp index 05db86f..b14d80a 100644 --- a/aids.hpp +++ b/aids.hpp @@ -396,7 +396,7 @@ struct String_View { if (*view.data == '-') { sign = -1; - view.chop(1); + view.chop_left(1); } while (view.count) { @@ -404,7 +404,7 @@ struct String_View { return {}; } number = number * 10 + (*view.data - '0'); - view.chop(1); + view.chop_left(1); } return { true, number * sign }; diff --git a/tests/string_view_test.cpp b/tests/string_view_test.cpp index aa5d84d..a359073 100644 --- a/tests/string_view_test.cpp +++ b/tests/string_view_test.cpp @@ -97,5 +97,12 @@ int main(int, char *[]) ASSERT_EQ(""_sv, bar); } } + // String_View::as_integer + { + auto year = "2021"_sv; + int number = unwrap_or_panic(year.as_integer()); + number += 1000; + ASSERT_EQ(3021, number); + } return 0; }