From 2676893dd89fd7127c34a2f211dd02b5a8d7a647 Mon Sep 17 00:00:00 2001 From: Tomasz Wasilczyk Date: Mon, 14 Aug 2023 17:05:51 +0000 Subject: [PATCH] Implement String8|16::empty and String16::length This time following std::string::empty meaning. String16::length is for parity with String8::length and to follow std::string::length/size duo. Bug: 295394788 Test: mma Change-Id: I43df2cbb9ca6f980a4cf6d971064d594d661f884 --- libutils/include/utils/String16.h | 14 ++++++++++++++ libutils/include/utils/String8.h | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/libutils/include/utils/String16.h b/libutils/include/utils/String16.h index d719aeaaa..b48b90765 100644 --- a/libutils/include/utils/String16.h +++ b/libutils/include/utils/String16.h @@ -60,6 +60,10 @@ private: static inline std::string std_string(const String16& str); public: size_t size() const; + inline bool empty() const; + + inline size_t length() const; + void setTo(const String16& other); status_t setTo(const char16_t* other); status_t setTo(const char16_t* other, size_t len); @@ -250,6 +254,16 @@ inline std::string String16::std_string(const String16& str) return std::string(String8(str).c_str()); } +inline bool String16::empty() const +{ + return length() == 0; +} + +inline size_t String16::length() const +{ + return size(); +} + inline String16& String16::operator=(const String16& other) { setTo(other); diff --git a/libutils/include/utils/String8.h b/libutils/include/utils/String8.h index ace0243f3..10eef06cd 100644 --- a/libutils/include/utils/String8.h +++ b/libutils/include/utils/String8.h @@ -64,6 +64,7 @@ public: inline size_t size() const; inline size_t bytes() const; + inline bool empty() const; inline bool isEmpty() const; size_t length() const; @@ -257,6 +258,11 @@ inline size_t String8::size() const return length(); } +inline bool String8::empty() const +{ + return length() == 0; +} + inline bool String8::isEmpty() const { return length() == 0;