From 38b95e4ac87a30fe78a95d22c343b9a6c909799c Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 19 Nov 2021 22:55:52 +0100 Subject: [PATCH] fix get_slice. --- core/string.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/string.cpp b/core/string.cpp index 9ef94e9..dc42760 100644 --- a/core/string.cpp +++ b/core/string.cpp @@ -380,6 +380,10 @@ int String::get_slice_count(const String &splitter) const { return count; } String String::get_slice(const char splitter, int index) { + if (_size == 0) { + return ""; + } + int count = 0; int start_index = 0; @@ -398,13 +402,13 @@ String String::get_slice(const char splitter, int index) { } } - if (count == 0) { - return ""; - } - return substr_index(start_index, _size - 1); } String String::get_slice(const String &splitter, int index) { + if (_size == 0) { + return ""; + } + int count = 0; int start_index = 0; @@ -423,10 +427,6 @@ String String::get_slice(const String &splitter, int index) { } } - if (count == 0) { - return ""; - } - return substr_index(start_index, _size - 1); }